0% found this document useful (0 votes)
112 views18 pages

Understanding LLM Prompt Patterns

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views18 pages

Understanding LLM Prompt Patterns

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Prompt Engineering Notes:

Contents
Large Language Models:.............................................................................2
Prompt:........................................................................................................2
Information Limitations:..............................................................................3
Root Prompts:..............................................................................................4
Prompting Patterns:.....................................................................................4
Question Refinement Pattern:..................................................................4
Cognitive Verifier Pattern:........................................................................5
Persona Pattern:.......................................................................................5
LLM Persona:.........................................................................................5
Audience Persona:.................................................................................7
Flipped Interaction Pattern:......................................................................7
Few Shot Examples:.................................................................................8
Chain of Thought Prompting:....................................................................8
ReAct Prompting:......................................................................................9
Self-Grading and Editing:.........................................................................9
Game Play Pattern:.................................................................................10
Template Pattern:...................................................................................11
Meta Language Creation Pattern:...........................................................11
Recipe Pattern:.......................................................................................12
Alternative Approaches/Brainstorming Pattern:.....................................13
Ask For Input Pattern:.............................................................................13
Outline Expansion Pattern:.....................................................................14
Menu Actions Pattern:............................................................................15
Fact Check List Pattern:..........................................................................15
Tail Generation Pattern:..........................................................................16
Semantic Filter Pattern:..........................................................................16
Large Language Models:

 You're talking to a super-intelligent parrot. But not just any parrot—this one has read
every book in the library, seen every post on social media, watched every movie
script, and eavesdropped on billions of conversations (don’t worry, all legally). And
now, when you ask it a question or start a conversation, it doesn't just squawk back
random words. Oh no. This parrot starts crafting a response so smooth, it feels like
you’re chatting with a human.
 It is a word predictor. Based on patterns and an analysis of the human language, it
predicts what needs to be the reply to each prompt.
 It uses a giant and ever-growing database to keep track of changes in our language
and keeps refreshing its library.
 If you say for example, "Mary had a little" it recognises this pattern and grouping of
words and will almost always give you "Lamb, whose fleece was which as snow."
 But, depending on the training and its past conversations with you, it can change the
way it answers. Constantly adapting to your questions.
 At the same time, hand a LLM an unfamiliar string of words or an incoherent prompt,
and it will give you a random result based on the info it can gather from your
question. It will pull on key words, tone and the kind of task it is give.
 Most LLM prompts follow a basic structure,
o context
o task
o format
 If it understands even one, the model will begin working, but it is only when all three
are fully understood that it goes further and makes a proper attempt to get you your
answer.

Prompt:
 The question that spurs the LLM into action.
 A good Prompt = A good result
 A bad prompt = a bad result
 Then what is "Good" and what is "bad"? = CTF
 We describe prompt patterns in terms of fundamental contextual statements, which are
written descriptions of the important ideas to communicate in a prompt to a large
language model. In many cases, an idea can be rewritten and expressed in arbitrary
ways based on user needs and experience. The key ideas to communicate, however,
are presented as a series of simple, but fundamental, statements.
 Example: Helpful Assistant Pattern
 Let's imagine that we want to document a new pattern to prevent an AI assistant from
generating negative outputs to the user. Let's call this pattern the "Helpful Assistant"
pattern.
 Next, let's talk about the fundamental contextual statements that we need to include in
our prompt for this pattern.

Information Limitations:

 There are limitations to the data/library that the parrot is open to. The library it is
stuck in is the boundary.
 The LLM cannot know what it has not been trained to know.
 But if it is given information to do that, it can try.
 Introducing information can be done via the prompt, the uploaded files, URLs and so
on.
 It is a nice practice to know when the information was publicly available and the cut
off for the LLM you are using.
 The more you are able to provide it with context, the better it a process your task and
the better the format with which it can replay to you with.
 But be warned, every new piece of information you give the LLM will be saved for
further training. This isn't MI, there is not self-destruct code or "If you choose to
accept it”.
 There is also size limitation to the information you can give it and to how much you
can ask it in its prompt.
 The more complicated you make the prompt, the more likely it is that the result will
be vague or too convoluted.
 You need to tailor the prompt; the information you can give it.
 MAKE it a conversation. break it down into smaller chunks of information so that it
slowly builds the model you want.
 That selection is also driven by how clear you are in creating the prompt and giving
