aiwithgrant
about me
aiwithgrantGuidesOpenAI
OpenAI
OpenAI
Help Center
Beginner

Best Practices (Help Center)

OpenAI's concise, no-nonsense best practices. Quick wins for prompt formatting, temperature tuning, few-shot examples, and avoiding common mistakes.

Official OpenAI docs →
Content sourced from official OpenAI documentation
1

Put instructions first, context second

Always place your instruction at the start of the prompt before the context. Use ### or triple quotes to visually separate instruction from content. Be specific about the desired outcome, length, format, and style. This simple structural change consistently improves output quality because the model 'sees' what you want before processing the material.

💡Think of it as: tell the model what job it's doing, then hand it the materials.
Document summarization
Summarize the following article in 3 bullet points, each under 20 words, focusing on business impact.

###
{{LONG_ARTICLE}}
Instructions first means the model reads the article with your requirements already in mind, rather than processing it aimlessly then trying to recall what you wanted.
2

Be specific, kill the fluff

Replace every vague word with a precise one. 'Fairly short' becomes '3 to 5 sentences.' 'A few examples' becomes 'exactly 3 examples.' 'Good quality' becomes 'professional tone, no jargon, aimed at non-technical executives.' Every vague word is a decision you're forcing the model to guess. Remove unnecessary words and be direct.

💡Read your prompt and circle every adjective. If it's subjective ('good', 'nice', 'appropriate'), replace it with something measurable.
Removing vague language
Write a 3-5 sentence product description. Use an energetic tone. Include one technical specification. Target audience: developers.
'Fairly short, pretty engaging, somewhat technical' means different things to everyone. Specific constraints get consistent results.
3

Say what to do, not what not to do

Negative instructions are surprisingly unreliable. 'Don't ask for interests' is less effective than 'Suggest available topics and ask the user to pick one.' Positive instructions give the model a clear path forward instead of a minefield to navigate. When you catch yourself writing 'don't', flip it to a 'do' statement.

💡This applies to safety guardrails too. Instead of 'Don't make up information', say 'Only use facts from the provided document. If unsure, say I don't know.'
Customer service bot
The agent will suggest 3 available product categories and ask the user to select one. Only recommend products the user has explicitly asked about. Use a professional, concise tone in every response.
The positive version gives clear actions for every scenario. The negative version leaves the model guessing what it should do instead.
4

Start zero-shot, then add examples

Try getting your result with no examples first. If the output isn't right, add 2-3 examples showing the exact input/output format you want (few-shot). If that still isn't working, consider fine-tuning. This progressive approach saves you tokens and time. Don't jump straight to complex prompts when a simple one might work.

💡Few-shot examples are most valuable for teaching format and style, not facts. Use them when you need consistent structure across outputs.
5

Temperature and top_p

Temperature controls randomness: 0 means deterministic and focused, 1 means creative and varied. For production use cases where consistency matters (classification, extraction, analysis), use 0 to 0.3. For creative tasks (writing, brainstorming, marketing copy), use 0.7 to 1.0. Top_p works similarly but controls randomness differently. Only change one at a time, never both.

💡When debugging inconsistent outputs, the first thing to try is lowering temperature to 0. If the output is still wrong, it's a prompt problem, not a randomness problem.
6

Code generation patterns

When generating code, use leading words to nudge the output. Starting your prompt with 'import' primes Python code generation. Be explicit about the language, framework, version, and coding style. Specify whether you want comments, error handling, type hints, or tests. For complex code tasks, describe the input/output contract before asking for the implementation.

💡Include a brief description of what the function should do, then provide the function signature. The model fills in the body more accurately when it sees the contract first.

Key topics covered

Prompt formatting
Temperature settings
Token management
API usage
Few-shot examples
Prompt iteration
Read the full guide
View the complete OpenAI documentation
Official docs →

More guides