Few-shot prompting
Apply few-shot prompting to improve output consistency and quality.
This subtopic (4.2) sits in Prompt Engineering & Structured Output (D4) on Anthropic's Claude Certified Architect — Foundations (CCA-F) exam. The bank holds 25 practice questions here — 8 easy, 12 medium, and 5 hard — with 5 free to try, answers and explanations included. 3 of the free questions are below; the rest are in the practice stream.
What the exam tests here
- few-shot enables generalization to novel patterns beyond pre-specified cases
- few-shot examples most effective for consistent formatted output
- few-shot examples demonstrate ambiguous-case handling
- few-shot reduces hallucination in extraction — handles varied document structures
Free practice questions: Few-shot prompting
Your CI/CD pipeline uses Claude to generate PR comments with structured feedback. Output consistency is poor across different reviewers' PRs. Which few-shot example strategy best improves formatted output consistency?
Show answer & explanation
Correct answer: A. Provide examples pairing PR diff snippets with correctly formatted feedback comments
Few-shot examples are most effective for consistent formatted output when each example demonstrates the exact input-output pattern Claude must replicate. 'Varied formats' teaches inconsistency rather than a standard. 'Single detailed example' fails to generalize across PR types. 'Edge cases only' leaves the common path without grounding.
Your CI/CD pipeline uses Claude Code to post PR comments with code review feedback. Review output is inconsistent in format across runs. Which few-shot strategy most effectively enforces a uniform comment structure?
Show answer & explanation
Correct answer: B. Include two to three example PR comments in the prompt showing the exact heading and bullet format required.
Few-shot examples showing the target format repeatedly are the most reliable way to enforce consistent structured output. 'One detailed example...' gives insufficient variation for the model to generalize the pattern. 'Instruct Claude to follow a numbered format...' relies on instruction compliance without demonstrating the target. '--json-schema' enforces structure at the schema level, not via few-shot prompting.
Your extraction system processes invoices with varying layouts. After adding few-shot examples to the prompt, validation against the JSON schema shows fewer missing fields. What does this improvement demonstrate?
Show answer & explanation
Correct answer: D. Few-shot examples help the model infer structure from varied document layouts.
Few-shot examples teach the model to handle varied layouts by demonstrating expected extraction patterns, reducing hallucination and missed fields. 'JSON schema validation automatically corrects...' is wrong — schemas validate but do not fill gaps. 'Increasing temperature...' degrades consistency. 'Few-shot examples reduce token usage...' conflates examples with compression.
2 more free questions on this subtopic in the practice stream, plus 20 in the full bank. Keep practicing →