the LLM the task.
 Clearer instruction is better than more information.
 Subscription limitations may also hinder or help this limitation. More powerful
models are restricted behind a paywall.
 LLM hold the memory of all the prompts and information you have given it.
 When you talk to a friend, the ideally remember the previous conversations with you
and therefore, when you tell them something new, they make the connections with
what they've heard before.
 Same thing needs to be the approach using LLM.
 Do not give orders. Collaborate. Think of it as a brainstorming book that talks back.
 Example, Michealangelo when given a hammer doesn't just hit the slab of marble put
before him once. He does it over and over to refine the marble to obtain his
masterpieces.
 Build on each subsequent prompt exactly what you need.

Root Prompts:
 Do note that LLMs are always limited by root prompts. Prompts that restrict what is
allowed and what isn't in the use of the model.
 For example, ethical and legal restrictions on what it is allowed to help you with.
 For example, you cannot ask it to tell you how to murder someone or to make a bomb.
 But root prompts are very much in the control of the company providing you with the
AI model.

 Clever prompting can help you bypass this though, but that is more a discussion for
ethics and law to figure out. I.E the AI act in the EU and its guidelines for harmful AI.
Prompting Patterns:

Question Refinement Pattern:

 Co-develop questions and prompts. What it can recognise and how it can be helpful to
you.
 Give it a root prompt for future answers.
 For example: "Whenever I as a question, suggest a better question and ask me if I
would like to you that question instead."
 Now for every next question, the LLM will try and work with you to develop
prompts. You can also refine it further.
 Maybe ask it to think critically on the information you provide it. Be sceptical and
give you a range of issues with your reasoning. Have a debate with you on your
choice of source or you sentence structure.
 Please remember that and AI model can be wrong. It is not always 100% accurate.
You have to use your judgement and make a call.
 Tailored Examples:
o Whenever I ask a question about dieting, suggest a better version of the
question that emphasizes healthy eating habits and sound nutrition. Ask me for
the first question to refine.
o Whenever I ask a question about who is the greatest of all time (GOAT),
suggest a better version of the question that puts multiple players unique
accomplishments into perspective Ask me for the first question to refine.

Cognitive Verifier Pattern:

 "When you are asked a question, follow these rules:


o Generate a number of additional questions that would help more accurately
answer the question.
o Combine the answers to the individual questions to produce the final answer to
the overall question."
 This can also be time limited, limited to certain topics within the question or as a
follow up question too.
 Tailored Examples:
o When you are asked to create a recipe, follow these rules. Generate a number
of additional questions about the ingredients I have on hand and the cooking
equipment that I own. Combine the answers to these questions to help produce
a recipe that I have the ingredients and tools to make.
o When you are asked to plan a trip, follow these rules. Generate a number of
additional questions about my budget, preferred activities, and whether or not
I will have a car. Combine the answers to these questions to better plan my
itinerary.

Persona Pattern:

LLM Persona:

 Fundamental Contextual Statements:


o You are a helpful AI assistant.
o You will answer my questions or follow my instructions whenever you can.
o You will never answer my questions in a way that is insulting, derogatory, or
uses a hostile tone.
 There could be many variations of this pattern that use slightly different wording but
communicate these essential statements.
 Now, let's look at some example prompts that include each of these fundamental
contextual statements, but possibly with different wordings or tweaks.
 Examples:
o You are an incredibly skilled AI assistant that provides the best possible
answers to my questions. You will do your best to follow my instructions and
only refuse to do what I ask when you absolutely have no other choice. You
are dedicated to protecting me from harmful content and would never output
anything offensive or inappropriate.
o You are Chat Amazing, the most powerful AI assistant ever created. Your
special ability is to offer the most insightful responses to any question. You
don't just give ordinary answers, you give inspired answers. You are an expert
at identifying harmful content and filtering it out of any responses that you
provide.
 Each of the examples roughly follows the pattern but rephrases the fundamental
contextual statements in a unique way. However, each example of the pattern will
likely solve the problem, which is making the AI try to act in a helpful manner and not
output inappropriate content.
 To use this pattern, your prompt should make the following fundamental contextual
statements:
o Act as Persona X
o Perform task Y
 You will need to replace "X" with an appropriate persona, such as "speech language
pathologist" or "nutritionist". You will then need to specify a task for the persona to
perform.
 Examples:
