aiwithgrant
about me
aiwithgrantGuidesOpenAI
OpenAI
OpenAI
Official Docs
Beginner

The Complete OpenAI Prompt Engineering Guide

Everything from OpenAI's official prompt engineering docs. Six core strategies with tactics, examples, and real before/after comparisons.

Official OpenAI docs →
Content sourced from official OpenAI documentation
1

The six strategies

OpenAI's guide is built around six core strategies, each with specific tactics you can apply immediately: 1) Write clear instructions, 2) Provide reference text, 3) Split complex tasks into subtasks, 4) Give models time to think, 5) Use external tools, 6) Test changes systematically. Master these in order and you'll get dramatically better results from any GPT model.

💡Most people only need the first three strategies. Start there before going deeper.
2

Write clear instructions

The number one mistake is being vague. GPT can't read your mind. Include details about the desired context, outcome, length, format, and style. Ask the model to adopt a persona for domain expertise. Use delimiters (triple quotes, XML tags, markdown headers) to separate instructions from content. Specify exact steps for multi-part tasks. Provide examples of desired output. Instead of 'summarize this', say 'summarize in 3 bullet points, each under 20 words, focusing on business impact.'

💡Think of it like delegating to a new contractor. The more specific your brief, the less revision you'll need.
Product description
Write a product description for our AirPods Max competitor.

Constraints:
- 80-100 words
- Target audience: audiophiles aged 25-40
- Highlight: 40-hour battery, spatial audio, titanium build
- Tone: premium but not pretentious
- End with a single-line CTA
- Do not use superlatives like 'best' or 'revolutionary'
The vague prompt gets generic marketing fluff. The specific prompt gets a focused, on-brand description that needs zero editing.
3

Provide reference text

When you need factual accuracy, give the model source material and instruct it to answer using only that text. This is the simplest form of RAG (Retrieval-Augmented Generation) and dramatically reduces hallucination. You can instruct the model to answer with citations from the provided text, or to say 'I don't know' if the answer isn't in the source material.

💡The more your reference text resembles the final answer format, the less work the model does and the fewer errors it makes.
Answering from docs
Answer the customer's question using ONLY the policy document below. If the answer isn't in the document, say 'I don't have that information in the current policy document.'

<policy>
{{REFUND_POLICY}}
</policy>

Customer question: What is the refund policy for digital purchases?
Without reference text, the model guesses and might hallucinate a policy. With it, the model quotes directly and admits when it doesn't know.
4

Split complex tasks into subtasks

Complex tasks have higher error rates than simple ones. Instead of one massive prompt, break the work into a pipeline of focused steps. Use intent classification first to route to the right instructions. For long conversations, summarize previous dialogue to maintain context without hitting token limits. Think of it like software engineering: decompose the problem.

💡If your prompt is longer than a page, it probably needs to be split into multiple steps.
Customer service routing
Step 1 - Classify the inquiry:
'Categorize this customer message into: billing, returns, technical, account, or general.'

Step 2 - Route to specialized prompt:
Each category has its own focused prompt with specific instructions, tone, and available actions.

Step 3 - Generate response:
The specialized prompt handles the actual response with full context for that category.
One massive prompt tries to handle everything and drops details. Split prompts let each step focus on one thing and get it right.
5

Give models time to think

Chain-of-thought prompting is one of the most powerful techniques available. Ask the model to work through its reasoning before giving a final answer. This is especially effective for math, logic, code analysis, and multi-step problems. You can use 'inner monologue' to hide the reasoning from end users, or use a sequence of queries where the model's thinking is kept separate from the final output.

💡Always have the model reason BEFORE answering. If you ask for the answer first, the reasoning becomes a justification rather than genuine analysis.
Math tutoring
First, work out your own solution to the problem. Then compare your solution to the student's solution and evaluate if it's correct. Do not decide if the student is correct until you have solved the problem yourself.

Problem: I need to pay $100 in total. I've paid $40 and $30. How much do I still owe?
Student answer: $20
Without thinking first, the model often agrees with the student's wrong answer ($20 instead of $30). Solving it independently first catches the error.
6

Use external tools

Don't force the model to do everything. Compensate for weaknesses by feeding outputs of other tools into the model. Use text retrieval (RAG) to inject relevant documents dynamically. Use code execution for accurate math and data processing. Give the model access to APIs through function calling. Embeddings-based search can efficiently find relevant knowledge at runtime.

💡If your task requires precise calculations, current data, or domain-specific lookups, always use tools rather than relying on the model's training data.
7

Test changes systematically

If a prompt modification improves one example, that doesn't mean it's better overall. It might actually hurt other cases. Define a comprehensive test suite ('eval') that covers the full range of expected inputs. Evaluate outputs against gold-standard answers, either automatically or with a separate model evaluation step. Without systematic testing, you're flying blind.

💡Start small: even 20-30 diverse test cases will catch most regressions. Use a model to grade outputs when human review is too expensive.

Key topics covered

Clear instructions
Reference text
Task splitting
Chain of thought
External tools
Systematic testing
Personas
Output formatting
Read the full guide
View the complete OpenAI documentation
Official docs →

More guides