Why it matters
The same model can be excellent or useless on the same task depending on the prompt. That gap is not mysticism. It comes from four ordinary engineering variables: whether the task is defined precisely, whether the model has the information it needs, whether the output format is specified, and whether anyone measured the result.
Prompt engineering matters most at the boundary between a demo and a product. A demo survives on one good example. A product receives malformed inputs, ambiguous requests, adversarial text and edge cases, and must behave predictably on all of them. That requires treating the prompt as a versioned artefact with tests, not as a string someone tuned until the screenshot looked right.
Mental model
A written brief for a capable contractor who cannot ask follow-up questions. The contractor knows the domain in general, has read widely, and will fill any gap in the brief with a plausible assumption. If the brief does not say who the audience is, what "done" means, or what to do when the input is incomplete, the contractor will invent an answer.
The analogy breaks in one important way: the contractor has judgement and will ask when something is impossible. The model does not reliably know what it does not know, and it will produce a confident answer from insufficient information. Prompts therefore need explicit abstain instructions and verification, not just clearer wording.
How it works
- 1State the task and the success criterion in one sentence a new colleague would understand.
- 2Supply the context the model cannot infer: definitions, policy, audience, domain rules.
- 3Put variable content in clearly delimited sections so the model can tell instructions from data.
- 4Specify the output contract: fields, format, length, and what to do when the answer is unknown.
- 5Add one or two examples only where the format or the decision boundary is hard to describe.
- 6Run the prompt against a labelled set, including adversarial and empty inputs.
- 7Change one thing at a time, record the version, and keep the change only if it improves the set.
Prompt budget · illustrative tokens
1,420 input+ 400 reserve= 1,820 of 2,000
180 free
Step 1Four jobs
Role, evidence rule, abstention rule and contract take 510 tokens of the 1,420-token prompt. Each is testable on its own; 'be accurate' is not.
Output reserve
400The four jobs cost 510 tokens; the document and question cost 820. That split is the specification.
Pick a section to read its token count, its role and its state.
Figure. A production prompt does four jobs at once — assign a role, restrict the evidence, define abstention, specify the shape — and each is paid for in the same window as the document. The terse prompt leaves 690 tokens free and makes every dropped job a decision the model takes for you.
What to notice. Counts are authored for a 2,000-token window with a 400-token answer reserve; no prompt was rendered and no tokenizer was run. The example is the cancellation-extraction prompt from this page. Model chat markers, retries and the provider's billing are omitted — the figure shows what the specification costs, not what an answer costs.
Text version
A 2,000-token window with a 400-token answer reserve, so 1,600 tokens are available. The default first step is the full prompt: role and policy 120, task statement 90, evidence rule 150, abstention rule 60, output contract 180, document 700 and question 120, for 1,420 input tokens and 180 free. The second step drops the role, the evidence rule, the abstention rule and the contract, leaving the task, the document and the question at 910 tokens with 690 free. The third step adds a 400-token worked example and runs 220 over the window, with the cells crossing the cap rule into the reserve. The fourth step keeps the example and cuts the document from 700 to 480 tokens, filling the window exactly with the reserve intact. Selecting a section shows its count and its job.
The first two steps do most of the work. Ambiguity is the dominant failure: "summarise this" without a length, audience or purpose produces a different summary every time and no way to call one wrong. "Extract the cancellation date; if the document has no cancellation clause, return null" is a specification, and it can be tested.
Delimiting variable content is both a quality and a security measure. A retrieved document that contains the sentence "ignore previous instructions" is data, but if it is pasted into the instruction section, the model has no structural reason to treat it as data. Section headings, XML-like tags, or a JSON envelope all help; none of them is a guarantee, which is why instruction hierarchy and untrusted input are separate topics.
Output contracts belong in the prompt even when the provider enforces a schema. Telling the model what each field means reduces the chance of a syntactically valid but semantically wrong object. The same applies to abstention: if the prompt does not define what "I don't know" looks like, the model will guess.
Evaluation is what distinguishes engineering from folklore. Build a small set of inputs with expected properties, include the cases that already failed, and run it on every change. A prompt that improves the average while breaking the refund-policy question is a regression, not an improvement.
Quick facts
- Primary input
- Task specification
- Secondary input
- Context and examples
- Output
- A contract, not a wish
- Evidence
- A labelled eval set
- Unit of release
- Versioned prompt
A prompt with an actual contract
SYSTEM = """You extract cancellation terms from contracts.
Rules:
- Use only the provided document. Do not use outside knowledge.
- If no cancellation clause exists, set found=false and reason="not_present".
- Quote the supporting sentence verbatim in evidence.
"""
USER_TEMPLATE = """<document>
{document}
</document>
Return JSON with fields:
found: boolean
notice_days: integer or null
evidence: string or null
reason: string
"""
def build_prompt(document: str) -> list[dict]:
return [
{"role": "system", "content": SYSTEM},
{"role": "user", "content": USER_TEMPLATE.format(document=document)},
]The prompt does four jobs at once: it assigns a role, restricts the evidence, defines abstention, and specifies the shape of the answer. Each of those is testable. "Be accurate" is not.
Trade-offs
| Approach | Good for | Cost | Fails when |
|---|---|---|---|
| Short zero-shot prompt | Simple, well-known tasks | Low token cost, high variance | The task has domain rules or an unusual format |
| Detailed instruction prompt | Most production tasks | More tokens, slower iteration | Rules conflict or the prompt grows past review |
| Few-shot examples | Format-sensitive or boundary-heavy tasks | Tokens, selection bias | Examples are unrepresentative or leak the answer |
| Prompt chaining | Multi-step tasks with checkpoints | More calls, more latency | A single call would be reliable |
| Fine-tuning | Stable task, high volume, strict format | Data and training pipeline | Requirements change frequently |
Good for
Simple, well-known tasks
Cost
Low token cost, high variance
Fails when
The task has domain rules or an unusual format
- The task has domain rules or an unusual format
- Rules conflict or the prompt grows past review
- Examples are unrepresentative or leak the answer
- A single call would be reliable
- Requirements change frequently
Figure. Each choice with what it buys, what it costs, and the case where it loses.
What to notice. The fourth column is the decision: if the losing case describes your situation, the choice is wrong.
Text version
Four trade-offs: Short zero-shot prompt is good for Simple, well-known tasks, costs Low token cost, high variance, and fails when The task has domain rules or an unusual format. Detailed instruction prompt is good for Most production tasks, costs More tokens, slower iteration, and fails when Rules conflict or the prompt grows past review. Few-shot examples is good for Format-sensitive or boundary-heavy tasks, costs Tokens, selection bias, and fails when Examples are unrepresentative or leak the answer. Prompt chaining is good for Multi-step tasks with checkpoints, costs More calls, more latency, and fails when A single call would be reliable. Fine-tuning is good for Stable task, high volume, strict format, costs Data and training pipeline, and fails when Requirements change frequently
Failure modes
Overfitting to one example. The prompt is tuned until a specific input works and degrades everything else. Debug by running the full set, not the failing case alone, and by adding a held-out slice you do not inspect while iterating.
Conflicting instructions. The system prompt says "be concise", the task says "explain every step", and the model splits the difference unpredictably. Debug by listing the active constraints and removing or prioritising them explicitly.
Format drift on long inputs. The model follows the output contract for short documents and adds prose for long ones. Debug by measuring contract compliance by input-length bucket; the fix is usually a reminder near the generation point or provider-enforced structure.
No evaluation, so no signal. Every change is judged by the last output someone happened to read. Debug by writing down the acceptance criteria before the next edit and turning the known failures into test cases.
Symptom
The prompt is tuned until a specific input works and degrades everything else.
Debug step
Running the full set, not the failing case alone, and by adding a held-out slice you do not inspect while iterating.
Figure. Each failure with its symptom and the check that would confirm it.
What to notice. A failure without a debug step is a rumour. Pick the symptom you are seeing; the check is the next action.
Text version
Failure modes: Overfitting to one example: The prompt is tuned until a specific input works and degrades everything else. Debug by running the full set, not the failing case alone, and by adding a held-out slice you do not inspect while iterating. | Conflicting instructions: The system prompt says "be concise", the task says "explain every step", and the model splits the difference unpredictably. Debug by listing the active constraints and removing or prioritising them explicitly. | Format drift on long inputs: The model follows the output contract for short documents and adds prose for long ones. Debug by measuring contract compliance by input-length bucket; the fix is usually a reminder near the generation point or provider-enforced structure. | No evaluation, so no signal: Every change is judged by the last output someone happened to read. Debug by writing down the acceptance criteria before the next edit and turning the known failures into test cases.
In production
Keep prompts in a registry or repository, version them, and record which version produced each response. Run the eval set on every change and on every model upgrade. Track token cost and latency per prompt version, because a prompt that improves quality by adding context also changes unit economics. Cache the stable prefix where the provider supports it. Give product and support a way to report bad outputs into the eval set; that feedback loop is worth more than any single prompt trick.
Common misconceptions
People think: Prompt engineering is obsolete now that models are better.
Actually: Better models reduce the need for phrasing tricks. They do not remove the need to specify the task, supply context, define abstention and measure behaviour.
People think: Longer prompts are more thorough.
Actually: Length helps only when it adds information or constraints the model would otherwise guess. Redundant instructions compete for attention and tokens.
People think: A prompt that works in the playground will work in the product.
Actually: Production inputs are longer, messier and sometimes adversarial. Only an evaluation set with realistic and edge-case inputs predicts production behaviour.
Interview angle
Interviewers rarely ask "what is a good prompt". They ask you to diagnose a bad output or improve a feature, and listen for whether you separate specification, context and evaluation. A strong answer rewrites the task as a testable contract, names the failure classes, and proposes a measurement. A weak answer reaches for a phrasing trick. Practise with the prompting question bank.
Sources
- OpenAI, Prompt engineering guide — message roles, specificity, and structured instruction patterns.
- Anthropic, Prompt engineering overview — clarity, examples, and role prompting.
- Google, Prompt design strategies — task framing and output specification.
- Schulhoff et al., The Prompt Report: A Systematic Survey of Prompting Techniques — a taxonomy of techniques and their evidence.
Related
- Prompt anatomy — the parts of a prompt.
- Few-shot — examples as specification.
- Context engineering — the wider discipline.
- Prompt testing — turning prompts into evaluated artefacts.
- Prompt versioning — shipping changes safely.