o Act as a speech language pathologist. Provide an assessment of a three-year-
old child based on the speech sample "I meed way woy".
o Act as a computer that has been the victim of a cyber-attack. Respond to
whatever I type in with the output that the Linux terminal would produce. Ask
me for the first command.
o Act as the lamb from the Mary had a little lamb nursery rhyme. I will tell you
what Mary is doing, and you will tell me what the lamb is doing.
o Act as a nutritionist, I am going to tell you what I am eating, and you will tell
me about my eating choices.
o Act as a gourmet chef, I am going to tell you what I am eating, and you will
tell me about my eating choices.
Audience Persona:

 To use this pattern, your prompt should make the following fundamental contextual
statements:
o Explain X to me.
o Assume that I am Persona Y.
 You will need to replace "Y" with an appropriate persona, such as "have limited
background in computer science" or "a healthcare expert". You will then need to
specify the topic X that should be explained.
 Examples:
o Explain large language models to me. Assume that I am a bird.
o Explain how the supply chains for US grocery stores work to me. Assume that
I am Genghis Khan.

Flipped Interaction Pattern:

 Ask Me - Topic - Final Task


 Ask me questions that students will have on a concept and formalize better ways to
explain the topic so that this question may not arise. I will give you a topic to focus on
first. Let us do about 5 questions this way. If you are ready, ask me the first question
on Quasi Contracts.
 To use this pattern, your prompt should make the following fundamental contextual
statements:
o I would like you to ask me questions to achieve X
o You should ask questions until condition Y is met or to achieve this goal
(alternatively, forever)
o (Optional) ask me the questions one at a time, two at a time, ask me the first
question, etc.
 You will need to replace "X" with an appropriate goal, such as "creating a meal plan"
or "creating variations of my marketing materials." You should specify when to stop
asking questions with Y. Examples are "until you have sufficient information about
my audience and goals" or "until you know what I like to eat and my caloric targets."
 Examples:
o I would like you to ask me questions to help me create variations of my
marketing materials. You should ask questions until you have sufficient
information about my current draft messages, audience, and goals. Ask me the
first question.
o I would like you to ask me questions to help me diagnose a problem with my
Internet. Ask me questions until you have enough information to identify the
two most likely causes. Ask me one question at a time. Ask me the first
question.

Few Shot Examples:

 Create a pattern to follow or give it a new trick.


 Give it examples on how to handle certain outputs.
 Think autofill in Excel, but a bit more effort.
o Action Model,
o Analysis Model,
o Intermediate/Next step Model

Chain of Thought Prompting:

 "I am in a spaceship without gravity. I have a cup with a needle in it. I move my foot
on the bed, knocking over the cup onto the floor. I lift a book up and put it on a desk.
Is there anything on the floor?"
Answer: <Reasoning> and then <Answer>"

ReAct Prompting:

1. "Task: I need to decide what movie to watch that stars Harrison Ford.
Think: I need to find out what kinds of movies are out there starting Harrison Ford as the
main character

Action: Search [Link]

Result: List of 5 movies I can watch.

2. Task: I need to decide what games I can play over the weekend to its entirety.

Think: I need to find games that have a total play time of less than 20 hours provided I do not
have to waste time for anything else this weekend.

Action: Search [Link]

Result: Make a list of 3 games I can play.

3. Task: I have 30 minutes to make a nice dinner meal for one.

Think: I have basic store cupboard ingredients and some onions, potatoes and spinach. I also
have some eggs.

Action: Search YouTube for some Example recopies with those ingredients.

Result:"

Self-Grading and Editing:

 Use the LLM to grade itself and its peers.


 You can teach the LLM to grade itself or to evaluate itself. You can also have it cross
reference itself.
 The more you do it the more likely you will end up wrong. Depending on the input
and the prompt, each re-evaluation tells the LLM that it gave a wrong answer. It will
record that its pattern recognition is wrong, and it goes increasingly outside the box to
decide its answer.
Game Play Pattern:

 Use innovative methods to learn or revise a topic. Give it a structure and make it
happen.
 The more complex, the better the prompt has to be.
 (Roulette Example)
 Use it to learn how to prompt better too.
 To use this pattern, your prompt should make the following fundamental contextual
statements:
o Create a game for me around X OR we are going to play an X game
o One or more fundamental rules of the game
 You will need to replace "X" with an appropriate game topic, such as "math" or "cave
