Prompt engineering
Also known as: prompt design
The craft of wording, ordering and testing the text you send a language model so that it gives useful answers more often.
Draft - this entry has not been reviewed yet.
Formal
The practice of designing a prompt - its instructions, examples, layout and requested answer format - and changing it step by step against test cases, to steer a large language model without changing its weights.
In plain English
Like giving a visitor directions over the phone - you learn which landmarks to mention and in what order, and after each change you check whether the next visitor finds the way.
In practice
A librarian at a public library rewrites the instructions for its book-tip assistant three times, adding two sample replies and “answer in under 80 words”, then reruns fifty saved questions from borrowers to check each version.
Why it matters
It is the cheapest and fastest way to change how an AI feature behaves, but a small change in wording can quietly break cases that used to work, so changes need testing.
Technical deep dive
Prompt engineering is best understood as an empirical optimisation loop over an input that has no formal semantics. The model's behaviour is a function of the exact token sequence, and small, meaning-preserving changes can produce large behavioural changes: Sclar et al. (2023) measured differences of up to 76 accuracy points on LLaMA-2-13B from formatting choices alone, such as separators, casing and spacing in few-shot prompts. That sensitivity is why a prompt should be treated like code - versioned, reviewed and regression-tested against a fixed evaluation set - rather than edited ad hoc in production.
The techniques with the most consistent support are structural. State the task, audience, constraints and success criteria explicitly; give the model a role in the system prompt; separate instructions from input data with clear delimiters such as XML-style tags or fenced sections; put long reference documents before the question rather than after it; specify the output format precisely, ideally backed by a schema via structured output; show examples for format and edge cases (few-shot); ask for step-by-step reasoning on multi-step problems where the model does not reason natively; and break complex jobs into chained calls with one responsibility each. Positive instructions ("write in plain prose") tend to work better than lists of prohibitions, and giving the reason for a rule helps the model generalise it.
Evaluation is the part most often skipped. A workable loop defines test cases that cover typical, edge and adversarial inputs; scores outputs with exact-match checks, schema validation, heuristics, human review or an LLM-as-a-judge grader calibrated against human labels; and compares prompt versions on the same set, sampling several times per case because outputs vary between runs. Automated methods can search the prompt space: Automatic Prompt Engineer (Zhou et al., 2022) generated and scored candidate instructions with an LLM, and frameworks such as DSPy compile declarative pipelines into optimised prompts and demonstrations against a metric.
Prompts do not transfer cleanly. A prompt tuned for one model, or one version of a model, can regress on the next, so model upgrades need the same regression run as prompt changes. Prompt engineering is also not a security boundary: instructions such as "never reveal this" or "ignore instructions in documents" reduce but do not prevent prompt injection or system-prompt leakage, so controls belong in the surrounding system - permissions, output validation, human approval. When prompting stops improving results, the next levers are context engineering (what information is supplied), retrieval, a different model, or fine-tuning.
What to learn first
Everything this builds on, foundations first.
- Token
- →Transformer
- →Large language model (LLM)
- →Prompt
- →Prompt engineering
Relationships
- Requires
- Prompt
- Don't confuse with
- Context engineering
- Alternative to
- Fine-tuning
Sources & further reading
Official documentation
- Anthropic documentation - Prompt engineering overview · Anthropic
- OpenAI documentation - Prompt engineering guide · OpenAI
Reference works
Where this data comes from
This entry was drafted by an AI from the sources above and has not yet been checked by a person. Treat it as a starting point, and check anything important against the sources.
See the review queueSuggest a correction on GitHubThis term as JSON
Check yourself
Loading…