ChatGPT Prompting: Useful Patterns And How To Use Them?

ChatGPT: A type of Large Language Models

Today is Sunday, November 5, 2023. I’m sitting here at the table in my memorable place, which used to be my studying room at my little home back then since I was only a elementary, secondary, and high school student. Such good gold memories are spilling my mind right now and I’m reckoning to writing something that I find it useful for me and for everyone as well. Taking advantage of what I’ve been learning recently on Coursera, which is Prompt Engineering for ChatGPT taught by Dr. Jules White, Vanderbilt University, it’d be a great chance to summarize all of the helpful prompting patterns here for convenient usage when someone is in need. I hope you guys are having a good day.

Pattern 1: The Persona Pattern

Taking Helpful Assistant Pattern as an example. 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.
In this pattern, it’s like you’re giving the ChatBot a characteristic or trait specially owned by this type of subject that you want to ask for. To efficiently use it, your prompt should communicate the following things:

  • You are a helpful AI assistant.
  • You will answer my questions or follow my instructions whenever you can.
  • You will never answer my questions in a way that is insulting, derogatory, or uses a hostile tone.

Some Examples:

  • 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.
  • You are ChatAmazing, 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.

The Persona Pattern Format:

  • Act as Persona X
  • Peform task Y

Some Examples:

  • 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.
  • Act as a nutritionist, I am going to tell you what I am eating and you will tell me about my eating choices.

Pattern 2: The Question Refinement Pattern

To use this pattern effectively, your prompts should say the following structure:

  • From now on, whenever I ask a question, suggest a better version of the question to use instead
  • Prompt me if I would like to use the better version instead (Optional)

Some Examples:

  • From now on, whenever I ask a question, suggest a better version of the question to use instead
  • From now on, whenever I ask a question, suggest a better version of the question and ask me if I would like to use it instead

Tailored Examples:

  • 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.

Pattern 3: The Cognitive Verifier Pattern

To use this pattern, your prompts should have the following structure:

  • When you are asked a question, follow these rules
  • Generate a number of additional questions that would help more accurately answer the question
  • Combine the answers to the individual questions to produce the final answer to the overall question

Some Examples:

  • When you are asked a question, follow these rules. Generate a number of additional questions that would help you more accurately answer the question. Combine the answers to the individual questions to produce the final answer to the overall question.

Tailored Examples:

  • 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.

Pattern 4: The Audience Persona Pattern

To use this pattern, your prompt should make the following fundamental contextual statements:

  • Explain X to me.
  • 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.

Some Examples:

  • Explain large language models to me. Assume that I am a 5-year-old kid.

Pattern 5: The Flipped Interaction Pattern

Your prompts should follow the structure below to mostly benefit from LLMs:

  • I would like you to ask me questions to achieve X
  • You should ask questions until condition Y is met or to achieve this goal (alternatively, forever)
  • Ask me the questions one at a time, two at a time, ask me the first question, etc. (Optional)

You have to replace “X” with an appropriate goal and specify when to stop asking questions with Y. For instance, “when you have sufficient information about my audience and goals”.

Some Examples:

  • 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.
  • 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.

Pattern 6: The Few-Shot Examples

The idea behind this method is just to develop a pattern in order for LLMs to know how to give the appropriate answers based on the given pattern.

Some Examples:

  • Sentiment Analysis
    Your prompt:
    Input: The movie was good but a bit too long
    Sentiment: Neutral
    Input: I didn’t really like this book, it lacked important details and ended up making no sense
    Sentiment: Negative
    Input: I love this book, it was really good in learning how to impove my gut health
    Sentiment: Positive
    Input: I wasn’t sure what to think of this new restaurant, the service was slow, but the dishes were pretty good
    Sentiment:
    Answer:
    Neutral
    Your prompt:
    I really hated this coffee, it was roasted too much and tasted burned
    Answer:
    Negative

  • With Actions
    Your prompt:
    Situation: I’m travelling 60 miles per hour and I see the brake lights on the car in front of me come on
    Action: Brake
    Situation: I have just entered the high way from an on-ramp and am travelling 30mph
    Action: Accelerate
    Situation: A deer has darted out in front of my car while I’m travelling 15mph and the road has a large shoulder
    Action: Brake and serve into the shoulder
    Situation: I’m backing out of a parking spot and I see the reverse lights illuminate on the car behind me
    Action:
    Answer:
    Stop and wait for the car to back out before proceeding

  • With Imtermediate Steps
    Your prompt:
    Situation: I’m travelling 60 miles per hour and I see the brake lights on the car in front of me come on
    Think: I need to slow the car down before I hit the car in front of me
    Action: Press foot on brake
    Think: The car isn’t going to stop in time
    Action: Check if the shoulder is wide enough to swerve into
    Think: The shoulder is wide enough
    Action: Swerve into shoulder
    Situation: I have just entered the high way from an on-ramp and am travelling 30mph
    Think: I need to speed up to the speed limit so that I don’t get hit from behind
    Action: Press foot on accelerator
    Think: I have reached the speed limit
    Action: Let up on accelerator
    Situation: I’m backing out of a parking spot and I see the reverse lights illuminate on the car behind me
    Action:
    Answer:
    Immediately stop backing up
    Think: I need to check my surroundings to make sure it’s safe to continue backing up
    Action: Check mirrors and surroundings for any obstacles or pedestrians
    Think: It’s safe to continue backing up
    Action: Continue backing up slowly and carefully while keeping an eye on surroundings