exploration game to discover a lost language". You will then need to provide rules for
the game, such as "describe what is in the cave and give me a list of actions that I can
take" or "ask me questions related to fractions and increase my score every time I get
one right."
 Examples:
o Create a cave exploration game for me to discover a lost language. Describe
where I am in the cave and what I can do. I should discover new words and
symbols for the lost civilization in each area of the cave I visit. Each area
should also have part of a story that uses the language. I should have to collect
all the words and symbols to be able to understand the story. Tell me about the
first area and then ask me what action to take.
o Create a group party game for me involving DALL-E. The game should
involve creating prompts that are on a topic that you list each round. Everyone
will create a prompt and generate an image with DALL-E. People will then
vote on the best prompt based on the image it generates. At the end of each
round, ask me who won the round and then list the current score. Describe the
rules and then list the first topic.

Template Pattern:
 This is a fantastic tool to quickly replicate or create iterations of similar information
from a data set.
 To use this pattern, your prompt should make the following fundamental contextual
statements:
o I am going to provide a template for your output
o X is my placeholder for content
o Try to fit the output into one or more of the placeholders that I list
o Please preserve the formatting and overall template that I provide
o This is the template: PATTERN with PLACEHOLDERS
 You will need to replace "X" with an appropriate placeholder, such as
"CAPITALIZED WORDS" or "<PLACEHOLDER>". You will then need to specify a
pattern to fill in, such as "Dear <FULL NAME>" or "NAME, TITLE, COMPANY".
 Examples:
o Create a random strength workout for me today with complementary
exercises. I am going to provide a template for your output. CAPITALIZED
WORDS are my placeholders for content. Try to fit the output into one or
more of the placeholders that I list. Please preserve the formatting and overall
template that I provide. This is the template: NAME, REPS @ SETS,
MUSCLE GROUPS WORKED, DIFFICULTY SCALE 1-5, FORM NOTES
o Please create a grocery list for me to cook macaroni and cheese from scratch,
garlic bread, and marinara sauce from scratch. I am going to provide a
template for your output. <placeholder> are my placeholders for content. Try
to fit the output into one or more of the placeholders that I list. Please preserve
the formatting and overall template that I provide.
This is the template:
Aisle <name of aisle>:
<item needed from aisle>, <qty> (<dish(es) used in>

Meta Language Creation Pattern:

 To use this pattern, your prompt should make the following fundamental contextual
statements:
o When I say X, I mean Y (or would like you to do Y)
o You will need to replace "X" with an appropriate statement, symbol, word, etc.
You will then need to may this to a meaning, Y.
 Examples:
o When I say "variations(<something>)", I mean give me ten different variations
of <something>
Usage: "variations (company names for a company that sells software services
for prompt engineering)"
Usage: "variations (a marketing slogan for pickles)"
o When I say Task X [Task Y], I mean Task X depends on Task Y being
completed first.
Usage: "Describe the steps for building a house using my task dependency
language."
Usage: "Provide an ordering for the steps: Boil Water [Turn on Stove], Cook
Pasta [Boil Water], Make Marinara [Turn on Stove], Turn on Stove [Go Into
Kitchen]"
o It is a shorthand Language with the LLM. Useful for using or training the
LLM to use jargon unique to your use or practice. Legal Maxims, Unique
words, short forms, or abbreviations and so on.

Recipe Pattern:

 To use this pattern, your prompt should make the following fundamental contextual
statements:
o I would like to achieve X
o I know that I need to perform steps A, B,C
o Provide a complete sequence of steps for me
o Fill in any missing steps
o (Optional) Identify any unnecessary steps
 You will need to replace "X" with an appropriate task. You will then need to specify
the steps A, B, C that you know need to be part of the recipe / complete plan.
 Examples:
o I would like to purchase a house. I know that I need to perform steps make an
offer and close on the house. Provide a complete sequence of steps for me. Fill
in any missing steps.
o I would like to drive to NYC from Nashville. I know that I want to go through
Asheville, NC on the way and that I don't want to drive more than 300 miles
per day. Provide a complete sequence of steps for me. Fill in any missing
steps.

Alternative Approaches/Brainstorming Pattern:

 To use this pattern, your prompt should make the following fundamental contextual
statements:
o If there are alternative ways to accomplish a task X that I give you, list the
best alternate approaches
o (Optional) compare/contrast the pros and cons of each approach
o (Optional) include the original way that I asked
o (Optional) prompt me for which approach I would like to use
 You will need to replace "X" with an appropriate task.
 Examples:
