How to write an AI prompt that works
Published
To write a good AI prompt, state the task specifically, supply the background the model cannot infer, define the output format, list explicit constraints, show one example, and say how the result will be judged. Then order it so context comes before instructions and the task is restated last.
What is the basic structure of a good prompt?
A working prompt has six parts. You do not need all six every time, but you should know which one you are leaving out and why.
- Role — the expertise the model should apply. Useful when it implies a standard: "a line editor who cuts redundancy", not "a brilliant writer".
- Context — the background the model has no way of knowing. Source material, your situation, what has already been tried.
- Task — what to produce, stated as precisely as you can manage.
- Constraints — the rules the output must follow, including what to avoid.
- Output format — the shape: markdown, JSON, a table, a word count, a tone.
- Success criteria — how you will judge it, so the model can check its own work.
Examples sit alongside these rather than inside them, and they are worth more than any of the six individually. If you can show one correct answer, do that before you write another sentence of description.
Does the order of a prompt matter?
Yes, and more than most people expect. Two ordering rules carry most of the benefit, and both work by exploiting how models read a context window rather than by changing what the prompt says.
Put long reference material before the instructions. When a model reads a 2,000-word document and then reads "summarise the above in five bullets", it processes the material already knowing nothing about what is wanted, then receives a clear instruction with the material fresh. Reversing that order — instruction first, then the wall of text — buries the instruction and dilutes it.
Restate the task at the end. Models weight the end of the context heavily, an effect known as recency bias. In a long prompt, an instruction given at the top can be quietly overridden by a casual remark at the bottom. Ending with a single line that restates what to do costs almost nothing and reliably helps.
These two rules are why the same six pieces of information, reordered, produce measurably different output from the same model. The words did not change; what the model attended to did.
How specific does a prompt need to be?
Specific enough that a competent stranger could do the task without asking you a question. That is the practical bar, and it is a useful one because it is checkable.
The most common failure is not vagueness about the topic — people are usually clear about that — but vagueness about the qualities the output should have. Words like "good", "engaging", "professional", "comprehensive" and "detailed" feel like requirements and constrain nothing. A model cannot verify whether it has been engaging. It can verify whether it opened with a concrete detail, stayed under 900 words, and named only UK-available products.
| Instead of | Write |
|---|---|
| Make it engaging | Open with a specific detail or a claim a reader could disagree with |
| Keep it professional | Plain business English. No exclamation marks, no hedging phrases |
| Be comprehensive | Cover these five things, and say what you left out |
| Make it short | Under 200 words |
| High quality code | Runs as written, every branch handled, no placeholder comments |
What should you do when you do not know what you want?
Often the honest answer is that the brief is unclear because the thinking is unfinished. Writing a detailed prompt is not possible yet, and pretending otherwise produces a confident answer to the wrong question.
The fix is to add a stop condition — an explicit instruction telling the model to ask before assuming:
If anything above is unclear, or you are missing information you
need, ask up to three specific clarifying questions before producing
any output. Do not invent facts, names, numbers or sources to fill a
gap — if you do not know something, say so.This single addition changes the failure mode from "confidently wrong output you have to detect" to "a question you can answer". It is the most useful thing you can add to a thin prompt, and it is why this site's compiler adds it automatically when a brief scores as underspecified.
How do you write a prompt you can reuse?
A prompt you will run more than twice should be a template: the structure fixed and tested once, with placeholders for the parts that change.
<role>
You are a support engineer writing replies that resolve the issue
in one message.
</role>
<context>
Product: {{product}}
Customer tier: {{tier}}
Previous contact: {{history}}
</context>
<task>
Reply to the message below.
</task>
<constraints>
- Address every question asked, in the order asked
- Never promise a delivery date that is not in the context
- If you cannot resolve it, say what happens next and when
</constraints>Name variables for what they mean rather than where they sit, and test that an unreplaced {{placeholder}} never reaches the model — it is a common and trivially detectable bug. More in the prompt templates guide.
What does a complete prompt look like?
Putting all of it together, for a task with real constraints:
<role>
You are a technical writer who explains infrastructure to developers
who have never run production systems.
</role>
<context>
Our team of four is moving from a single server to containers. Nobody
has used Kubernetes. We deploy twice a week and have had two outages
this quarter, both from manual deploy mistakes.
</context>
<task>
Write a 1,200-word explanation of what container orchestration solves
and whether a team our size needs it.
</task>
<constraints>
- Define every term the first time it appears
- Give one concrete example before each general rule
- Say plainly if the honest answer is that we do not need it
- No vendor recommendations
</constraints>
<output_format>
Markdown with descriptive headings. Paragraphs of three sentences or
fewer. Plain British English.
</output_format>
<success_criteria>
- A developer who has never deployed to production could explain the
trade-off back in their own words
- Every claim is either common knowledge or stated as uncertain
</success_criteria>
Now write the explanation.Note what is absent: no flattery, no urgency, no "this is very important to my career". Every line either supplies information the model lacked or bounds what it may produce.
Common questions
- What is the best way to start an AI prompt?
- With the role or the context, not the task. Stating who the model should be and what situation it is working in gives everything that follows something to attach to. Save the task itself for after the background, and restate it at the very end.
- Should I use XML tags or markdown headings in my prompt?
- XML tags for Claude, which was trained on XML-delimited structure and follows it most reliably. Markdown headings for ChatGPT and Grok. Either works for most tasks; what matters more is that the sections are separated at all, so the model can tell your instructions from your source material.
- How many examples should I include in a prompt?
- Two to five. One example is a large improvement over none. Beyond about five, returns diminish while context is consumed. The examples must be consistent with each other, since inconsistent formatting teaches the model that formatting is optional.
- Why does my prompt work sometimes and not others?
- Usually because a requirement you consider obvious was never written down, so the model satisfies it by chance rather than by instruction. Look for the assumption you are making, write it in as an explicit constraint, and the variance usually disappears.
- Should I put everything in one prompt or split it up?
- Split it when the task has genuinely separate stages, each of which could be checked on its own. A single prompt doing research, analysis and writing produces work that is hard to debug, because you cannot tell which stage went wrong. See [prompt chaining](/glossary/prompt-chaining/).
- Does telling the model the task is important help?
- No. Urgency framing, emotional appeals and offers of payment do not reliably change output quality. They occupy tokens and attention that a concrete constraint would use better.