Pattern 7: Chain of Thoughts Prompting

Example without Chain of Thoughts
Your prompt:
Q: I have four bike racers start a race and travel an average of 30mph. They each race for 2 hours. Is the total number of miles ridden by all riders greater than 200?
A: Answer - YES
Q: I have a staging process for a bike race to line up racers. It takes 47s to stage a group of 8 riders and 67s to get the group to the starting gate and ready to race. I want a new group to start the race every 30s. Do I need 8 groups staged at all times in order to have races continually starting every 30s?
A: Answer - NO
Q: I am in a space ship 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 anything on the floor?
A: Answer - <ANSWER>
Answer:
A: Answer - YES. When the cup with the needle in it is knocked over onto the floor, both the cup and the needle will end up on the floor. In the absence of gravity, objects will not fall downward as they do on Earth, but they will still move in response to forces applied to them. In this case, the force applied by your foot knocking over the cup will cause the cup and the needle to move and come to rest on the floor. Lifting a book and putting it on a desk does not affect the position of the cup and the needle, so they will remain on the floor.

Example with Chain of Thoughts:
Your prompt:
Q: I have four bike racers start a race and travel an average of 30mph. They each race for 2 hours. Is the total number of miles ridden by all riders greater than 200?
A: Reasoning - Each rider will ride 30mph x 2hrs = 60miles. I have four riders. Therefore, the total number of miles ridden by the riders is 4 x 60 miles = 240 miles. Answer - YES
Q: I have a staging process for a bike race to line up racers. It takes 47s to stage a group of 8 riders and 67s to get the group to the starting gate and ready to race. I want a new group to start the race every 30s. Do I need 8 groups staged at all times in order to have races continually starting every 30s?
A: Reasoning - Each group takes 47s + 67s = 114s to be ready to race. In order to race every 30s, I will need to calculate how many races will need to run before a group is ready to race. A group will have 114s / 30s = 3.8s races run before it is ready to race. I can’t have a partial group, so I need to round up to 4. I only need 4 groups staged to be able to race every 30s, so I do not need 8 groups. Answer - NO
Q: I am in a space ship 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 anything on the floor?
A: Reasoning - <REASONING> Answer - <ANSWER>
Answer:
A: Reasoning - In a spaceship without gravity, objects do not behave as they do on Earth with gravity. When the cup with the needle in it is knocked over, the cup and the needle will not fall to the “floor” as they would on Earth. Instead, they will float in place or move in the direction of the force applied to the. Similarly, when the book is lifted and placed on the desk, it will not stay on the desk as it would on Earth; it will float away from the desk unless secured in place. Therefore, in the absence of gravity, there is no concept of objects being “on the floor” as we understand it on Earth. Answer - NO (Because there is no concept of “on the floor” in a zero-gravity environment)

Pattern 8: ReAct Prompting