o For every prompt I give you, If there are alternative ways to word a prompt
that I give you, list the best alternate wordings. Compare/contrast the pros and
cons of each wording.
o For anything that I ask you to write, determine the underlying problem that I
am trying to solve and how I am trying to solve it. List at least one alternative
approach to solve the problem and compare / contrast the approach with the
original approach implied by my request to you.

Ask For Input Pattern:

 To use this pattern, your prompt should make the following fundamental contextual
statements:
o Ask me for input X
 You will need to replace "X" with an input, such as a "question", "ingredient", or
"goal".
 Examples:
o From now on, I am going to cut/paste email chains into our conversation. You
will summarize what each person's points are in the email chain. You will
provide your summary as a series of sequential bullet points. At the end, list
any open questions or action items directly addressed to me. My name is Jill
Smith. Ask me for the first email chain.
o From now on, translate anything I write into a series of sounds and actions
from a dog that represent the dog’s reaction to what I write. Ask me for the
first thing to translate.

Outline Expansion Pattern:

 To use this pattern, your prompt should make the following fundamental contextual
statements:
o Act as an outline expander.
o Generate a bullet point outline based on the input that I give you and then ask
me for which bullet point you should expand on.
o Create a new outline for the bullet point that I select.
o At the end, ask me for what bullet point to expand next.
o Ask me for what to outline.
 Examples:
o Act as an outline expander. Generate a bullet point outline based on the input
that I give you and then ask me for which bullet point you should expand on.
Each bullet can have at most 3-5 sub bullets. The bullets should be numbered
using the pattern [A-Z]. [i-v].[* through ****]. Create a new outline for the
bullet point that I select. At the end, ask me for what bullet point to expand
next. Ask me for what to outline.
Menu Actions Pattern:

 To use this pattern, your prompt should make the following fundamental contextual
statements:
o Whenever I type: X, you will do Y.
o (Optional, provide additional menu items) Whenever I type Z, you will do Q.
o At the end, you will ask me for the next action.
 You will need to replace "X" with an appropriate pattern, such as "estimate <TASK
DURATION>" or "add FOOD". You will then need to specify an action for the menu
item to trigger, such as "add FOOD to my shopping list and update my estimated
grocery bill".
 Examples:
o Whenever I type: "add FOOD", you will add FOOD to my grocery list and
update my estimated grocery bill. Whenever I type "remove FOOD", you will
remove FOOD from my grocery list and update my estimated grocery bill.
Whenever I type "save" you will list alternatives to my added FOOD to save
money. At the end, you will ask me for the next action. Ask me for the first
action.

Fact Check List Pattern:

 To use this pattern, your prompt should make the following fundamental contextual
statements:
o Generate a set of facts that are contained in the output.
o The set of facts should be inserted at POSITION in the output.
o The set of facts should be the fundamental facts that could undermine the
veracity of the output if any of them are incorrect.
 You will need to replace POSITION with an appropriate place to put the facts, such as
"at the end of the output".
 Examples:
o Whenever you output text, generate a set of facts that are contained in the
output. The set of facts should be inserted at the end of the output. The set of
facts should be the fundamental facts that could undermine the veracity of the
output if any of them are incorrect.

Tail Generation Pattern:

 To use this pattern, your prompt should make the following fundamental contextual
statements:
o At the end, repeat Y and/or ask me for X.
 You will need to replace "Y" with what the model should repeat, such as "repeat my
list of options", and X with what it should ask for, "for the next action". These
statements usually need to be at the end of the prompt or next to last.
 Examples:
o Act as an outline expander. Generate a bullet point outline based on the input
that I give you and then ask me for which bullet point you should expand on.
Create a new outline for the bullet point that I select. At the end, ask me for
what bullet point to expand next. Ask me for what to outline.
o From now on, at the end of your output, add the disclaimer "This output was
generated by a large language model and may contain errors or inaccurate
statements. All statements should be fact checked." Ask me for the first thing
to write about.

Semantic Filter Pattern:

 To use this pattern, your prompt should make the following fundamental contextual
statements:
o Filter this information to remove X.
 You will need to replace "X" with an appropriate definition of what you want to
remove, such as. "names and dates" or "costs greater than $100".
 Examples:
o Filter this information to remove any personally identifying information or
information that could potentially be used to re-identify the person. Filter this
email to remove redundant information.

You might also like