Prompt Engineering
Official scope (Exam Guide v1.0): clarity, few-shot, system vs user, output constraints, instruction placement across components, iterative refinement, input sanitisation.
Core techniques (verified: Anthropic prompting best practices)
- Be clear and direct. State the task, audience, output format and constraints; number steps when order matters; ask explicitly for "above and beyond" if you want it.
- Golden rule: a colleague with no context should understand the prompt.
- Explain the why. "This is read aloud, so avoid ellipses" generalises better than "never use ellipses".
- Examples (few-shot): 3 to 5 relevant, diverse examples, wrapped in
<example>tags so they are not mistaken for instructions. - XML tags separate instructions, context, examples and inputs; nest for hierarchy (documents with sources).
- Long documents first, question last; the docs report up to about 30% better responses on complex multi-document inputs. Ask for relevant quotes first, then the answer.
- Let it think for hard problems: adaptive thinking with suitable effort, or ask for reasoning before a clearly marked final answer.
- Chain complex tasks into separate calls when you need to inspect intermediate output (draft → review against criteria → refine).
- Prefill is gone on newer models (400 on Claude 4.6+); use structured outputs, system instructions or
output_config.format.
System vs user
system (top-level field) for role, standing rules and format; the user turn for the task and its inputs. A role in the system prompt focuses tone and behaviour.
Instruction placement across components (design guidance)
| Put this | Here |
|---|---|
| Standing rules, role, format | System prompt |
| The task and its inputs | User turn |
| When and how to use a tool | Tool description |
| Project facts (Claude Code) | CLAUDE.md |
| Format by demonstration | Examples |
| Untrusted content (web pages, emails, retrieved docs) | Tool results only, labelled with source; never system prompt or plain instruction text |
Your own instructions do not belong inside tool results: content there is treated as untrusted data.
Input sanitisation (design guidance, verified defence ideas)
Never concatenate raw user text into instructions. Wrap or JSON-encode untrusted strings so they cannot close a tag or quote and escape into instructions; strip or escape markup; screen inputs (a small fast model returning a structured verdict) for injection patterns; cap length.
Iterative refinement (verified principle)
Define success criteria and an eval set first; change one thing; rerun the same cases; compare scores. Without an eval you are guessing.
Exam traps
- Question before a 40-page document.
- Examples that are all alike, so the model copies one example's phrasing.
- Prefill on a new model to force JSON.
- Untrusted text pasted into the system prompt.
- "It looks better" without an eval.
References
- Prompting best practices — checked Oct 16, 2026
- Prompt engineering overview — checked Oct 16, 2026
- Mitigate jailbreaks and prompt injections — checked Oct 16, 2026
- Errors (prefill) — checked Oct 16, 2026
- Define success criteria and build evaluations — checked Oct 16, 2026
Check your understanding
"Make it good." Two improvements?Show answerHide answer
Answer
Exact output format and constraints; the reason and an example.Where does retrieved web text go?Show answerHide answer
Answer
In a tool result, labelled; never in the system prompt.Model copies one example's wording. Fix?Show answerHide answer
Answer
More diverse examples covering edge cases.Is prompt B better than A?Show answerHide answer
Answer
Run both on the same eval set and compare scores.