The idea behind this is to teach LLMs think through what tools it need to solve a task or do an action. The way we write these types of prompts is very similar to Chain of Thoughts
Example:
Your prompt:
Task: Calculate when I need to arrive at the Music City BMX National Race for my son to be on time for his 9-10 Open race.
Think: I need to find out what time the first race begins. I can use a web search of the Music City BMX site to get the information.
Action: SEARCH https://www.musiccitybmx.com
Result: All races start at 9am.
Think: I need to find out how many motos run before the 9-10 Open race. I can use a web search of the Music City BMX site to get the information.
Action: SEARCH https://www.musiccitybmx.com
Result: There are 30 motos that run before the 9-10 Open race.
Think: I need to find out how long each moto took last year. I can use the video live stream from the USA BMX website to and record how long the first ten motos took.
Action: VIDEO https://www.usabmx.com/live/2022/musiccitybmx/live.mp4
Result: The first 10 motos took 5mins
Think: If 10 motos took 5mins, 30 motos will take 15mins. The race starts at 9am, so I need to arrive before 9:15am when the race starts. I will arrive 30mins early at 8:45am to be safe.
Task: Calculate what time my 36-40 novice race will end at the USA BMX Grand Nationals.
Think:
Answer:
I need to find out what time the first race begin at the USA BMX Grand Nationals. I can use a web search of the USA BMX site to get the information.
Action: SEARCH https://www.usabmx.com/events/grands
Result: [Note: As an Al language model, I am unable to perform web searches. Please assume a hypothetical result for the purpose of this exercise.] The first race begins at 8am.
Think: I need to find out how many motos run before the 36-40 Novice race at the USA BMX
Grand Nationals. I can use a web search of the USA BMX site to get the information.
Action: SEARCH https://www.usabmx.com/events/grands
Result: [Hypothetical result] There are 120 motos that run before the 36-40 Novice race.
Think: I need to find out how long each moto took last year at the USA BMX Grand Nationals. I can use the video live stream from the USA BMX website to record how long the first ten motos took.
Action: VIDEO https://www.usabmx.com/live/2022/grands/live.mp4
Result: [Hypothetical result] The first 10 motos took 6 minutes

Pattern 9: The Game Play Pattern

To use this pattern, your prompt should make the following fundamental contextual statements:

  • Create a game for me around X OR we are going to play an X game
  • 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:

  • 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.
  • 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.

Pattern 10: The Template Pattern

To use this pattern, your prompt should make the following fundamental contextual statements:

  • I am going to provide a template for your output
  • X is my placeholder 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: 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:

  • 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
  • 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>)

Pattern 11: The Meta Language Creation Pattern

To use this pattern, your prompt should make the following fundamental contextual statements:

  • When I say X, I mean Y (or would like you to do Y)

You will need to replace “X” with an appropriate statement, symbol, word, etc. You will then need to say this to a meaning, Y.

Examples:

  • 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)”
  • 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]”

Pattern 12: The Recipe Pattern

To use this pattern, your prompt should make the following fundamental contextual statements:

  • I would like to achieve X
  • I know that I need to perform steps A,B,C
  • Provide a complete sequence of steps for me
  • Fill in any missing steps
  • (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:

  • 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.

Pattern 13: The Alternative Approaches Pattern

To use this pattern, your prompt should make the following fundamental contextual statements:

  • If there are alternative ways to accomplish a task X that I give you, list the best alternate approaches
  • (Optional) compare/contrast the pros and cons of each approach
  • (Optional) include the original way that I asked
  • (Optional) prompt me for which approach I would like to use

You will need to replace “X” with an appropriate task.

Examples:

  • 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.
  • 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.

Pattern 14: The Ask for Input Pattern

To use this pattern, your prompt should make the following fundamental contextual statements:

  • Ask me for input X

You will need to replace “X” with an input, such as a “question”, “ingredient”, or “goal”.

Examples:

  • 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.
  • From now on, translate anything I write into a series of sounds and actions from a dog that represent the dogs reaction to what I write. Ask me for the first thing to translate.

Pattern 15: The Outline Expansion Pattern

To use this pattern, your prompt should make the following fundamental contextual statements:

  • 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.

Examples:

  • 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.

Pattern 16: The Menu Actions Pattern

To use this pattern, your prompt should make the following fundamental contextual statements:

  • Whenever I type: X, you will do Y.
  • (Optional, provide additional menu items) Whenever I type Z, you will do Q.
  • 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:

  • 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.

Pattern 17: The Fact Check List Pattern

To use this pattern, your prompt should make the following fundamental contextual statements:

  • Generate a set of facts that are contained in the output
  • The set of facts should be inserted at POSITION in 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

You will need to replace POSITION with an appropriate place to put the facts, such as “at the end of the output”.

Examples:

  • 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.

Pattern 18: The Tail Generation Pattern

To use this pattern, your prompt should make the following fundamental contextual statements:

  • 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:

  • 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.
  • 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.

Pattern 19: The Semantic Filter Pattern

To use this pattern, your prompt should make the following fundamental contextual statements:

  • 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:

  • 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.
Author

Sononymous (Son Nguyen)

Posted on

2023-11-05

Updated on

2023-12-06

Licensed under