Few-shot examples
The instructions are clear, Claude can repeat them back, and the output still differs from run to run, mostly on the borderline cases and the odd layouts. The tempting answer is more instructions. The exam's answer is to show Claude 2 to 4 worked examples of the tricky cases, with the reasoning and the exact output format.
D4 Prompt Engineering & Structured OutputExam guide 4.2About 15 minutes
At a glance
Start here: folding shirts for the shop window
A clothes shop wants every shirt on the display table folded the same way.
A few-shot example is a worked case placed in the prompt: an input, the output you want, and a line on why. “Few” means 2 to 4, chosen targeted: they cover the cases that go wrong, not the ones that already work. They show three things at once: the exact format (for a review: location, issue, severity, fix), how to decide the ambiguous cases, and how to read varied document structures. Because they show reasoning, Claude can carry it over to cases no example covers.
- Yes: add 2 to 4 targeted examples that cover the ambiguous cases, show the reasoning for the chosen action, and show the exact output format. For documents, pick examples with different layouts.
- The rule for what to flag is itself vague (“flag anything questionable”): that is a different trap. State explicit criteria first (see Explicit criteria).
- The JSON syntax breaks: use tool use with a JSON schema. The value isn't on the page: make the field nullable (see Extraction honesty).
Words in the question that tell you which side you're on
Points to few-shot examples
- “inconsistent format”, “different every run”
- “borderline cases”, “where two tests seem to apply”
- “varied layouts”, “carriers' own schedules”
- “instructions alone”, “Claude repeats the rules correctly”
Words that point elsewhere
- a vague rule for what to flag: explicit criteria
- a value missing from the document: a nullable field
- JSON syntax breaks: tool use with a schema
- “add more rules”, “twenty examples”: the trap options
Try it: run it twice
Pick a job, then a technique. The simulator runs the same six inputs twice and puts the two runs side by side, so you can see whether they match, whether the format holds, how the borderline cases go, and whether anything was invented. Each job has easy inputs, borderline ones, one new pattern no example shows, and one with an unusual structure.
The behaviours, token counts and call counts are illustrative, chosen to show the shape. They are not measurements, and every run is the same. The exam guide's points are that few-shot is the most effective technique for consistent, actionable output when instructions alone are inconsistent, and that 2 to 4 targeted examples should show reasoning and the output format and cover varied document structures.
Things to try: Pull-request review + Instructions only, and read rows 3 to 6. Then Longer, more detailed instructions: one row fixed, the rest still swing. Then 3 targeted examples, with reasoning, and read row 5, the annotation no example shows. Then 3 examples, easy cases only. Last, switch to Certificate extraction and compare JSON schema through tool use with the targeted examples.
The four traps
| Trap | What the wrong option looks like | Why it loses |
|---|---|---|
| More instructions only usually works | Expand the rules for each case; rewrite the prose as a checklist or a decision table | Instructions alone are what's already inconsistent. Each rule fixes the case it names and leaves the next borderline case to chance. |
| Too many examples overbuilt | Twenty examples covering every case seen so far | It works, but it costs tokens on every call and needs upkeep. The pattern is 2 to 4 targeted examples that let Claude generalise. |
| Fix it afterwards delays the problem | Validate the output in code and retry when the format is wrong | It catches format drift after the fact, at extra calls. It can't see a borderline case decided the wrong way. Examples prevent the drift. |
| Schema for judgement different problem | Use a JSON schema through tool use to fix the format | A schema fixes syntax and structure. It doesn't teach how to handle the ambiguous cases, or what an actionable fix looks like. |
One more lookalike: examples that only cover the easy cases. They look like few-shot, but they teach Claude what it already does well. Pick examples from the cases that go wrong.
Practice: three exam-style questions
Answer first, then open “Think it through”.
Rule to remember
Exam guide 4.2: “Few-shot is the most effective technique for consistent, actionable output when instructions alone are inconsistent.” “Demonstrate ambiguous-case handling; enable generalization to novel patterns; reduce extraction hallucination.” “2-4 targeted examples showing reasoning for the chosen action; demonstrate desired output format (location, issue, severity, fix); handle varied doc structures.”