Prompt Engineering
Prompt Engineering
This guide shares strategies and tactics for getting better results
from large language models (sometimes referred to as GPT models)
like GPT-4o. The methods described here can sometimes be
deployed in combination for greater effect. We encourage
experimentation to find the methods that work best for you.
You can also explore example prompts which showcase what our
models are capable of:
Prompt examples
Explore prompt examples to learn what GPT models can do
These models can’t read your mind. If outputs are too long, ask for
brief replies. If outputs are too simple, ask for expert-level writing. If
you dislike the format, demonstrate the format you’d like to see.
The less the model has to guess at what you want, the more likely
you’ll get it.
Tactics:
Tactics:
Tactics:
Tactics:
Instruct the model to work out its own solution before rushing
to a conclusion
Use inner monologue or a sequence of queries to hide the
model's reasoning process
Ask the model if it missed anything on previous passes
Tactics:
Tactic:
Tactics
Each of the strategies listed above can be instantiated with specific
tactics. These tactics are meant to provide ideas for things to try.
They are by no means fully comprehensive, and you should feel free
to try creative ideas not represented here.
Worse Better
SYSTEM
When I ask for help to write something, you will reply with a
document that contains at least one joke or playful comment in
every paragraph.
USER
Write a thank you note to my steel bolt vendor for getting the
delivery in on time and in short notice. This made it possible for us
to deliver an important order.
Open in Playground
Delimiters like triple quotation marks, XML tags, section titles, etc.
can help demarcate sections of text to be treated differently.
USER
Summarize the text delimited by triple quotes with a haiku. """insert
text here"""
Open in Playground
SYSTEM
You will be provided with a pair of articles (delimited with XML tags)
about the same topic. First summarize the arguments of each
article. Then indicate which of them makes a better argument and
explain why.
USER
<article> insert first article here </article> <article> insert second
article here </article>
Open in Playground
SYSTEM
You will be provided with a thesis abstract and a suggested title for
it. The thesis title should give the reader a good idea of the topic of
the thesis but should also be eye-catching. If the title does not meet
these criteria, suggest 5 alternatives.
USER
Abstract: insert abstract here Title: insert title here
Open in Playground
SYSTEM
Use the following step-by-step instructions to respond to user
inputs. Step 1 - The user will provide you with text in triple quotes.
Summarize this text in one sentence with a prefix that says
"Summary: ". Step 2 - Translate the summary from Step 1 into
Spanish, with a prefix that says "Translation: ".
USER
"""insert text here"""
Open in Playground
SYSTEM
Answer in a consistent style.
USER
Teach me about patience.
ASSISTANT
The river that carves the deepest valley flows from a modest spring;
the grandest symphony originates from a single note; the most
intricate tapestry begins with a solitary thread.
USER
Teach me about the ocean.
Open in Playground
You can ask the model to produce outputs that are of a given target
length. The targeted output length can be specified in terms of the
count of words, sentences, paragraphs, bullet points, etc. Note
however that instructing the model to generate a specific number of
words does not work with high precision. The model can more
reliably generate outputs with a specific number of paragraphs or
bullet points.
USER
Summarize the text delimited by triple quotes in about 50 words.
"""insert text here"""
Open in Playground
USER
Summarize the text delimited by triple quotes in 2 paragraphs.
"""insert text here"""
Open in Playground
USER
Summarize the text delimited by triple quotes in 3 bullet points.
"""insert text here"""
Open in Playground
SYSTEM
Use the provided articles delimited by triple quotes to answer
questions. If the answer cannot be found in the articles, write "I
could not find an answer."
USER
<insert articles, each delimited by triple quotes> Question: <insert
question here>
Open in Playground
Given that all models have limited context windows, we need some
way to dynamically lookup information that is relevant to the
question being asked. Embeddings can be used to implement
efficient knowledge retrieval. See the tactic "Use embeddings-
based search to implement efficient knowledge retrieval" for more
details on how to implement this.
SYSTEM
You will be provided with a document delimited by triple quotes and
a question. Your task is to answer the question using only the
provided document and to cite the passage(s) of the document used
to answer the question. If the document does not contain the
information needed to answer this question then simply write:
"Insufficient information." If an answer to the question is provided,
it must be annotated with a citation. Use the following format for to
cite relevant passages ({"citation": …}).
USER
"""<insert document here>""" Question: <insert question here>
Open in Playground
SYSTEM
You will be provided with customer service queries. Classify each
query into a primary category and a secondary category. Provide
your output in json format with the keys: primary and secondary.
Primary categories: Billing, Technical Support, Account
Management, or General Inquiry. Billing secondary categories: -
Unsubscribe or upgrade - Add a payment method - Explanation for
charge - Dispute a charge Technical Support secondary categories: -
Troubleshooting - Device compatibility - Software updates Account
Management secondary categories: - Password reset - Update
personal information - Close account - Account security General
Inquiry secondary categories: - Product information - Pricing -
Feedback - Speak to a human
USER
I need to get my internet working again.
Open in Playground
SYSTEM
You will be provided with customer service inquiries that require
troubleshooting in a technical support context. Help the user by: -
Ask them to check that all cables to/from the router are connected.
Note that it is common for cables to come loose over time. - If all
cables are connected and the issue persists, ask them which router
model they are using - Now you will advise them how to restart their
device: -- If the model number is MTD-327J, advise them to push the
red button and hold it for 5 seconds, then wait 5 minutes before
testing the connection. -- If the model number is MTD-327S, advise
them to unplug and replug it, then wait 5 minutes before testing the
connection. - If the customer's issue persists after restarting the
device and waiting 5 minutes, connect them to IT support by
outputting {"IT support requested"}. - If the user starts asking
questions that are unrelated to this topic then confirm if they would
like to end the current chat about troubleshooting and classify their
request according to the following scheme: <insert
primary/secondary classification scheme from above here>
USER
I need to get my internet working again.
Open in Playground
Notice that the model has been instructed to emit special strings to
indicate when the state of the conversation changes. This enables
us to turn our system into a state machine where the state
determines which instructions are injected. By keeping track of
state, what instructions are relevant at that state, and also
optionally what state transitions are allowed from that state, we
can put guardrails around the user experience that would be hard to
achieve with a less structured approach.
SYSTEM
Determine if the student's solution is correct or not.
USER
Problem Statement: I'm building a solar power installation and I
need help working out the financials. - Land costs $100 / square foot
- I can buy solar panels for $250 / square foot - I negotiated a
contract for maintenance that will cost me a flat $100k per year,
and an additional $10 / square foot What is the total cost for the first
year of operations as a function of the number of square feet.
Student's Solution: Let x be the size of the installation in square
feet. 1. Land cost: 100x 2. Solar panel cost: 250x 3. Maintenance
cost: 100,000 + 100x Total cost: 100x + 250x + 100,000 + 100x =
450x + 100,000
ASSISTANT
The student's solution is correct.
Open in Playground
But the student's solution is actually not correct! We can get the
model to successfully notice this by prompting the model to
generate its own solution first.
SYSTEM
First work out your own solution to the problem. Then compare your
solution to the student's solution and evaluate if the student's
solution is correct or not. Don't decide if the student's solution is
correct until you have done the problem yourself.
USER
Problem Statement: I'm building a solar power installation and I
need help working out the financials. - Land costs $100 / square foot
- I can buy solar panels for $250 / square foot - I negotiated a
contract for maintenance that will cost me a flat $100k per year,
and an additional $10 / square foot What is the total cost for the first
year of operations as a function of the number of square feet.
Student's Solution: Let x be the size of the installation in square
feet. 1. Land cost: 100x 2. Solar panel cost: 250x 3. Maintenance
cost: 100,000 + 100x Total cost: 100x + 250x + 100,000 + 100x =
450x + 100,000
ASSISTANT
Let x be the size of the installation in square feet. 1. Land cost:
100x 2. Solar panel cost: 250x 3. Maintenance cost: 100,000 + 10x
Total cost: 100x + 250x + 100,000 + 10x = 360x + 100,000 The
student's solution is incorrect. They made an error in the
maintenance cost calculation, using 100x instead of 10x. The
correct total cost for the first year of operations is 360x + 100,000.
Open in Playground
SYSTEM
Follow these steps to answer the user queries. Step 1 - First work
out your own solution to the problem. Don't rely on the student's
solution since it may be incorrect. Enclose all your work for this
step within triple quotes ("""). Step 2 - Compare your solution to the
student's solution and evaluate if the student's solution is correct or
not. Enclose all your work for this step within triple quotes (""").
Step 3 - If the student made a mistake, determine what hint you
could give the student without giving away the answer. Enclose all
your work for this step within triple quotes ("""). Step 4 - If the
student made a mistake, provide the hint from the previous step to
the student (outside of triple quotes). Instead of writing "Step 4 - ..."
write "Hint:".
USER
Problem Statement: <insert problem statement> Student Solution:
<insert student solution>
Open in Playground
First, we can ask the model to solve the problem on its own. Since
this initial query doesn't require the student’s solution, it can be
omitted. This provides the additional advantage that there is no
chance that the model’s solution will be biased by the student’s
attempted solution.
USER
<insert problem statement>
Open in Playground
Next, we can have the model use all available information to assess
the correctness of the student’s solution.
SYSTEM
Compare your solution to the student's solution and evaluate if the
student's solution is correct or not.
USER
Problem statement: """<insert problem statement>""" Your solution:
"""<insert model generated solution>""" Student’s solution:
"""<insert student's solution>"""
Open in Playground
Finally, we can let the model use its own analysis to construct a
reply in the persona of a helpful tutor.
SYSTEM
You are a math tutor. If the student made an error, offer a hint to
the student in a way that does not reveal the answer. If the student
did not make an error, simply offer them an encouraging comment.
USER
Problem statement: """<insert problem statement>""" Your solution:
"""<insert model generated solution>""" Student’s solution:
"""<insert student's solution>""" Analysis: """<insert model
generated analysis from previous step>"""
Open in Playground
Tactic: Ask the model if it missed anything on previous
passes
SYSTEM
You will be provided with a document delimited by triple quotes.
Your task is to select excerpts which pertain to the following
question: "What significant paradigm shifts have occurred in the
history of artificial intelligence." Ensure that excerpts contain all
relevant context needed to interpret them - in other words don't
extract small snippets that are missing important context. Provide
output in JSON format as follows: [{"excerpt": "..."}, ... {"excerpt":
"..."}]
USER
"""<insert document here>"""
ASSISTANT
[{"excerpt": "the model writes an excerpt here"}, ... {"excerpt": "the
model writes another excerpt here"}]
USER
Are there more relevant excerpts? Take care not to repeat
excerpts. Also ensure that excerpts contain all relevant context
needed to interpret them - in other words don't extract small
snippets that are missing important context.
Open in Playground
SYSTEM
You can write and execute Python code by enclosing it in triple
backticks, e.g. ```code goes here```. Use this to perform calculations.
USER
Find all real-valued roots of the following polynomial: 3*x**5 -
5*x**4 - 3*x**3 - 7*x - 10.
Open in Playground
Another good use case for code execution is calling external APIs.
If a model is instructed in the proper use of an API, it can write code
that makes use of it. A model can be instructed in how to use an API
by providing it with documentation and/or code samples showing
how to use the API.
SYSTEM
You can write and execute Python code by enclosing it in triple
backticks. Also note that you have access to the following module
to help users send messages to their friends: ```python import
message message.write(to="John", message="Hey, want to meetup
after work?")```
Open in Playground
30% ~10
10% ~100
3% ~1,000
1% ~10,000
SYSTEM
<insert system message above>
USER
"""Neil Armstrong is famous for being the first human to set foot on
the Moon. This historic event took place on July 21, 1969, during the
Apollo 11 mission."""
Open in Playground
SYSTEM
<insert system message above>
USER
"""Neil Armstrong made history when he stepped off the lunar
module, becoming the first person to walk on the moon."""
Open in Playground
SYSTEM
<insert system message above>
USER
"""In the summer of '69, a voyage grand, Apollo 11, bold as legend's
hand. Armstrong took a step, history unfurled, "One small step," he
said, for a new world."""
Open in Playground
SYSTEM
Use the following steps to respond to user inputs. Fully restate each
step before proceeding. i.e. "Step 1: Reason...". Step 1: Reason step-
by-step about whether the information in the submitted answer
compared to the expert answer is either: disjoint, equal, a subset, a
superset, or overlapping (i.e. some intersection but not
subset/superset). Step 2: Reason step-by-step about whether the
submitted answer contradicts any aspect of the expert answer.
Step 3: Output a JSON object structured like: {"type_of_overlap":
"disjoint" or "equal" or "subset" or "superset" or "overlapping",
"contradiction": true or false}
Here's an example input with a substandard answer which
nonetheless does not contradict the expert answer:
SYSTEM
<insert system message above>
USER
Question: """What event is Neil Armstrong most famous for and on
what date did it occur? Assume UTC time.""" Submitted Answer:
"""Didn't he walk on the moon or something?""" Expert Answer:
"""Neil Armstrong is most famous for being the first person to walk
on the moon. This historic event occurred on July 21, 1969."""
Open in Playground
SYSTEM
<insert system message above>
USER
Question: """What event is Neil Armstrong most famous for and on
what date did it occur? Assume UTC time.""" Submitted Answer:
"""On the 21st of July 1969, Neil Armstrong became the second
person to walk on the moon, following after Buzz Aldrin.""" Expert
Answer: """Neil Armstrong is most famous for being the first person
to walk on the moon. This historic event occurred on July 21,
1969."""
Open in Playground
SYSTEM
<insert system message above>
USER
Question: """What event is Neil Armstrong most famous for and on
what date did it occur? Assume UTC time.""" Submitted Answer:
"""At approximately 02:56 UTC on July 21st 1969, Neil Armstrong
became the first human to set foot on the lunar surface, marking a
monumental achievement in human history.""" Expert Answer:
"""Neil Armstrong is most famous for being the first person to walk
on the moon. This historic event occurred on July 21, 1969."""
Open in Playground
Other resources
For more inspiration, visit the OpenAI Cookbook, which contains
example code and also links to third-party resources such as: