OpenAI prompt engineering best practices, with prompts to copy
The OpenAI prompt engineering best practices come down to a few habits: put rules and inputs in separate messages, give the prompt a clear structure, show examples, name the goal, and test every change. Each one is below with a prompt.
This page follows OpenAI's own documentation. Each section gives you a prompt to copy, what to change in it and where it tends to break. If you are new to the subject, start with what prompt engineering is.
Start with a prompt that has four parts
OpenAI's guide says to organize a developer message into four parts, usually in this order: identity, instructions, examples and context. Context goes near the end because it may change from one request to the next.
Four-part prompt
What to change: the role, the limits and the example. Replace the context block each time the facts change; leave the top alone.
Where it breaks: if the context is long and messy, the model may lean on the wrong part. Trim it to what the task needs. Instructions that contradict each other also cause trouble, so read the prompt once as a stranger would.
Use message roles and clear separators
In the API, developer messages carry the rules and business logic, and user messages carry the input. Developer instructions take priority over user ones. In plain ChatGPT you have no such roles, so the same idea means keeping your rules apart from the material you paste in.
OpenAI suggests Markdown headers and lists to mark sections of a prompt, and XML tags to show where a piece of reference content starts and ends. OpenAI's help article on the API makes the same point with ### or triple quotes: put the instruction first, then separate it from the context.
Rules apart from material
What to change: the audience, the bullet count and the rules. Where it breaks: if the pasted text contains its own instructions, the model may follow them. See prompt injection for how to guard against that.
Say what you want, not only what to avoid
OpenAI's help article asks you to be specific about the context, the outcome, the length, the format and the style. It also advises telling the model what to do instead of only listing what not to do.
The newest model guide adds a point about goals. For work that can run without supervision, say which outcome to reach and which decisions need your input. It also says to give the model room to make reasonable assumptions on longer tasks and keep working.
Outcome-first task brief
What to change: every bracket. Where it breaks: a goal like "make it better" gives the model nothing to aim at. Name the result you would accept. For more on this habit, read prompt discipline for outcome oriented AI.
Show examples, then check they fit
Few-shot prompting means putting input and output examples in the prompt. OpenAI says to show a diverse range of possible inputs with the desired outputs. The help article describes a sensible order: try zero-shot first, then few-shot, and consider fine-tuning only if neither works.
Few-shot classifier
What to change: the labels and the examples. Pick examples that differ from each other. Where it breaks: if all your examples look alike, the model copies that pattern even when the new input is different.
Match the prompt to the kind of model
OpenAI's guide says reasoning models give better results with high-level guidance, while GPT models need more explicit instructions. A prompt that suits one can be too thin or too heavy for the other.
| Reasoning models | GPT models | |
|---|---|---|
| How to instruct | Keep prompts simple and direct, and be specific about the end goal | Spell out the steps and the rules |
| Step-by-step requests | OpenAI says "think step by step" may not help and can sometimes hurt | Fine to include when the task needs a method |
| Examples | Try zero-shot first, then few-shot if needed | Use diverse examples to show the format |
Lean prompt for a reasoning model
What to change: the goal, the success criteria and the limits. Where it breaks: adding long step lists or "explain your reasoning" to this kind of prompt works against the advice above. If you use the Claude family as well, compare with the Anthropic prompt engineering guide.
Model names change often. Check OpenAI's latest model page before you copy a model name into code.
Treat the prompt as code: pin, store and test
For production apps, OpenAI says to pin to specific model snapshots so behavior stays consistent. It also says to store production prompts in your application code and to build tests and evaluation suites that measure prompt behavior, especially when you change or upgrade models.
Another tip is about cost and speed: put reusable instructions in the first developer message, so the shared start of every request can be cached.
Prompt test-case writer
What to change: the prompt and the counts. Where it breaks: the expected outputs are the model's guess, so review them yourself before you trust them as a test suite.
Questions
Where can I find the official OpenAI prompt engineering guide?
OpenAI publishes it in its API documentation under the prompt engineering guide. Its help center also has an article called best practices for prompt engineering with the OpenAI API.
Do these tips work in ChatGPT, or only in the API?
The ideas of clear structure, examples, separators and a stated goal carry over to ChatGPT. Message roles and model pinning apply to the API.
Should I tell a reasoning model to think step by step?
OpenAI's guidance says this may not help reasoning models, because they reason internally, and it can sometimes hurt results. Give a clear goal instead.
How many examples should I put in a prompt?
OpenAI gives no fixed number. It says to show a diverse range of inputs with the desired outputs, and to try zero-shot first before adding examples.
Are the same practices useful with other AI tools?
Many are: clear structure, specific goals and testing are not tied to one vendor. Check each vendor's own guide for model-specific advice.
Sources
- Prompt engineering – OpenAI
- Reasoning best practices – OpenAI
- Using the latest model – OpenAI
- Best practices for prompt engineering with the OpenAI API – OpenAI Help Center
