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 (CCAR-F) exam. The bank holds 24 practice questions here — 8 easy, 11 medium, and 5 hard — with 6 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 CI/CD pipeline uses --output-format json to post PR comments. Comments for security vulnerabilities are formatted differently from performance issues. Which few-shot strategy best aligns both types to the same schema?
Show answer & explanation
Correct answer: C. Include one example of a security-vulnerability PR comment and one performance-issue comment, both formatted to the target schema
Providing examples of both issue types in the target schema format shows Claude how the schema applies across categories, directly addressing format divergence. Showing only security examples leaves performance format unanchored. Schema description in the system prompt is weaker than concrete examples. Post-processing normalizes output after the fact rather than fixing the generation.
3 more free questions on this subtopic in the practice stream, plus 18 in the full bank. Keep practicing →