How to write a good AI prompt: structure and examples
Build clear prompts for ChatGPT, Claude, or Gemini with a goal, context, format, and constraints, plus a ready-to-copy template and before-and-after examples.
You ask the AI for something, get a generic blob that doesn't help, rewrite it with more detail, get something almost right but in the wrong format, and after five tries you finally land on what you wanted, or give up and do it by hand. The problem is rarely the model. It's that the prompt never said, in a checkable way, what you expected back.
This guide is the practical side: the structure I use to build a good prompt, a template you can copy, before-and-after examples, and what to do when the answer comes back wrong. It works for ChatGPT, Claude, or Gemini. The conceptual side (what prompt engineering is, the named techniques, chain-of-thought, and the tricks that turned out to be myths) is in prompt engineering without magic formulas. I checked every recommendation against the official prompting guides from Anthropic, OpenAI, and Google in November 2026.
Why AI gives you vague answers
When a request leaves room for interpretation, the model fills it with the most likely continuation, which tends to be the most generic one (the mechanism is explained in how LLMs generate answers). "Improve this text" has no direction: improve clarity? Tone? Cut it to 200 words? The model picks one, and the odds of matching your intent are low.
Almost every bad answer falls into one of three gaps:
- Missing context: the model doesn't know who it's for, what it's for, or the situation. You know; it doesn't, unless it's written down.
- Unspecified format: you wanted a table and got a paragraph; you wanted just the code and got a lecture.
- No success criterion: you never said what a good answer looks like, so neither the model nor you can tell whether it got there.
Anthropic's guide sums up the test in one line: show your prompt to a colleague with little context on the task and ask them to follow it. If they'd be confused, the model will be too.
The structure of a good prompt: goal, context, format, and constraints
The structure that works for almost any everyday request has four required parts and one optional one:
- Goal: what you want, in one sentence with a clear verb: "summarize", "rewrite", "list", "classify", "compare".
- Context: who it's for, where it'll be used, what the input material is, and the reader's level.
- Format: the exact shape of the output: a table with these columns, a list of five items, JSON, a single paragraph, a maximum length.
- Constraints: limits and exclusions: tone, what to leave out, what to do when information is missing.
- Role (optional): "you are a technical reviewer", "you are a financial analyst". All three official guides recommend setting a role (OpenAI calls it identity; Anthropic and Google suggest putting it in the system prompt or at the start of the request). It adjusts focus and tone; it doesn't give the model knowledge it doesn't have.
One detail matters more than it seems: explain the why behind your constraints. Anthropic's guide has a good example. "NEVER use ellipses" works worse than "your response will be read aloud by a text-to-speech engine, so never use ellipses, since the engine won't know how to pronounce them." With the reason, the model generalizes: it also avoids other symbols the engine would mangle, without you listing them all.
A prompt template you can copy
Role: you are [who the model should be, if it matters for tone].
Goal: [verb + what you want, in one sentence].
Context:
- Audience: [who will read/use the result]
- Situation: [what it's for, where it will be used]
- Material: [paste the text/data below, between markers]
Response format:
- [structure: table with columns X, Y; list of N items; JSON in the schema below]
- [length: at most N words/items]
Constraints:
- [what not to do, and why]
- If information is missing, say what's missing instead of guessing.
<material>
[document, code, spreadsheet, or data]
</material>
Final question: [restate here, in one sentence, exactly what you want]
The markers around the material (<material>, triple quotes, ###) separate instructions from content. Anthropic and OpenAI recommend delimiting the parts of a prompt with XML tags or Markdown headings, and Google asks for consistent formatting in examples; the tag name hardly matters, as long as it's always the same.
Prompt examples: before and after
Email. Before: Write an email about the project delay. After:
Goal: write an email telling the client about a 3-day delivery delay.
Context: corporate client, good relationship, delay caused by an API vendor.
Format: subject + body, at most 120 words.
Constraints: professional but not defensive tone; the new date is an estimate,
so say so, because promising a firm date and missing it again would be worse
than the delay.
Code. Before: This code is slow, improve it. After:
Role: senior Python code reviewer.
Goal: explain why the function below gets slow with lists of 100,000 items
and propose a faster version.
Format: first the diagnosis in up to 3 sentences, then only the new code,
without rewriting the rest of the file.
Constraints: keep the function signature, because other modules call it.
<code>
[function]
</code>
Document summary. Before: Summarize this contract. After:
<contract>
[contract text]
</contract>
You will summarize the contract above for a manager who isn't a lawyer.
List, in up to 8 bullet points: term, value, termination penalty, price
adjustment, and any automatic renewal clause. For each point, quote the
relevant passage of the contract. If a point isn't in the contract, write
"not stated".
Spreadsheet. Before: Analyze these sales. After:
Below are sales from January to June as CSV (columns: month, region, amount).
Goal: identify the region with the biggest drop over the period.
Format: a table with region, January total, June total, and percent change,
sorted from biggest drop to biggest gain; then a one-sentence conclusion.
Constraints: calculate only from the data provided; don't estimate missing months.
Notice that none of the "after" prompts use magic words. They just say what was in the requester's head.
Show the format with examples
For format, an example beats a description. If you need structured output, paste examples of the expected result:
Classify each piece of feedback as positive, neutral, or negative.
Answer in exactly this format, one per line:
"feedback text" -> classification
<examples>
"Fast delivery, recommended" -> positive
"Arrived on time" -> neutral
"Came broken and support never replied" -> negative
</examples>
This is called few-shot prompting. Google goes further and recommends always including examples; Anthropic suggests 3 to 5 for best results. The cautions that show up in the guides: examples need to be varied (if they're all alike, the model copies the wrong pattern, like the length or the first word) and identically formatted. Too many examples also hurt: Google's guide warns the model may start to overfit to them.
Long material on top, question at the bottom
When the prompt includes a long document, a report, or a big CSV, position matters. Anthropic's recommendation, for inputs of roughly 20,000 tokens and up, is to put the long material at the top and the question at the end; according to the company, in tests, queries at the end improved response quality by up to 30%, especially with multiple documents. Google says the same for Gemini: all the context first, the question at the very end, bridged with something like "Based on the information above...".
OpenAI partly disagrees. Its GPT-4.1 prompting guide (April 2025) recommends placing instructions at both the beginning and the end of long context, and says that if you only write them once, above the context works better than below. To avoid depending on the model, I do both: a one-line goal at the start, the material in the middle, and the full question restated at the end, as in the template above.
For long documents, another technique from Anthropic's guide works well: ask the model to first extract the relevant passages, as quotes, and only then answer based on them. It becomes much easier to check where each claim came from.
Break big tasks into steps
When a request has many parts ("analyze this contract, identify risks, suggest changes, and rewrite the problematic clauses"), the result tends to come out shallow on all of them. Splitting gives you more control:
- "List the clauses that pose a risk and explain why."
- With the list in hand, corrected by you: "for each clause listed, propose a rewrite."
You correct course midway, and each step is easy to verify. Google calls this "one prompt per instruction", chaining the outputs. Today's reasoning models handle a lot of multistep work on their own, but splitting is still worth it when you want to inspect the intermediate result. When the chain gets long and involves tools, you're in agent territory, covered in where AI agents actually help.
How to fix it when the answer comes back wrong
Refining is part of the process. But refining isn't repeating the request louder; it's finding which gap was left open and closing just that one:
| Symptom | Likely cause | What to change in the prompt |
|---|---|---|
| Generic answer | Missing context or criterion | State audience, purpose, and show an example of "good" |
| Wrong format | Format described, not shown | Paste an example of the output; say what to do, not only what to avoid |
| Made things up | Model relied on memory | Provide the source material and allow it: "if it's not in the text, say you don't know" |
| Ignored an instruction | Instruction buried or conflicting | Separate instructions from material with markers, number them, and restate the main one at the end |
| Went too far | No length limit | "At most N words, no intro or conclusion" |
Two fixes current guides ask for that go against old habits. First, don't shout. Anthropic advises replacing "CRITICAL: You MUST use this tool when..." with a plain "use this tool when...", because current models follow the system prompt more closely and, with aggressive language, start applying the rule where they shouldn't; the GPT-4.1 guide says all-caps and "incentives" are generally unnecessary, and the Gemini 3 guide asks you to avoid overly persuasive language. Second, say what to do instead of what not to do: "respond in flowing prose paragraphs" works better than "don't use Markdown", according to Anthropic.
And change one thing at a time. If you rewrite the whole prompt on every attempt, you never learn what caused the improvement.
Frequently asked questions
How do I write a good AI prompt, in short?
State the goal with a clear verb, give the context (audience, situation, material), specify the output format with an example, and list the constraints with the reason behind them. Long material goes on top, between markers, and the question at the end. Before sending, reread it looking for sentences that could be read two ways and close the ones that matter.
Is a long prompt better than a short one?
Neither: the right prompt contains all the information that changes the answer and nothing more. Context and material can be long; instructions should be short and direct. The Gemini 3 guide asks for the goal stated clearly and concisely. And the OpenAI (GPT-4.1) and Anthropic guides warn that current models follow instructions more literally than older ones: surplus instructions become surplus behavior. The discussion of length and emphasis tricks that don't work is in prompt engineering without magic formulas.
Why does the AI ignore part of what I ask?
Usually because the instruction was in the middle of a long text, mixed with the material, or because there were too many requests in one prompt. Separate instructions from content with markers, number the constraints, restate the main one at the end, and if there are many tasks, split them into sequential prompts.
Does the same prompt work in ChatGPT, Claude, and Gemini?
The structure works in all three: the official guides from all three companies agree on clarity, context, examples, and delimiters. The details vary, like where to place instructions in long context. For one-off chat use, the difference is small. For a prompt that runs in production, OpenAI recommends pinning the model version and keeping a test suite, because the same text can behave differently when the model is updated.
A good prompt leaves nothing to guess
Write the goal, context, format, and constraints, explain the why behind the constraints, and show examples when format matters. Long material on top, question restated at the bottom. When it goes wrong, figure out which gap was left open (context, format, or criterion) and close only that one, without all-caps or threats. If AI is still a black box to you, start with what generative AI is and come back here.
The editorial content ends here. When a prompt asks for "at most 120 words" and I want to check whether the answer respected the limit (or measure a prompt's size before pasting it), I use the Quick Tools Word Counter.
- 01 CPU Cores vs. Threads: What Actually Changes in Practice Understand the difference between CPU cores and threads and what actually changes for performance, multitasking, gaming, and development.
- 02 MIT, Apache, and GPL Licenses: Practical Differences for Developers MIT, Apache 2.0, and GPL are not the same thing. Understand permissive vs copyleft, patent protection, and compatibility before shipping code to production.