Learn · Prompt engineering & structured output · CCAR-F task 4.2
Few-shot prompting for consistency
A few well-chosen examples fix format and judgement better than more instructions. Always include the hard, ambiguous case.
Key ideas
- Examples are the most reliable way to fix both format and judgement.
- Use a few targeted examples: the exam guide says 2-4, Anthropic's prompting docs say 3-5.
- Make them relevant and diverse, wrap them in <example> tags, and include the hard or ambiguous case.
- Show why one choice beat plausible alternatives, and show acceptable patterns that should not be flagged.
- For extraction, cover varied document structures and informal values.
Worked example: Teaching the null case
If Claude invents values when data is missing, add an example whose correct output is null with reason "unclear". One worked edge case usually beats a paragraph of rules about missing data.
Exam traps
- Adding many near-identical easy examples. Diversity and the edge case matter more than volume.
- Showing only the answer, not the reasoning that ruled out the alternatives.
- Piling on more instructions when a few targeted examples would fix the inconsistency.
Official docs
Practise CCAR-F questions · Next lesson: Structured output with schemas and tools