Last Step/Prompt Engineering and Structured Output20%
Domain 46 task statements20% of the exam

Prompt Engineering and Structured Output

How to make Claude produce consistent, schema-valid output on the first try through explicit criteria, few-shot patterns, constrained decoding, validation loops, and batch discipline.

Prompt engineering for production is not about clever phrasing but about removing ambiguity from every input that shapes Claude's next token. The system prompt, the few-shot examples, the JSON schema, and the validation loop each remove a different class of variance: vague criteria produce inconsistent classification, missing examples produce format drift, a missing schema produces malformed JSON, and a missing validator lets wrong values pass as correct structure. When all four are in place the model still makes mistakes, but those mistakes become detectable and correctable rather than silent and random.

This domain's six tasks map directly to the six places a production pipeline drifts. Task 4.1 makes the system prompt explicit by replacing subjective instructions with categorical criteria and the RACCE diagnostic. Task 4.2 adds few-shot examples with reasoning so the model matches a demonstrated pattern instead of interpreting an adjective. Task 4.3 moves from probabilistic JSON in text to constrained decoding through tool schemas and structured outputs. Task 4.4 closes the loop with semantic validation and retry with error feedback that distinguishes fixable from unfixable failures. Task 4.5 chooses batch versus synchronous for cost without breaking latency guarantees. Task 4.6 replaces single-pass self review with multi-pass independent review plus calibrated confidence routing.

Two principles cut across every task. First, structure removes variance more reliably than additional prose. An explicit category list beats a paragraph defining conservatism, a concrete input-output pair beats a page defining warmth, and a JSON schema with constrained decoding beats an instruction to respond only in JSON. Whenever the exam offers more instructions versus an example or a schema, the example or schema is the correct answer. Second, schema guarantees structure but never guarantees correctness. Line items can sum to the wrong total inside perfectly valid JSON, and a field can be populated with a plausible invention that passes type checks. Production therefore needs both structural enforcement and semantic validation, with retry that names the specific error rather than repeating the same prompt.

On this page
  1. 4.1 System Prompts Replace vague guidance with explicit categorical criteria, RACCE structure, and primacy-aware placement so every response is judged by the same testable boundary.
  2. 4.2 Few-Shot Prompting Show the pattern with 2 to 4 reasoning-annotated examples so Claude matches a demonstrated judgement instead of interpreting an adjective.
  3. 4.3 Structured Output Guarantee schema-valid JSON through tool schemas and constrained decoding, then design nullable enums and redundancy fields that handle real document variation.
  4. 4.4 Validation and Retry Loops Add semantic validation and retry with document plus failed output plus specific error so fixable mistakes self-correct and unfixable ones route to human review.
  5. 4.5 Batch Processing Use the Message Batches API for latency-tolerant work at 50 percent savings and keep blocking workflows synchronous, correlating every batch result through custom_id.
  6. 4.6 Multi-Pass Review Split large audits into per-file passes plus an integration pass from an independent instance, with calibrated confidence routing to focus human review where it matters.
The essentials
Everything below explains why each of these is true.
  1. System prompt persists across every turn and carries persona, constraints, output conventions, and quality criteria. It is re-sent with every request, which is why keeping it lean and stable matters for both attention and cost.
  2. RACCE is the diagnostic for system prompts: Role, Audience, Criteria, Constraints, Examples. When a prompt underperforms the fault maps to a missing or underspecified RACCE component.
  3. Explicit categorical criteria define what to flag and what to skip with concrete code patterns per category. Confidence thresholds are poorly calibrated and are a routing mechanism, not a substitute for criteria.
  4. Primacy and recency both receive strong attention. Put critical behavioural constraints at the very top of the system prompt, supporting detail in the middle, and examples last where recency helps.
  5. Negative constraints such as do not include a preamble or do not wrap output in markdown fences directly suppress a pattern. Lowering temperature reduces randomness but does not guarantee pattern absence.
  6. Few-shot examples with reasoning teach the decision principle and generalise to novel patterns. Use 2 to 4 targeted examples, mix classes in classification, keep formatting identical down to punctuation, and place examples close to the query.
  7. Structured outputs: tool use with a JSON schema guarantees schema-compliant output by eliminating JSON syntax errors. Prompt-based JSON is probabilistic and will produce malformed output. Schemas eliminate syntax errors but not semantic errors, which still need external validation.
  8. tool_choice modes: auto lets the model return text instead of a tool, any forces a tool call but lets the model choose which, forced tool selection with type tool and name guarantees exactly that tool. Strict mode on a tool requires additionalProperties false and applies constrained decoding to arguments.
  9. Optional and nullable fields prevent fabrication. Required fields pressure the model to invent values when source data is absent. Add unclear and other to enums, with a freeform detail string for other, to handle ambiguity and long tail categories.
  10. Retry with error feedback sends the original document, the failed extraction, and the specific validation error. It fixes format mismatches, structural errors, misplaced values, and arithmetic errors, but cannot fix genuinely absent information which routes to human review.
  11. Batch API gives 50 percent cost savings with results available when all requests finish or at 24 hours whichever comes first, most batches finishing inside an hour but with no per-item latency promise, and custom_id correlation. Use batch for latency-tolerant work and synchronous for blocking workflows. Work backwards from the deadline to schedule submissions.
  12. Independent review instances beat self review in the same session because the reviewing instance does not carry the generation reasoning. Large audits need per-file local passes plus a cross-file integration pass, with calibrated confidence thresholds for routing via labelled validation sets.
Task 4.118 min

System Prompts

Replace vague guidance with explicit categorical criteria, RACCE structure, and primacy-aware placement so every response is judged by the same testable boundary.

What you need to know

The system prompt is the single most influential input you control when deploying Claude because it persists unchanged across every turn of the conversation. It is the right place for anything that should shape every response rather than just the current one: persona, behavioural constraints, output conventions, and the criteria by which quality is judged. Anything time bound or query specific belongs in a user message, while any standard that must apply without an invocation step belongs in the system prompt.

The most common production failure is a vague instruction that sounds engineering grade but gives the model no actionable decision boundary. Phrases such as be conservative, only report high-confidence findings, use your best judgement, be ethical, and be careful cannot be verified from the output and mean different things in different contexts. The exam uses exactly this language as distractors because it feels responsible while being untestable. The correct replacement is explicit categorical criteria that name what to flag and what to skip with concrete patterns per category, for example flag comments only when claimed behaviour contradicts actual code behaviour and otherwise skip minor style preferences and local patterns.

RACCE is the framework that makes a system prompt diagnosable when output quality drops. Role activates domain knowledge and perspective, without it Claude defaults to generic helpful assistant behaviour. Audience calibrates vocabulary, tone, and assumed knowledge, without it tone mismatches the consumer. Criteria define how quality is evaluated and which tradeoffs are favoured, without them Claude decides whether correctness or brevity matters. Constraints are hard boundaries not to cross, without them Claude improvises scope. Examples demonstrate the target format and quality through demonstration rather than description. When a system prompt underperforms the fault almost always maps to one missing RACCE component.

System prompts exhibit a primacy effect where Claude attends more strongly to content at the very beginning and end of context than to content buried in the middle. A critical behavioural constraint placed in the middle of an 8000 token system prompt receives reliably weaker attention than the same constraint placed at the top. The fix is structural: put the most critical behavioural constraints first, supporting detail in the middle, and examples last where they also benefit from recency. A practical budget is to keep the system prompt under 10 percent of total token budget, otherwise it competes with the task for attention.

Confidence-based filtering is not a substitute for explicit criteria. Instructions such as only report high-confidence findings fail because LLM self-reported confidence is poorly calibrated, the model is often sure about wrong findings and hesitant about right ones. Confidence scoring earns its place as a routing mechanism for uncertain outputs to human review, which is covered in the multi-pass review task, but it never replaces explicit criteria that define what counts as a valid finding in the first place. The hierarchy is explicit criteria first, confidence routing second, and skipping the first step cannot be compensated by tuning the second.

RACCE as a diagnostic and the explicit criteria replacement

Vague guidance fails the verifiability test. A constraint such as never provide a specific diagnosis or always escalate when the user describes an emergency can be checked directly in the output, while be ethical cannot. Explicit categorical criteria pass the same test: report bugs and security vulnerabilities and flag comment mismatches only when claimed behaviour contradicts code, skip style preferences and local patterns, each paired with a concrete code snippet for the critical severity and a snippet for the minor severity so severity is recognised by pattern not by prose interpretation.

RACCE makes the gap explicit during debugging. Walk each component when a prompt underperforms and ask whether role, audience, criteria, constraints, or examples is underspecified. Underperforming documentation mismatch detection almost always maps to criteria, missing the definition of what counts as a mismatch, not to a model capability limit. Adding high confidence language after the fault is still criteria missing, so it still fails.

Primacy, negative constraints, and size discipline

When a prompt grows by appending detail, critical constraints drift toward the middle where primacy is weakest. The presentation that a long plausible prompt asks which instruction is reliably followed keys to the instruction at the top, not the middle, and the fix is to reorder rather than to add emphasis words. Supporting detail and long examples belong in the middle and at the end where recency still helps.

Negative constraints are more reliable than sampling adjustments for suppressing unwanted behaviour. Lowering temperature reduces randomness but does not guarantee the absence of a preamble, while a specific negative constraint such as do not include text outside the JSON object or do not wrap output in markdown fences directly suppresses the pattern. Keep negative constraints specific and verifiable, the same rule as positive constraints.

Caching reduces per-token price but not attention cost. A 10000 token system prompt still consumes 10000 tokens of attention budget per call, the cache only discounts the price, so size discipline still applies even when caching is enabled.

Mechanism and API surface

RACCE framework
Role, Audience, Criteria, Constraints, Examples. Each maps to a failure mode and the fix for an underperforming prompt almost always maps to one component.
Explicit categorical criteria with examples per severity
Define what to flag and what to skip per category with concrete code patterns, for example critical as a SQL injection snippet and minor as inconsistent variable naming, not prose descriptions.
Primacy and recency placement
Critical behavioural constraints at the very top, supporting detail in the middle, examples last. Content in the middle of a long prompt receives weaker attention than the same content at either end.
Negative constraints over temperature
Specific suppressions such as Output ONLY the JSON object, no preamble, no explanation, no markdown fences suppress a pattern directly. Temperature controls randomness, not pattern absence.
Size budget and update discipline
Keep system prompt under 10 percent of token budget, version in source control, shadow test a sample of real inputs on old versus new prompt, change one RACCE component at a time, and monitor satisfaction, tool call patterns, and refusal rate.
CI code review pipeline with a trust collapse and a three-part recovery
A production walkthrough with the reasoning chain made explicit.

A team operates a pull request review service whose system prompt starts as Review this code, be conservative, only report high-confidence findings. Performance degrades as categories are added, bugs, security, style, documentation mismatch, and performance. Some categories run at 98 percent accuracy and developers trust them, but the documentation mismatch category runs at a 40 percent false positive rate by flagging style preferences as documentation issues. Developers stop reading the entire review output, including the accurate security findings, because one unreliable category poisons trust in all of them.

The first attempted fix adds only report high-confidence documentation issues. It fails because confidence is poorly calibrated and does not address the missing criteria, the model has no definition of what counts as a documentation mismatch versus a style preference, so the same false positives continue at a different threshold. The trust collapse is driven by category precision, not by a missing cutoff.

The fix that works has three parts. The system prompt is rewritten with explicit criteria per category: flag comments only when claimed behaviour contradicts actual code behaviour, report bugs and security vulnerabilities, and skip minor style preferences and local patterns, each severity paired with a concrete code example rather than a description. The documentation mismatch category is temporarily disabled while its criteria and examples are reworked, because a 40 percent false positive rate destroys system-wide trust and the only way to recover is to remove the broken category until its precision improves. After repair the category is re-enabled with a shadow test comparing old versus new prompts on recent inputs before deployment.

Distinctions that decide answers

ThisNot thisHow to tell them apart
System promptUser messageSystem persists across every turn and frames the assistant, user is per-turn input that can request a temporary shift. Universal standards belong in system, query-specific instructions belong in user.
Explicit categorical criteriaConfidence-based filteringCriteria define what to flag and what to skip with code examples per category. Confidence tries to filter by self-reported certainty, which is poorly calibrated. Hierarchy is criteria first, confidence routing second.
Negative constraintsLower temperatureNegative constraints directly suppress a pattern such as a preamble. Lowering temperature reduces randomness but does not guarantee pattern absence.
Primacy at topRecency near endBoth ends receive strong attention, primacy shapes core behaviour, recency shapes the specific output format. Put behavioural constraints first and examples last.
RACCE frameworkFree-form prose promptsRACCE decomposes the prompt into five testable components. Free-form prose reads like a specification but cannot be diagnosed systematically when quality drops.

Traps

Be conservative or only report high-confidence findings as prompt improvements

The tempting answer. Add the phrases be conservative or only report high-confidence findings because they sound engineering grade.

Why it fails. Both phrases give the model no actionable decision boundary. Conservative varies by context and high-confidence is an uncalibrated subjective threshold. The exam uses them as distractors for exactly their plausible tone.

What is correct. Replace them with explicit categorical criteria and concrete code examples per category that define what counts as a valid finding.

Confidence threshold to fix a high false positive category

The tempting answer. Add only report high-confidence documentation issues to curb a category running at 40 percent false positives.

Why it fails. LLM self-reported confidence is poorly calibrated and does not address the missing definition of what counts as a valid finding in that category, so the same false positives continue at a new cutoff.

What is correct. Define what counts as a valid finding with criteria and examples, then use confidence only as a routing signal to human review.

Keep all categories active while iterating on the broken one

The tempting answer. Keep the high false positive category live during repair because disabling it feels like losing functionality.

Why it fails. Trust bleeds across categories. A 40 percent false positive rate on one category destroys trust in security findings that remain highly accurate.

What is correct. Temporarily disable the unreliable category, rework its criteria and examples, and re-enable only once precision improves, with shadow testing before deployment.

Critical constraints buried in the middle of a long system prompt

The tempting answer. Grow the prompt by appending detail and leave the most important constraints where they were originally written.

Why it fails. Content at the very top receives stronger attention than content buried in the middle due to the primacy effect, so middle-placed constraints are reliably followed less often.

What is correct. Move critical behavioural constraints to the very top, supporting detail to the middle, and examples to the end.

Be ethical or be careful as a constraint

The tempting answer. Add aspirational constraints such as be ethical or be careful to cover safety.

Why it fails. Aspirational constraints are not verifiable from the output, there is no way to check whether Claude was ethical from the text alone.

What is correct. Use testable constraints such as never provide a specific diagnosis or always escalate when the user describes an emergency.

Caching removes the cost of system prompt size

The tempting answer. Treat a 10000 token system prompt as free once prompt caching is enabled.

Why it fails. Caching reduces repeat-call price but not per-call attention footprint. The 10000 tokens still occupy attention budget on every call.

What is correct. Keep the system prompt under 10 percent of working context even when caching, and treat caching as a price discount not an attention discount.

Going deeper than the task statement
Adjacent material that shows up in harder scenario questions.
Negative constraints as a paired complement to positive instructions

A positive instruction to respond only in JSON still permits a preamble such as Here is the JSON. A paired negative constraint that forbids any text before or after the object, preamble, explanation, or markdown fences, suppresses that pattern more reliably than sampling changes.

System Prompt Design
Explicit uncertainty handling as a first-class constraint

A prompt that covers tone and scope but never states what to do when uncertain leaves the model to produce fluent guesses. Adding an instruction to say it is not sure and offer to escalate closes that opening.

Prompt Anti-Patterns
Versioning and shadow testing discipline for prompt changes

Version the system prompt in source control, shadow test a sample of recent real inputs on old versus new prompt, change one RACCE component at a time, and monitor satisfaction, tool call patterns, and refusal rate after deployment.

System Prompt Design
Build it
Replace vague review guidance with explicit criteria and prove trust recovery
  1. Write a baseline system prompt with vague instructions review this code, be conservative, only report high-confidence findings and run it against five snippets containing known bugs, security issues, and style nitpicks.
  2. Rewrite the prompt with explicit categorical criteria per category report bugs and security vulnerabilities, skip style preferences and local patterns, and flag comments only when claimed behaviour contradicts actual code behaviour.
  3. Add concrete code examples for each severity level showing the actual pattern that defines that severity rather than a prose description.
  4. Compare false positive rates on the same five snippets between the vague and explicit prompts and record inconsistency across repeated runs.
  5. Temporarily disable any category whose false positive rate exceeds the threshold, document the specific criteria refinements needed for re-enablement, and shadow test a sample of recent real inputs on old versus new prompt before deploying the re-enabled category.

Verify. The explicit version classifies consistently across runs with measurably lower false positives, the unreliable category stops poisoning trust while disabled, and the re-enabled version holds precision because its boundary is defined by patterns not adjectives.

Answer real questions on this task
8 exam-style questions written against the rules above. You get the reasoning and a note on every wrong option after each answer.
Task 4.216 min

Few-Shot Prompting

Show the pattern with 2 to 4 reasoning-annotated examples so Claude matches a demonstrated judgement instead of interpreting an adjective.

What you need to know

Few-shot examples are the most effective technique for achieving consistent, well formatted output from Claude, more effective than more instructions, confidence thresholds, or temperature adjustments. When output is inconsistent across invocations despite detailed instructions, the first tool to reach for is a small set of examples showing the exact format and judgement you want. The exam presents exactly that scenario and tests whether you choose more instructions or few-shot examples, with the latter as the correct answer.

Few-shot works through in-context learning: Claude generalises patterns from in-context examples more reliably than it follows verbal descriptions of those same patterns. Telling the model to respond in a warm, concise, professional tone with a brief empathy statement leaves warm and concise open to interpretation, while three actual responses exhibiting that tone remove the interpretation step entirely. The model matches the demonstrated pattern rather than reconstructing it from an adjective.

Three triggers tell you few-shot is needed. Detailed instructions produce inconsistent formatting, sometimes a bulleted list and sometimes a table for the same request, more prose will not converge it. Judgement calls are inconsistent on ambiguous cases, for code review the model flags variable shadowing as critical in one file and minor in another, or for routing it sends check my order to different tools depending on phrasing. Extraction produces empty or null fields for information that exists but appears in an unexpected format, inline citations versus bibliographies or narrative text versus structured tables. All three resolve faster with examples than with additional description.

The rules for constructing effective examples are tight. Use 2 to 4 targeted examples, fewer than 2 does not establish a pattern and more than 4 wastes tokens without proportional benefit. Point each example at a specific ambiguous scenario causing problems, not at generic happy paths. Each example must show reasoning, not just input and output, explaining why one action was chosen over plausible alternatives so the model learns the decision principle and generalises to novel inputs. Without reasoning the model learns literals such as queries mentioning order numbers go to lookup_order, with reasoning it learns the principle that specific identifiers route to specific lookup tools.

Examples also reduce hallucination in extraction. Varying document structures such as inline citations, bibliographies, narrative descriptions, structured tables, headers, and embedded text taught through examples help the model handle structural variety without inventing data. A report that lists expenses in a table on one page and buries them in a paragraph on the next is the canonical case where, without examples, the model extracts the table correctly but leaves narrative fields empty or fabricated, and with examples for both structures extraction quality climbs.

Where examples live and how many to use

Few-shot examples appear either embedded in the system prompt as part of the Examples component of RACCE for patterns that should shape every response, or inline in the messages array as a sequence of user and assistant pairs before the actual query for patterns specific to that query. Proximity matters, examples immediately before the user message influence the response more than examples earlier in context due to recency, the same effect that shapes system prompt placement.

Task complexity determines count, not input volume. Simple three-category sentiment classification needs 2 to 3 examples, a complex extraction with 20 fields, nested objects, and conditional logic may need 8 to 10. Few-shot with 2 to 5 offers the best reliability to cost ratio for most applications, zero-shot is cheapest but least reliable for format-sensitive tasks, and many-shot with 5 or more helps nuanced tasks at the cost of context and potential dilution of system instructions.

Ordering, balance, and format hygiene

Example ordering affects output because later examples carry more influence near the query. For balanced classification mix categories rather than grouping all positives then all negatives, grouping biases the model toward the last group seen. If chain-of-thought examples are used the last example's reasoning pattern is most likely to be emulated, and a 5 to 10 percent accuracy swing between orderings is common.

Label balance creates a prior that biases predictions. Four positives and one negative in a five-example sentiment set teaches the model a positive prior comparable to adding hundreds of majority-class training examples. For balanced classification use equal class counts, for genuinely skewed production distributions a proportionally skewed set may be intentional but trades minority accuracy for majority accuracy. Format consistency is non-negotiable, even a missing colon or inconsistent capitalisation is modelled as intentional and may be reproduced, so every example must use identical formatting.

Dynamic few-shot selection is the production pattern when the example bank is too large for a static prompt. Embedding similarity retrieval finds semantically similar examples, keyword overlap such as TF-IDF or BM25 finds term-sharing examples, hybrid combines both, and cluster-based selection serves very large banks of 1000 or more where nearest neighbour is noisy.

Examples with reasoning and the email classification case

Examples without reasoning teach literal pattern matching that fails on novel phrasing. Examples with reasoning that explains why a classification was chosen teach the underlying principle that transfers. For email triage the principle becomes the primary intent is what the customer asks the agent to do, not which keywords appear most often, and a billing question that mentions a refund in passing stays a billing question when the ask is about the bill, while an explicit money back request becomes a refund request.

The same principle resolves code review inconsistency for variable shadowing. Shadowing within an arrow function scope is limited and does not create a bug, so the example classifies it as minor with reasoning about scope. Shadowing across a function boundary that hides a parameter creates real risk and the example classifies it as critical with reasoning about the hidden parameter. With those two examples the model generalises that severity depends on scope and whether something important is hidden, not on whether the word shadow appears.

Mechanism and API surface

In-context learning from 2 to 4 examples
Targeted examples pointed at the ambiguous scenarios causing problems, fewer than 2 does not establish a pattern, more than 4 wastes tokens without proportional benefit for most tasks.
Examples with reasoning over bare pairs
Each example shows input, reasoning for why one choice beats alternatives, then output, so the model learns the principle that generalises rather than the literal mapping that does not.
Placement and proximity
Examples in system prompt shape every response, examples in messages as user assistant pairs before the query shape that query. Closer to the query means stronger influence due to recency.
Ordering and label balance
Later examples influence output more, so mix classes for classification rather than grouping positives then negatives. Equal class counts produce neutral prior, skewed counts produce a prior for the majority class.
Format consistency down to punctuation
Every example uses identical formatting, a missing colon or capitalisation difference is modelled as intentional and may be reproduced in the response.
Dynamic few-shot selection
Embedding similarity, keyword overlap, or hybrid retrieval selects the most relevant examples at request time for large banks, cluster-based selection scales to 1000 or more where nearest neighbour is noisy.
Email triage that stabilises only after reasoning-annotated examples
A production walkthrough with the reasoning chain made explicit.

A customer support triage classifies inbound email as refund_request, billing_question, or general_inquiry based on primary concern. The initial prompt lists detailed prose rules and works on explicit cases, but ambiguous emails such as a billing question with refund language produce inconsistent classification across runs, sometimes refund_request and sometimes billing_question on the same email in consecutive invocations.

Adding more precise prose does not converge the output because prose still relies on interpretation. The correct fix is three few-shot examples with reasoning. The first example shows an email that explicitly requests a refund with I would like my money back classified as refund_request, with reasoning that the explicit refund request is the primary intent and the requested action. The second shows an email that mentions a refund in passing but asks Why is my bill higher this time, please do not make me request a refund classified as billing_question, with reasoning that the primary intent is understanding the bill and the refund mention is conditional. The third shows a general inquiry with no billing or refund content classified as general_inquiry with reasoning that neither keyword appears. With these examples the model generalises that primary intent is what the customer asks the agent to do, not which keywords appear.

A second scenario shows the same mechanism for code review. Variable shadowing is flagged inconsistently as minor in one file and critical in another. Two examples demonstrate the principle with reasoning, shadowing within an arrow function scope classified as minor because the shadow is limited and does not cause a bug, and shadowing across a function boundary that hides a parameter classified as critical because it creates real risk. The model generalises that severity depends on scope and whether the shadow hides something important, and consistency improves across files without a new rule per file.

The hygiene lesson is durable. Mixing classes rather than grouping positives then negatives prevents recency bias toward the last group, keeping formatting identical prevents the model from learning the inconsistency itself, and placing the examples near the query maximises their influence for the next turn.

Distinctions that decide answers

ThisNot thisHow to tell them apart
Zero-shotFew-shotZero-shot relies on instructions alone, few-shot shows examples. Few-shot is more reliable for format sensitive tasks, zero-shot is cheaper for simple transformations.
Few-shot examplesMore detailed instructionsExamples demonstrate the pattern via input-output pairs, more instructions describe the pattern in prose. Examples eliminate interpretation variance, prose reduces it but does not eliminate it.
Examples with reasoningExamples without reasoningWith reasoning the model learns the decision principle and generalises to novel patterns, without reasoning it learns surface pattern matching that may not transfer.
Static few-shotDynamic few-shot selectionStatic uses a fixed set baked into the prompt, dynamic retrieves the most similar examples at request time using embedding or keyword search. Dynamic scales to large example banks, static is simpler to maintain.
Few-shot for classificationSchema changes for fabricationFew-shot teaches consistent extraction from varied structures, schema changes such as making fields optional or nullable prevent fabrication of absent values. The two address different problems and often stack.
Few-shot examplesConfidence thresholdsFew-shot teaches the correct judgement for ambiguous cases, confidence thresholds filter by self-reported certainty which is poorly calibrated. Few-shot fixes judgement, confidence fixes routing.

Traps

More instructions for inconsistent formatting

The tempting answer. Add more detailed prose when detailed instructions already produce inconsistent output structures across invocations.

Why it fails. Prose descriptions still rely on interpretation and more precise prose does not eliminate interpretation ambiguity.

What is correct. Add few-shot examples demonstrating the exact desired format, with reasoning when the format depends on a judgement.

Examples as literal templates only

The tempting answer. Treat input-output pairs as templates the model copies rather than principles it generalises.

Why it fails. Bare pairs teach surface matching, so novel phrasing fails when the literal token does not appear.

What is correct. Include reasoning for why each decision was made alongside the pair, so the model learns the principle behind the mapping that transfers to new inputs.

Confidence thresholds for inconsistent judgement

The tempting answer. Filter inconsistent judgement calls with a confidence cutoff instead of teaching the judgement.

Why it fails. Thresholds are poorly calibrated and do not address the root cause of inconsistency.

What is correct. Show few-shot examples demonstrating the correct judgement for ambiguous cases, with reasoning that names the decision boundary.

Grouped examples by class for classification

The tempting answer. Present all positives first then all negatives because grouping feels organised.

Why it fails. Later examples have more influence than earlier ones, grouping biases the model toward the last group seen and a 5 to 10 percent accuracy swing is common.

What is correct. Mix classes so no class dominates the recency window.

More examples instead of well-chosen ones

The tempting answer. Add many more examples to feel thorough rather than selecting a small well-chosen set.

Why it fails. Two to four well-chosen examples covering the standard case and key edge cases are enough, beyond that token cost rises without proportional benefit and system instructions may be diluted.

What is correct. Keep 2 to 4 targeted examples covering standard plus edge, then verify generalisation on a novel case.

Format inconsistency across examples

The tempting answer. Treat small formatting differences such as a missing colon or inconsistent capitalisation as harmless.

Why it fails. The model treats inconsistency as intentional pattern and may reproduce it, so a colon drop in one example becomes a random colon drop in output.

What is correct. Use identical formatting down to punctuation across every example.

Going deeper than the task statement
Adjacent material that shows up in harder scenario questions.
Selection strategies for which examples to include

Representative sampling for common patterns, edge case emphasis when edge correctness matters more than average, diversity maximisation for varied output styles, and difficulty curriculum from easiest to hardest to prime simple patterns before complex ones.

Few-Shot Prompting
Dynamic retrieval methods and bank size tradeoffs

Embedding similarity for semantic matches, keyword overlap with TF-IDF or BM25 for term matches, hybrid for both signals, and cluster-based selection for very large banks of 1000 or more where nearest neighbour is noisy.

Few-Shot Prompting
Few-shot combined with chain-of-thought for judgement tasks

Examples that pair input, reasoning trace, and output teach both format and decision principle in one demonstration and produce the strongest results for complex judgement.

Chain of Thought
Build it
Prove few-shot with reasoning fixes inconsistency that prose cannot
  1. Create a base extraction prompt with detailed instructions but no examples and test it against ten documents with varied structures including tables, narrative paragraphs, and mixed formats, recording empty field rate and format variance across runs.
  2. Record which fields fail on which document types, for example dates correct from tables but missed in narrative, amounts inconsistent in words versus digits, and line items empty when embedded in paragraphs.
  3. Create three few-shot examples targeting the failing patterns, each including reasoning that explains why the extraction was done that way, and keep formatting identical across the three examples.
  4. Re-run the same ten documents with the few-shot-enhanced prompt and compare empty field rate, format consistency, and extraction accuracy, especially on the document types that previously failed.
  5. Document which structural patterns improve with few-shot and which still need schema changes such as optional and nullable fields to prevent fabrication.

Verify. The same ten documents show a measurable drop in empty fields and format variance, with the greatest improvement on narrative documents, while absent values remain null rather than invented once the schema treats them as optional.

Answer real questions on this task
8 exam-style questions written against the rules above. You get the reasoning and a note on every wrong option after each answer.
Task 4.318 min

Structured Output

Guarantee schema-valid JSON through tool schemas and constrained decoding, then design nullable enums and redundancy fields that handle real document variation.

What you need to know

When you need guaranteed schema-compliant structured output from Claude there is a clear reliability hierarchy, and committing it to memory pays directly on the exam. At the top is tool_use with JSON schemas or the API-level structured outputs mode, which eliminates JSON syntax errors entirely through constrained decoding. Below that is prompt-based JSON where the model is asked to output JSON in a text response, which is probabilistic and will periodically produce malformed output with missing brackets, trailing commas, unquoted keys, or markdown code fences that break parsers.

With tool_use the tool's JSON schema constrains the shape of what Claude returns, and the separate tool_choice parameter controls whether the model must call a tool at all. Prompt-based extraction gives no structural guarantees, so a production parser that expects pure JSON will eventually receive a preamble such as Here is the JSON, a forgotten required field, or commentary before the object, and will fail. The exam builds directly on this hierarchy by asking which approach guarantees schema-valid JSON and which still requires a fallback parser.

The tool_choice parameter has three modes that the exam tests directly. Auto is the default and lets the model decide whether to call a tool or return text, so it may answer conversationally without ever producing structured output. Any forces the model to call a tool but lets it choose which one from the tools array, which is correct when you have multiple extraction schemas and document type is unknown. Forced tool selection with type tool and name guarantees the model calls exactly that tool regardless of input, and the name must character-for-character match a tool in the array or the request returns a 400 error. Use forced selection when a step must run before other steps, such as metadata extraction that must precede enrichment.

Schema design prevents entire classes of errors at the structural level before any model judgement is involved. Optional and nullable fields are the primary defence against fabrication: if a field is required the model is pressured to produce a value even when the source has none, if the field is nullable the model can honestly return null. An unclear enum value handles genuinely ambiguous cases, an other value paired with a freeform detail string handles long-tail categories the predefined enum does not cover, and format normalisation rules in the prompt such as all dates in ISO 8601 or all currency as decimal numbers without symbols enforce consistency alongside the schema.

The structured outputs mode at the API level works through constrained decoding at the sampler. The sampler maintains the set of valid next tokens given the partial output and the target schema, and tokens that would violate the schema such as a string where a number is required or a closing brace before required fields are filled are assigned zero probability at generation time. The model cannot generate them. This is a logit-level intervention, not post-processing. Strict tool use with strict true on a tool definition applies the same mechanism to tool call arguments, guaranteeing the arguments exactly match the provided JSON schema with no missing required fields, no extra fields, and correct types throughout, provided additionalProperties false is set.

Hierarchy and the tool_choice contract

Prompt-based JSON depends on model compliance, which is best effort, while API-level structured outputs and strict tool_use depend on constrained decoding, which is enforced. That difference is why a pipeline that must produce machine-parseable output for a downstream system should never rely on prompt instructions alone; the exam marks the schema-backed path as the only guarantee.

Choosing among auto, any, and forced selection is a design decision. Use auto only when a conversational response is a legitimate alternative to a tool call. Use any when a document could match several schemas and the model should choose the best fit. Use forced selection when a mandatory step must run and the model's preference must not override the workflow order.

Schema patterns that prevent fabrication and brittleness

Make fields nullable with a type union such as string or null or with nullable true depending on the schema dialect, so absence is an honest signal rather than an invented value. Add unclear to enums for genuinely indeterminate cases rather than forcing the model to pick a precise label from an incomplete set.

Pair an other enum value with a freeform detail string so unseen categories do not fail validation and are still captured verbatim. Add a description to every property so a field named tier with description Customer tier one of bronze, silver, gold is unambiguous where tier alone could be a string, integer, or label. Add format normalisation rules in the prompt because the schema enforces structure while the prompt enforces formatting consistency.

Build self-correction into the schema with redundancy fields such as calculated_total versus stated_total plus total_discrepancy, or conflict_detected for contradictory source text, so discrepancy detection surfaces inline without external recomputation for every document.

What tool_use guarantees and what it does not

Tool_use with JSON schemas eliminates JSON syntax errors, the class that includes malformed JSON, missing required fields, wrong data types for structurally enforced fields, and extra fields when strict. It does not prevent semantic errors: values that do not sum correctly, data placed in the wrong field, or fabricated values for missing information inside structurally valid JSON. Those require validation logic in a separate layer, which is the subject of the next task.

This separation is why production needs both layers. Schema catches structure, semantic validation catches correctness, and the two together determine whether a document is accepted, retried, or routed to human review.

Mechanism and API surface

Reliability hierarchy tool_use and structured outputs over prompt JSON
tool_use with JSON schemas and tool use with a JSON schema with json_schema eliminate syntax errors via constrained decoding, prompt-based JSON in text is probabilistic and will produce unparseable output in production.
tool_choice auto, any, and forced
auto lets the model return text, any forces a tool call but lets the model choose which, forced with type tool and name guarantees exactly that tool and 400s on a name mismatch.
Nullable, unclear, and other patterns
Nullable type unions allow honest null when information is absent, unclear handles ambiguous cases, other paired with a freeform detail string captures long-tail categories without validation failure.
Self-correction redundancy fields
calculated_total versus stated_total plus total_discrepancy boolean, conflict_detected for contradictions, and detected_pattern per finding enable inline discrepancy detection and dismissal-driven prompt improvement.
Format normalisation alongside schema
Schema enforces structure, prompt rules such as all dates in ISO 8601 and all currency as decimal numbers without symbols enforce formatting consistency.
Invoice extraction from markdown-wrapped failures to schema-redundant success
A production walkthrough with the reasoning chain made explicit.

A document processing team extracts invoice_number, vendor_name, line_items, and stated_total from invoices. The first implementation uses prompt-based JSON: Extract the fields and return JSON with invoice_number, vendor_name, line_items, and stated_total. In production the model sometimes wraps output in markdown fences, sometimes forgets vendor_name, and sometimes includes a preamble before the object. The downstream parser handles some cases but breaks on others, and the breakage rate is too high for production.

A second pass addresses semantic errors that remain inside valid JSON. The schema is extended to extract both calculated_total, the model sum of line item amounts, and stated_total, the total read verbatim from the document, plus total_discrepancy true when they differ. A Pydantic validator compares the two and routes discrepancies to human review, the schema redundancy pattern for math consistency. Fabrication is addressed in the same pass by making purchase_order nullable with string or null so that when no purchase order exists the model returns null rather than an invented PO number.

The choice of tool_choice completes the design. When document type is unknown the pipeline uses any so the model selects the right extraction tool, and when metadata extraction must precede enrichment it uses forced selection with type tool and name extract_metadata so that step is guaranteed regardless of model preference.

Distinctions that decide answers

ThisNot thisHow to tell them apart
Prompt-based JSONAPI-level structured outputsPrompt-based JSON is probabilistic and may produce malformed output. API-level structured outputs use constrained decoding to enforce the schema at generation time.
tool_choice autotool_choice anyauto lets the model respond with text instead of calling a tool, any requires a tool call but lets the model choose which. For guaranteed structured output with unknown document type use any.
tool_choice anyForced tool selectionany lets the model pick which tool, forced with type tool and name requires exactly the named tool. Use forced when a step must run before others such as mandatory metadata extraction.
Optional or nullable fieldsRequired fieldsRequired pressures the model to fabricate when information is absent, nullable allows honest null. Use nullable when the source may lack the field.
Schema validation for structureSemantic validation for correctnessSchema catches type errors and missing required fields, semantic validation catches arithmetic errors, misplaced values, and fabricated content. Both are required.
strict true on a toolNon-strict tool useStrict applies constrained decoding guaranteeing schema conformance, non-strict relies on best-effort compliance. Strict requires additionalProperties false and correct optional handling.

Traps

Tool schemas prevent all extraction errors

The tempting answer. Treat tool_use with JSON schemas as a complete guarantee against any extraction mistake.

Why it fails. Structural enforcement feels comprehensive but only covers syntax. Semantic errors such as wrong sums, values in wrong fields, or fabricated values for absent data remain inside valid JSON.

What is correct. Add semantic validation and retry with error feedback for correctness, the schema guarantees structure, validation guarantees correctness.

Auto and any are interchangeable

The tempting answer. Use auto when you need guaranteed structured output because both involve tools.

Why it fails. auto allows the model to return text instead of calling any tool, so structured output is not guaranteed. Any guarantees a tool call.

What is correct. Use any for guaranteed structured output with unknown document type, use forced selection when a specific tool must run.

Make every schema field required for completeness

The tempting answer. Mark every field required to ensure nothing is missed.

Why it fails. Required fields pressure the model to invent plausible values when the source lacks information, which is worse than an honest null.

What is correct. Make fields where the source may lack information nullable or optional so the model can return null honestly.

Omit additionalProperties false with strict mode

The tempting answer. Enable strict true without additionalProperties false because it looks like a minor detail.

Why it fails. Strict requires additionalProperties false to explicitly reject extra fields, without it the schema cannot be enforced through constrained decoding.

What is correct. Always set additionalProperties false and include all optional properties in properties even when not required when using strict.

Stay on prompt-based JSON for simplicity

The tempting answer. Keep prompt-based JSON because adding a JSON schema feels like overhead.

Why it fails. Prompt-based JSON periodically produces malformed output and downstream parsers break on that failure class.

What is correct. Use structured outputs or strict tool_use at the API level, which cost nothing extra and eliminate the syntax failure class.

Skip property descriptions as documentation

The tempting answer. Omit description on schema properties because the field name seems self-explanatory.

Why it fails. Descriptions guide the model's interpretation of ambiguous names, a field named tier without description could be a string, integer, or label, with description it is unambiguous.

What is correct. Add a description to every property, especially any name that admits multiple interpretations.

Going deeper than the task statement
Adjacent material that shows up in harder scenario questions.
The schema as the tool's instruction manual

The schema says what parameters exist, what types they accept, which are required, and what valid values are. A precise schema reduces errors and the need for downstream validation and helps Claude construct correct tool calls even on ambiguous inputs.

Schema Definition
Resilient catch-all with other plus detail string

An enum of invoice, receipt, and contract fails on an unseen type. Adding other to the enum and a category_detail string captures the long tail without breaking validation, which is the resilient schema pattern.

Validation Strategies
Evolution history as arrays of value plus source plus effective date

Storing amended fields as arrays of objects with value, source, and effective_date captures both original and amended values for contracts with amendments, invoices with revisions, and policies with updates.

Schema Definition
Build it
Guarantee structure and prove nullable honesty on absent data
  1. Define an extraction tool with a JSON schema containing three required fields, three optional nullable fields, an enum with unclear and other, and a freeform detail string for other, each property with a description.
  2. Send a request with tool_choice auto and observe at least one response where the model returns text instead of a tool call, documenting why auto is unsuitable for guaranteed structured output.
  3. Switch to tool_choice any and verify every response has stop_reason tool_use with a valid tool call conforming to the schema.
  4. Force a specific tool with type tool and name extract_metadata and verify the mandatory extraction step runs on every request even when document content suggests a different tool.
  5. Process five documents, three with complete data and two with missing fields, and verify nullable fields return null rather than fabricated values on the two sparse documents.

Verify. Structure is guaranteed by schema and choice, absent values surface as null instead of inventions, and the long tail is captured through other plus detail without validation failure.

Answer real questions on this task
8 exam-style questions written against the rules above. You get the reasoning and a note on every wrong option after each answer.
Task 4.416 min

Validation and Retry Loops

Add semantic validation and retry with document plus failed output plus specific error so fixable mistakes self-correct and unfixable ones route to human review.

What you need to know

Production extraction systems fail for reasons no schema can prevent. Documents arrive in unexpected formats, line items do not sum to the stated total, values end up in the wrong fields, and plausible looking values appear for data that was never in the source. The question is not whether failures happen but how the system responds, and the validation retry pattern turns those failures into self-correcting workflows.

The correct retry pattern sends three pieces of information back to the model: the original document so the model has the source to re-examine, the failed extraction so it can see what it produced, and the specific validation error so it knows exactly what went wrong. This beats naive retry by a wide margin, because without the specific error the model has no guidance for what to fix and usually reproduces the same mistake, while with it the model can target its correction such as re-examining the document for missed line items, checking field placement, or recalculating a total.

Retries have a clear effectiveness boundary and the exam tests this boundary most aggressively in this task. Retries are effective for format mismatches such as wrong date format or inconsistent currency notation, structural output errors such as values in wrong fields or incorrect nesting, misplaced values where data exists but was extracted into the wrong field, and mathematical errors such as a missed line item affecting a total. Retries are not effective for information genuinely absent from the source document, data that exists only in an external document not provided to the model, or fields requiring knowledge the model does not have. If a document genuinely does not contain a department name, no amount of retrying will produce a correct value; the correct action is to flag for human review or return null when the schema allows it.

The exam distinguishes two error categories that must be handled separately. Schema syntax errors are malformed JSON, missing required fields, and wrong data types, and are eliminated entirely by tool_use with JSON schemas from the previous task. Semantic validation errors are correct JSON structure but incorrect values: line items that do not sum, dates with invalid ordering, values in the wrong fields. Schema validation cannot catch semantic errors because the JSON is structurally valid, only business-rule validation can. The overlap between the two tasks is intentional and the exam tests whether you understand what tool_use solves and what it does not.

Pydantic is the canonical Python validation layer alongside JSON Schema. A Pydantic model does two jobs at once: parsing enforces structure such as types, required fields, and enums, while validators enforce semantics such as cross-field arithmetic or date ordering. Both failure kinds surface through one ValidationError with machine-readable errors naming the field and the broken rule, and the except branch of that validation is the retry-with-error-feedback pattern where Pydantic supplies the specific error in a form that can be formatted straight into the retry prompt. Self-correction schema design reinforces this by building error detection into the extraction shape itself, for example calculated_total versus stated_total with total_discrepancy, conflict_detected for contradictory source text, or detected_pattern per finding for systematic prompt improvement.

The three-part retry message and the fixable boundary

A retry message that contains only the original prompt gives the model the same ambiguous input and produces the same mistake. A retry message that contains the original document, the failed JSON, and the specific validation error in the form what was expected versus what was found gives the model a target, such as Validation errors line_items sum to 450.00 but stated_total is 500.00, please re-extract ensuring all line items are captured.

The boundary decision precedes the retry. Format mismatches, structural errors, misplaced values, and arithmetic errors are fixable and should be retried. Absent information, external data not in source, and knowledge the model lacks are not fixable and should route to human review. The exam presents both shapes and expects the boundary to be applied before choosing retry, not as an afterthought.

Pydantic parsing versus validation and the SDK integration

Parsing enforces structure at parse time through model_validate_json and related entry points, while validation runs after parsing via model_validator with mode after and can access all fields to enforce cross-field rules. Raising ValueError inside the validator adds to the ValidationError returned by model_validate, with loc for the path to the failing field, msg for the error message, and type for the category, all directly formattable into the retry prompt without manual translation.

External validation logic recomputes checks after extraction, while self-correction fields in the schema surface discrepancies without external logic. The two are complementary: external validators are the enforcement, self-correction fields are the surface that makes discrepancy visible inline.

Schema redundancy and dismissal-driven improvement

Schema redundancy builds error detection into the extraction output. calculated_total is populated by summing line_items amount, stated_total is read verbatim from the document, total_discrepancy is true when they differ, conflict_detected flags contradictory text in the source such as payment due 30 days in one section and net 60 in another, and detected_pattern on each finding names the specific construct that triggered the finding.

The detected_pattern field creates a systematic improvement loop. When developers dismiss findings triggered by a specific pattern, that pattern likely needs prompt refinement, not a generic quality complaint. Tracking frequency and dismissal rate per pattern prioritises which prompts to refine next, closing the loop from extract to validate to collect dismissal data to refine prompts to repeat.

Mechanism and API surface

Three-part retry with error feedback
Original document plus failed extraction plus specific validation error in the retry message. Without the specific error the model reproduces the same mistake, with it the model targets correction such as missed line items or misplaced fields.
Fixable versus unfixable boundary
Fixable: format mismatches, structural errors, misplaced values, arithmetic errors. Not fixable: genuinely absent information, data in an external document not provided, knowledge the model lacks. Retries only on the first category.
Pydantic structure versus semantics
Parsing enforces types, required fields, and enums. Validators with model_validator mode after enforce cross-field arithmetic, date ordering, and conditional rules. Both surface via ValidationError with loc, msg, and type.
Self-correction fields in the schema
calculated_total versus stated_total plus total_discrepancy, conflict_detected for contradictions, and detected_pattern per finding build detection into the output shape rather than only in external logic.
Retry budget and routing
Maximum typically three retries, beyond that route to human review. Routing for absent fields uses nullable schema and null return, while low-confidence routing uses calibrated thresholds from labelled validation sets.
Invoice pipeline where totals diverge and purchase orders are invented
A production walkthrough with the reasoning chain made explicit.

A logistics team processes invoices with tool_use and a JSON schema but no semantic validation. The schema catches structural errors such as missing fields or wrong types but lets through semantic errors, and two production failure modes emerge. Line items do not sum to the stated total in 8 percent of invoices because a line item is missed, and the model fabricates plausible purchase order numbers for required fields when the source invoice has no purchase order at all.

The fix has three components. The schema adds calculated_total populated by summing line_items amount and stated_total read verbatim from the document as separate number fields, plus total_discrepancy true when they differ. This builds discrepancy detection into the schema with no external logic needed for the math check. purchase_order and payment_terms become nullable rather than required, allowing honest null returns when the source lacks them. A Pydantic validator enforces that calculated_total equals stated_total and raises a ValueError with the specific mismatch when they differ.

The retry loop catches the fixable errors. When the validator raises, the loop constructs a retry message containing the original invoice text, the failed extraction JSON, and the specific error Validation errors line_items sum to 450.00 but stated_total is 500.00, please re-extract ensuring all line items are captured. The model re-examines the source and self-corrects in one to two retries on most cases, because the specific error targets the missing line item.

The unfixable cases route to human review rather than infinite retry. When an invoice genuinely lacks a department name the loop recognises the field is null and the schema validates, so it flags the document for a human queue instead of retrying. A separate systematic loop tracks detected_pattern on dismissed findings, where a high dismissal rate for variable shadowing in nested scope indicates that pattern's prompt needs refinement rather than a generic quality problem, creating a durable improvement cadence beyond any single retry.

Distinctions that decide answers

ThisNot thisHow to tell them apart
Schema syntax errorsSemantic validation errorsSyntax is malformed JSON, missing required fields, wrong types, eliminated by tool_use with schemas. Semantic is correct JSON with incorrect values such as wrong sums or misplaced fields, requiring validation logic.
Retry with error feedbackNaive retryNaive resends the same prompt, retry with error feedback sends document, failed extraction, and specific error. The latter is dramatically more effective at producing corrected output.
Fixable errorsUnfixable errorsFixable is format mismatches, structural errors, misplaced values, and math errors. Unfixable is absent information, external data not in source, or unavailable knowledge. Retry only the first category.
Schema validationPydantic validationSchema enforces structure via JSON Schema, Pydantic enforces both structure and semantics via validators. Schema catches syntax, Pydantic catches arithmetic and business-rule violations.
Single total fieldcalculated_total plus stated_totalA single total hides discrepancies, the dual field plus total_discrepancy surfaces them inline, the schema redundancy pattern for math consistency.
External validation logicSelf-correction fields in schemaExternal recomputes checks after extraction, self-correction builds the check into the schema surfacing discrepancies without external recomputation for each document.

Traps

Retries always work for extraction failures

The tempting answer. Retry any extraction failure because retry is the default reflex when something fails.

Why it fails. Retries fix format mismatches, structural errors, misplaced values, and math errors, but they cannot produce information genuinely absent from the source, such as a department name the document never contains.

What is correct. Distinguish fixable from unfixable before retrying and route absent-data cases to human review or null when the schema allows it.

Retry without the specific validation error

The tempting answer. Retry by resending the same prompt or only the original document because the retry message is easier to build that way.

Why it fails. Without the specific error the model has no guidance and typically reproduces the same mistake.

What is correct. Include the original document, the failed extraction, and the specific validation error stating what was expected versus what was found.

Schema validation alone is sufficient

The tempting answer. Rely on schema validation because tool_use enforces the schema.

Why it fails. Schema validation catches syntax errors only, semantic errors such as wrong sums, misplaced values, and fabricated data remain inside valid JSON.

What is correct. Add semantic checks with Pydantic validators and route detected discrepancies through the retry loop.

Pydantic is redundant once tool_use enforces a JSON schema

The tempting answer. Drop Pydantic because the schema already enforces structure.

Why it fails. Schemas cannot express cross-field semantic rules such as sums that must match or dates that must be ordered, and validators produce the specific per-field messages the retry loop feeds back.

What is correct. Keep Pydantic validators for business rules and use their ValidationError loc, msg, and type directly in the retry prompt.

Retry indefinitely on the same input

The tempting answer. Keep retrying the same document because more attempts feel more thorough.

Why it fails. Beyond a budget of three the cost exceeds value and unfixable cases will never succeed regardless of attempts.

What is correct. Cap retries at three and route to human review on exhaustion.

Retry unfixable errors because they look similar to fixable ones

The tempting answer. Route any failure through the retry path because the retry infrastructure already exists.

Why it fails. Retries on absent information never succeed and waste API cost while the correct action would have been a null return or a human queue.

What is correct. Apply the fixable versus unfixable boundary before invoking retry, and treat absent data as a routing decision not a correction problem.

Going deeper than the task statement
Adjacent material that shows up in harder scenario questions.
Four validation strategies along speed, cost, and quality axes

Schema validation is very fast and cheap for structure, Pydantic semantic checks add business rules at similar cost, LLM-as-judge adds full semantic accuracy at the cost of an extra API call, and human evaluation gives ground truth at highest cost and slowest speed.

Validation Strategies
Parse versus validate and the role of detected_pattern

Parsing enforces structure at parse time, validators enforce semantics after parsing. The detected_pattern field per finding turns dismissal tracking into systematic prompt improvement by identifying which constructs are dismissed most often.

Schema Definition
Conflict detection as a required extraction pattern

When a source contains contradictory information such as payment due 30 days in one section and net 60 in another, extracting both plus conflict_detected true prevents the model from silently picking one.

Validation Strategies
Build it
Add semantic validation, the three-part retry, and the boundary test
  1. Define an extraction tool with calculated_total and stated_total, conflict_detected, and detected_pattern per finding so discrepancies surface inside the output shape.
  2. Implement validation logic for completeness, numerical consistency between calculated and stated totals, enum validity, and date ordering, each returning a specific expected versus found error message.
  3. Build the retry loop that on validation failure constructs a follow-up message containing the original document, the failed extraction JSON, and the specific validation error and sends it to the model.
  4. Test with five documents, two with fixable errors and three with unfixable absent information, and verify the loop retries only the fixable cases in one to two attempts while the unfixable cases route to human review.
  5. Log detected_pattern per finding and analyse which patterns are dismissed most frequently to prioritise prompt refinement, closing the systematic improvement loop.

Verify. Fixable arithmetic and misplacement errors self-correct with targeted errors, absent-data cases do not burn retries, and dismissal data points directly to the prompt that needs refinement next.

Answer real questions on this task
8 exam-style questions written against the rules above. You get the reasoning and a note on every wrong option after each answer.
Task 4.514 min

Batch Processing

Use the Message Batches API for latency-tolerant work at 50 percent savings and keep blocking workflows synchronous, correlating every batch result through custom_id.

What you need to know

The Message Batches API is a cost optimisation tool with hard constraints that the exam tests directly, and you design around those constraints rather than working around them. The fixed properties are 50 percent cost savings compared to synchronous API calls, results that become available when every request finishes or at the 24 hour ceiling whichever comes first, no per-item latency promise even though most batches complete well inside an hour, and custom_id fields for correlating request-response pairs. These are not tuning knobs, they are the contract.

The matching rule is the single most tested concept from this task. The synchronous Messages API is for blocking workflows where someone or something is waiting for the result: pre-merge checks in CI, real-time code review feedback, or any workflow where developers are blocked pending completion. The Batch API is for latency-tolerant workflows where results are consumed later: overnight technical debt reports, weekly code audit summaries, nightly test generation runs, or batch document extraction. The exam presents a manager who proposes switching everything to batch for the cost savings, and the correct answer keeps blocking workflows synchronous while moving only latency-tolerant workflows to batch, because a 50 percent saving that breaks a merge gate is not a saving.

When designing batch schedules you must plan for the worst case, not the typical case. Results often arrive in well under an hour, but the platform guarantee is within 24 hours, so latency-tolerant designs must budget for the full window. If an organisation requires a 30 hour SLA for a report, the math is 30 hours minus 24 hours of processing equals 6 hours of buffer for collecting requests, validating inputs, and absorbing operational delay. The final batch must therefore be submitted at least 24 hours before the deadline, with submissions every 4 to 6 hours inside the buffer so a fresh batch is always in flight. Working backwards from the SLA is the pattern the exam tests, not polling for status.

A batch request is a single asynchronous unit with no interactive loop between your code and the model in the middle of it. Documentation confirms that tool use including server tools, multi-turn conversation history, system messages, vision, and extended thinking can all appear inside a batched request, so the naive claim that tools are unavailable is too strong. What is genuinely unavailable is a control flow where your own code inspects a tool result and then decides the next request, because nothing runs on your side until the batch ends. Any workflow whose next step depends on reading an intermediate result therefore needs separate requests, and if that decision must happen within seconds it needs the synchronous path. The unsupported request parameters are the ones that assume interactivity or per-request scheduling: streaming, fast-mode speed selection, stateful thread fields, cache and context routing hints, and a zero token ceiling.

Two production disciplines determine batch economics more than the per-token discount. First, sample set refinement before full submission: take 5 to 10 representative documents covering the range of formats, edge cases, and types, iterate on the sample refining prompts, examples, and schema until accuracy is high, then submit the full batch. A 90 percent first-pass success rate on 1000 documents means 100 retries, a 60 percent rate means 400 retries, four times the resubmission cost, so refinement is the highest leverage activity. Second, failure handling resubmits only the failures with targeted modifications, not the entire batch, with modifications such as chunking oversized documents, simplifying prompts for unusual structures, or adding format-specific few-shot examples, each retry batch reusing custom_id with a suffix so correlation stays unambiguous.

Request shape, limits, and correlation

The Message Batches API accepts up to 100000 requests per batch or 256 MB total request size, whichever limit is reached first. Each request carries a unique custom_id that is the correlation key to its eventual response, and the array of requests wraps parameters identical to a synchronous Messages call such as model, max_tokens, and messages. The batch creation response returns a batch identifier whose status can be queried and whose results are retrieved once processing completes.

Results iterate over the array and are checked per item. A successful item has type succeeded and carries the same shape as a synchronous response, a failed item has type errored with an error field. Failure handling filters by type, looks up the original document by custom_id, and constructs a retry batch containing only the failed items with targeted modifications. The per-request model and parameters can vary, so a single batch may contain heterogeneous requests as long as each has its own custom_id.

The matching rule and the 24 hour schedule math

Blocking workflows have someone waiting, latency-tolerant workflows consume results later, and the label determines the API. The exam probes this by naming overnight reports, weekly audits, and nightly runs as batch-eligible and pre-merge checks and real-time screening as synchronous-only, with a manager proposing to batch everything as the distractor. The correct answer preserves synchronous for anything blocking and reserves batch for anything tolerant, because batch has no SLA.

The 24 hour maximum is the planning number, not the observed typical latency. The schedule works backwards from the consumer deadline: consumer deadline minus 24 hours is the latest submission time for the final batch, with a buffer for collection and validation. Submitting every 4 to 6 hours inside that buffer keeps throughput high while respecting the guarantee, and a fallback that tries batch then switches to synchronous on timeout defeats the batch contract because latency cannot be predicted per item.

Cost leverage through sample refinement and targeted resubmission

Submitting a large unrefined batch feels fast but is the most expensive path. Refining on a small representative sample first raises first-pass success from the 60 percent range into the 90 percent range, and the difference on 1000 documents is 400 failures versus 100 failures that each require a retry batch. The cost of a few sample iterations is repaid in avoided resubmission.

Resubmission must be targeted, not wholesale. Oversized documents need chunking into line-item requests, documents with unusual structures need simplified prompts, and structurally varied documents need format-specific few-shot examples. Each pattern gets its own modification, and the retry batch carries the same custom_id convention with a retry suffix so a second failure can be traced to the original document without ambiguity.

Mechanism and API surface

Fixed batch contract
50 percent savings versus synchronous, results available when every request finishes or at the 24 hour ceiling whichever comes first with no per-item latency promise, and custom_id correlation for request-response pairs.
Matching rule blocking versus latency-tolerant
Synchronous for blocking workflows where someone waits such as pre-merge checks, batch for latency-tolerant workflows such as overnight reports, weekly audits, and nightly generation where results are consumed later.
Batch limits and shape
Up to 100000 requests per batch or 256 MB total size whichever is first, requests array with custom_id plus params per item matching a synchronous call, models and parameters can vary per item in the same batch.
Result handling with custom_id
Iterate results, filter by type succeeded versus errored, use custom_id to look up original inputs, retry batch contains only failures with modifications and a suffixed custom_id for correlation.
SLA schedule working backwards
Consumer deadline minus 24 hours is latest submission for the final batch, with 4 to 6 hour submission cadence inside the buffer. Use worst-case latency for planning, not observed best case.
Sample refinement as cost leverage
Refine prompts on 5 to 10 representative documents before the full batch, covering formats, edge cases, and types. Higher first-pass success directly reduces retry count and total batch cost.
Weekly compliance audit that saves 50 percent without breaking the transaction screen
A production walkthrough with the reasoning chain made explicit.

A financial compliance team runs two workflows. The first is a weekly audit over 5000 transactions whose results are consumed Monday morning, taking 6 hours of compute at full price on the synchronous API. The second is a real-time transaction screening system that must complete within 200 milliseconds of each transaction. A proposal to move the entire audit to the Batch API for 50 percent savings is evaluated against the matching rule: the weekly audit is latency-tolerant with results consumed later and fits batch, the real-time screen is blocking and latency-intolerant and must remain synchronous. The final decision moves only the weekly audit, so the saving applies to that cost alone.

Implementation starts with a 50-transaction sample covering the full range of edge cases: large amounts, international currencies, unusual merchant categories, refunds, and partial captures. Three prompt iterations on the sample refine few-shot examples for the unusual categories until sample first-pass accuracy reaches 92 percent. The full batch of 5000 transactions is then submitted with the refined prompts. The first-pass success rate holds at 90 percent, producing 500 failures, compared to the 60 percent baseline without refinement that would have produced 2000 failures, a direct cost demonstration.

Failure handling parses the batch results, groups the 500 failures by custom_id, and clusters them into three patterns. Oversized transactions that hit context limits account for 280 cases and are chunked into separate line-item requests for the retry batch. International transactions with unusual currency notation account for 150 cases and receive a format-specific few-shot example. Low confidence classifications account for 70 cases and receive a refined prompt with stricter criteria. The retry batch of 500 completes in about 3 hours at batch pricing, well inside the overnight window.

The scheduling discipline preserves the consumer guarantee. The consumer deadline is audit results by Monday morning, so with a 24 hour maximum processing window the final batch must be submitted by Sunday morning. The team submits every 6 hours starting Friday afternoon, so the last batch goes out Saturday evening and finishes by Sunday evening with the 24 hour safety margin intact regardless of whether individual batches finish early.

Distinctions that decide answers

ThisNot thisHow to tell them apart
Synchronous Messages APIBatch APISynchronous returns immediately at full price, batch returns within 24 hours at 50 percent lower cost. Use synchronous for blocking, batch for latency-tolerant.
Blocking workflowLatency-tolerant workflowBlocking has someone waiting for the result such as pre-merge checks, latency-tolerant consumes results later such as overnight reports. The matching rule is the most tested concept in this task.
Best-case latencyWorst-case latencyBest case is often much less than 24 hours, worst case is the guaranteed 24 hours. Design around worst case, not best case, because there is no SLA.
custom_id correlationAnonymous requestscustom_id is the unique identifier per request used to match responses to requests. Without it batch results cannot be correlated and failure handling is impossible.
Resubmitting only failuresResubmitting the entire batchResubmitting only the failed custom_id values with targeted modifications saves cost on already successful documents, resubmitting the whole batch wastes cost.
Queue with bounded latencyBatch with fixed collectionA queue processes items as they arrive with bounded per-item latency, batch processes a fixed collection together with no per-item guarantee. Queues suit continuously arriving tolerant workloads, pure batch suits one-shot large jobs.

Traps

Switch all workflows to batch for cost savings

The tempting answer. Move every workflow to batch because 50 percent savings applies uniformly.

Why it fails. Blocking workflows where developers wait for results must remain synchronous. Batch has up to 24 hours with no SLA and will block merges unpredictably regardless of how often it finishes early in practice.

What is correct. Keep blocking workflows on synchronous and move only latency-tolerant workflows to batch, with the saving applied to the tolerant subset alone.

Assume batch results arrive quickly because they often do

The tempting answer. Design a blocking workflow around typical batch speed such as minutes rather than the guaranteed maximum.

Why it fails. Typical latency is much less than 24 hours but there is no SLA, so designing for best case is unsafe for anything blocking.

What is correct. Design around the 24 hour maximum and keep any workflow that cannot tolerate that window on synchronous.

Assume tools cannot appear in a batched request at all

The tempting answer. Read the absence of an interactive loop as tools being unsupported inside a batch.

Why it fails. Documentation lists tool use including server tools, multi-turn history, and extended thinking among what can be batched. What is missing is your own code reading an intermediate result and choosing the next request, because nothing runs on your side until the batch ends.

What is correct. Batch anything that completes as one asynchronous unit, and use the synchronous path only when your control flow must inspect an intermediate result before deciding what to send next.

Resubmit the entire batch when some items fail

The tempting answer. Resubmit the full batch because tracking which items failed requires extra bookkeeping.

Why it fails. Already successful documents are billed again for no reason, which directly wastes the cost savings the batch was meant to capture.

What is correct. Identify failures by custom_id, look up the original inputs, and resubmit only the failed items with the modification each pattern needs.

Skip prompt refinement before a large batch

The tempting answer. Submit the full 5000-document batch first and refine after seeing results because refinement feels like extra work.

Why it fails. A 60 percent first-pass rate means four times the retry count of a 90 percent rate, so the cost of unrefined submission exceeds the cost of a few sample iterations.

What is correct. Refine on 5 to 10 representative documents first, then submit the full batch with the improved prompts.

Poll for status instead of working backwards from SLA

The tempting answer. Monitor batch status with polling to decide when to submit the next batch.

Why it fails. Polling does not solve the scheduling problem, the platform may still hold a batch for the full window regardless of polling frequency.

What is correct. Work backwards from the consumer deadline to determine the latest submission time for the final batch, then submit at fixed intervals of 4 to 6 hours inside the buffer.

Going deeper than the task statement
Adjacent material that shows up in harder scenario questions.
Maximum batch size and the split discipline

Up to 100000 requests or 256 MB per batch, whichever is first, so a 200000-document audit must be split across multiple batches and the per-batch processing window applies to each.

Message Batches API
Batch versus queue as distinct latency patterns

A queue is FIFO with bounded per-item latency, batch is a fixed collection with no per-item guarantee. Queues fit continuously arriving tolerant workloads that collect every 6 hours then submit, pure batch fits one-shot large jobs.

Message Batches API
Grouped failure patterns drive targeted modifications

Failures cluster into oversized documents needing chunking, unusual structures needing simplified prompts, and structural variety needing format-specific few-shot examples, each handled with its own retry modification rather than a single generic retry.

Message Batches API
Build it
Route by latency class, refine on a sample, and schedule from the SLA
  1. List five workflows in a hypothetical organisation and categorise each as blocking synchronous or latency-tolerant batch-eligible with a one-sentence justification per workflow.
  2. Define a batch submission for twenty documents using the Message Batches API format with a unique custom_id, model, max_tokens, and messages per document.
  3. Implement failure handling that parses batch results, filters by type errored versus succeeded, extracts the custom_id values of failures, looks up the original documents, and creates a retry batch with a targeted modification per pattern.
  4. Calculate the submission frequency needed to guarantee a 30 hour SLA given the 24 hour maximum window, showing 30 minus 24 equals 6 hours of buffer and submission at least 30 hours before the consumer deadline every 4 to 6 hours.
  5. Create a five-document sample set covering the range of document types and edge cases, iterate the extraction prompt two to three times on the sample to raise accuracy, then submit the full twenty-document batch and compare first-pass success with and without refinement.

Verify. Each workflow lands in the correct API class, the batch is correlated through custom_id, the schedule respects the 24 hour guarantee, and sample refinement measurably reduces retry count before the full batch runs.

Answer real questions on this task
8 exam-style questions written against the rules above. You get the reasoning and a note on every wrong option after each answer.
Task 4.616 min

Multi-Pass Review

Split large audits into per-file passes plus an integration pass from an independent instance, with calibrated confidence routing to focus human review where it matters.

What you need to know

When Claude reviews its own output in the same session it starts at a disadvantage because it still carries the reasoning it used to generate that output. The model remembers why it chose each approach, classified each finding at a particular severity, or selected certain values, and is less likely to question those decisions. This is not a defect to argue with but a property to design around, and the design that works is an independent review instance: a separate Claude invocation without the prior reasoning context that approaches the output fresh and judges it on what it actually says.

The exam tests this decision directly. When presented with options for improving review quality, an answer that adds please review carefully to the same session is never the correct improvement over an answer that uses a separate model instance. The separate instance is significantly more effective at catching subtle issues because it carries no prior commitment to the decisions it is about to evaluate, while the self-review instance filters evidence through the lens of why it already chose that path.

Large reviews such as multi-file pull requests, complex extraction pipelines, and broad code audits suffer from attention dilution when processed in a single pass. The symptoms are recognisable: detailed feedback on some files and superficial comments on others, obvious bugs missed in the middle of the review, and contradictory findings where a pattern is flagged as problematic in one file while identical code is approved in another. A larger context window does not fix this. The problem is not capacity but attention quality, the model can hold more text but still spreads its attention unevenly across files.

The fix is to split the review into focused passes. Pass one is per-file local analysis, where each file is examined individually with a focused review prompt so every file receives full attention regardless of its position in the batch. This eliminates the inconsistent depth and the middle-file misses, because each invocation sees only one file. Per-file analysis also parallelises naturally since files are independent inputs, so all per-file reviews can run concurrently. Pass two is cross-file integration, where a separate pass receives all per-file findings and checks for cross-file issues that no single-file review could identify: data flow between modules, consistent API usage across services, dependency conflicts, and contradictions among the per-file findings themselves.

Confidence-based routing complements multi-pass review. The review prompt asks the model to report a confidence value typically from 0.0 to 1.0 alongside each finding plus the reasoning for the score. High confidence findings report directly to developers, low confidence findings route to a human review queue. Raw self-reported confidence is poorly calibrated and must not be used for automated decisions without calibration, which uses labelled validation sets where correct outputs are already known. Running the system against the labelled set and measuring how reported confidence tracks actual accuracy identifies the threshold that best separates usually correct from often wrong, and the set should cover the full range of finding types and severity levels rather than an aggregate accuracy number.

Independent instances and why self-review confirms

Independent review uses a fresh API call whose messages array starts without the generation system prompt or conversation history, containing only the output to review plus a focused review prompt. The fresh invocation approaches the output as if seeing it for the first time, which is why its findings are measurably more thorough on subtle issues even though the model and prompt may be the same otherwise.

The cost-quality tradeoff is explicit. Independent multi-pass review with confidence routing costs more than single-pass self-review, and the tradeoff is worth it when review quality directly affects production reliability such as CI pipelines, financial extraction, or compliance analysis. It is not worth it for low-stakes outputs where occasional misses are tolerable, which is why the exam frames the choice around downstream impact rather than abstract thoroughness.

Per-file local passes plus integration pass

Per-file passes ensure consistent depth by giving each file a dedicated context window with the same focused prompt such as Review this file for bugs, security issues, and logic errors. Each file is an independent input that can run concurrently, so total wall-clock time drops even though more API calls are made, and middle files receive the same scrutiny as the first and last.

The integration pass runs sequentially after all per-file reviews complete because it depends on their findings. Its prompt names the cross-file checks explicitly: data flow inconsistencies between modules, contradictory patterns flagged in different files, and API contract violations across service boundaries. Skipping the integration pass saves one call but removes the only mechanism that catches these systemic issues.

Calibrated confidence routing and dismissal-driven refinement

Confidence scores are reported in the structured output alongside each finding with reasoning for the score, and the routing decision of direct report versus human review is based on the score relative to a calibrated threshold. Calibration validates the threshold against labelled sets, so the score becomes a routing signal with a known accuracy boundary rather than an uncalibrated claim.

The detected_pattern field per finding creates a systematic improvement loop beyond calibration. When developers dismiss findings triggered by a specific pattern, that pattern's dismissal rate indicates a prompt refinement priority. Patterns with high dismissal rates need refined prompts, patterns with low dismissal rates are working correctly, and tracking frequency plus dismissal rate per pattern produces a prioritised refinement backlog that continuously improves review quality from production data.

Mechanism and API surface

Independent review instance
Separate API call with no prior generation system prompt or conversation history, only the output to review plus a focused review prompt, so the model judges the code on its content alone without bias from I chose this because.
Per-file local analysis
One focused review invocation per file ensuring consistent depth for every file including middle files, parallelisable because files are independent, carries the same prompt and criteria for each file.
Cross-file integration pass
Sequential pass after all per-file reviews that receives all per-file findings and checks data flow, API contract violations, dependency conflicts, and contradictions among per-file findings.
Confidence reporting per finding
Review prompt requests a 0.0 to 1.0 confidence value plus reasoning per finding, enabling per-finding routing rather than a single document-level threshold.
Calibration on labelled validation sets
Run the system against a labelled set where correct outputs are known, compare reported confidence to actual accuracy, and set the routing threshold that best separates usually correct from often wrong across the full range of finding types and severities.
detected_pattern for systematic refinement
Each finding carries the specific pattern that triggered it, so dismissal tracking by pattern identifies which prompts need refinement and creates a feedback loop from production data.
Fourteen-file pull request that hides a SQL injection in the middle
A production walkthrough with the reasoning chain made explicit.

A pull request modifying fourteen files arrives for automated review at a financial services team. The single-pass review produces the canonical attention dilution symptoms: detailed feedback on the first and last files, superficial comments on the middle files, a missed SQL injection vulnerability in file seven, and contradictory findings where the same shadowing pattern is flagged as problematic in file three but approved in file eleven. A larger context window is proposed as a fix, but the correct answer rejects it because larger capacity does not correct uneven attention quality.

The restructured review splits into per-file local analysis. Each of the fourteen files is reviewed in its own invocation with the same focused prompt for bugs, security issues, and logic errors, so file seven receives the same focused attention as every other file. The SQL injection is now caught because middle files are no longer diluted by neighbours, and parallel execution reduces total wall time since the fourteen per-file reviews run concurrently.

The cross-file integration pass receives the structured findings from all per-file reviews and runs a separate prompt that asks for data flow inconsistencies between modules, contradictory patterns flagged in different files, and API contract violations across service boundaries. It catches the data flow issue between the API service and the data layer that no single-file review could identify, and it surfaces the contradiction between the file three and file eleven shadowing findings so they can be resolved rather than shipped as conflicting guidance.

Each finding is annotated with a confidence score from 0.0 to 1.0 and a reasoning string, with high confidence findings routing directly to the developer and low confidence findings routing to a human review queue. The routing threshold is not taken from raw scores but calibrated against a labelled validation set of past pull requests, so the boundary reflects observed accuracy across the range of finding types rather than self-reported certainty. The result costs more than single-pass self-review but is the correct tradeoff when review quality governs production reliability and regulatory exposure.

Distinctions that decide answers

ThisNot thisHow to tell them apart
Self-review in same sessionIndependent review instanceSelf-review retains reasoning context and tends to confirm prior decisions, independent has no prior reasoning and approaches output fresh, with significantly higher effectiveness on subtle issues.
Single-pass reviewMulti-pass review with per-file plus integrationSingle pass produces inconsistent depth, missed bugs, and contradictions from attention dilution. Multi-pass splits into per-file local passes plus a cross-file integration pass for consistent depth and systemic coverage.
Larger context windowFocused per-file passesLarger capacity does not improve attention quality, the model still gives uneven attention across files. Focused per-file passes ensure consistent depth regardless of window size.
Raw confidence scoresCalibrated confidence thresholdsRaw confidence is poorly calibrated self-reported certainty, calibrated thresholds are validated against labelled sets and suitable for routing decisions. Using raw confidence for automation is an anti-pattern.
Per-file analysisCross-file integrationPer-file catches local issues within a single file such as bugs, security, and logic errors. Integration catches systemic issues across files such as data flow, contract violations, and contradictions.
Routing to human reviewAuto-approving findingsHigh confidence findings auto-report to developers, low confidence findings route to human review. The threshold determines treatment and must be calibrated.

Traps

Self-review in the same session as a viable review strategy

The tempting answer. Review the generated output in the same session to avoid extra API calls because the model already has full context.

Why it fails. The model retains its generation reasoning and is less likely to question decisions it already justified, so subtle issues survive that an independent instance would catch.

What is correct. Use a separate Claude instance with a fresh session and no prior generation history so the reviewer approaches the output without the bias of prior reasoning.

Single pass for large multi-file reviews

The tempting answer. Run a single review pass over fourteen files because single-pass is simpler to implement.

Why it fails. Single-pass multi-file reviews produce inconsistent depth, miss bugs in the middle, and generate contradictory findings due to attention dilution.

What is correct. Split into per-file local passes for consistent depth plus a cross-file integration pass for systemic issues.

Larger context window to fix attention dilution

The tempting answer. Switch to a higher-tier model with a larger context window so fourteen files fit more easily.

Why it fails. The problem is attention quality, not capacity. A larger window holds more text but the model still spreads attention unevenly across files.

What is correct. Keep focused per-file passes, which ensure consistent depth regardless of window size.

Uncalibrated confidence scores for automated routing

The tempting answer. Route findings automatically by raw confidence scores such as treating 0.85 and above as high confidence.

Why it fails. Raw self-reported confidence is poorly calibrated and the score does not reliably track actual accuracy.

What is correct. Calibrate thresholds against labelled validation sets that cover the range of finding types and severities, then route by the calibrated boundary.

Sequential per-file reviews instead of parallel

The tempting answer. Run per-file reviews sequentially because sequential execution is simpler to code.

Why it fails. Per-file reviews are independent inputs that can run concurrently, so sequential execution wastes wall-clock time for no quality gain.

What is correct. Parallelise per-file reviews and run the integration pass sequentially only after all per-file results are available.

Skip the integration pass when per-file reviews find no cross-file issues

The tempting answer. Skip the integration pass to save an API call when per-file reviews appear self-consistent.

Why it fails. The integration pass is the only mechanism that catches cross-file issues such as data flow between modules, API contract violations, and contradictions among per-file findings, which per-file passes cannot evaluate.

What is correct. Always run the integration pass after per-file analysis, regardless of whether per-file findings appear independent.

Going deeper than the task statement
Adjacent material that shows up in harder scenario questions.
Calibration methodology across finding types

Calibration requires labelled sets covering the range of finding types and severities, not an aggregate accuracy number, with threshold selection based on how reported confidence tracks actual accuracy per type.

Validation Strategies
Production review architecture as a five-component workflow

Generation plus per-file review plus integration review plus confidence routing plus calibration loop forms the production architecture, skipping any component reduces review quality in a measurable way.

Confidence Scoring and Uncertainty Handling
Detected_pattern as the refinement backlog signal

High dismissal rate per detected_pattern identifies prompt refinement priorities from real production data, with low dismissal patterns left alone and high dismissal patterns refined first for continuous quality improvement.

Escalation Patterns
Build it
Show single-pass dilution, multi-pass consistency, and calibrated routing
  1. Create a single-pass review prompt and run it against a ten-file mock pull request, documenting inconsistent depth such as detailed feedback on some files and superficial comments on others, at least one missed bug in a middle file, and at least one contradictory finding for the same pattern.
  2. Implement per-file local analysis by iterating over each file with the same focused review prompt for bugs, security, and logic errors, and compare missed bugs between single-pass and per-file results.
  3. Implement a cross-file integration pass that receives all per-file findings and checks for data flow inconsistencies, contradictory findings across files, and API contract violations, producing a synthesis that no single-file pass could produce.
  4. Add confidence scoring from 0.0 to 1.0 per finding with reasoning and implement routing where high confidence goes directly to the developer and low confidence goes to a human review queue.
  5. Use a separate Claude instance with a fresh session and no prior generation history to review a subset of findings and compare its assessment to the original confidence scores, calibrating the routing threshold from the labelled comparison.

Verify. Single-pass shows dilution and contradictions, per-file catches middle-file bugs with consistent depth, integration catches systemic cross-file issues, and calibrated routing separates usually correct from often wrong by measured accuracy rather than raw self-report.

Answer real questions on this task
8 exam-style questions written against the rules above. You get the reasoning and a note on every wrong option after each answer.
Prompt Engineering and Structured Output exam
12 questions, the same number this domain contributes to the real 60-question paper. Drawn fresh from a larger pool each attempt, so a retake is a different paper. You can reveal the answer to any question while taking the exam, which locks that question. Otherwise answers stay hidden until you submit.
Cross-cutting decision table
DecisionChoose thisOver thisWhy
Where to shape every responseExplicit categorical criteria in the system prompt with RACCEBe conservative or high-confidence language in the system promptExplicit criteria define a testable boundary per category, vague adjectives give none and are the classic distractor.
Inconsistent formatting or judgementFew-shot examples with reasoning, 2 to 4 examplesMore detailed prose instructionsExamples remove interpretation variance by demonstrating the principle, prose leaves room for interpretation.
Guaranteed schema-valid JSONtool_use with JSON schemas or tool use with a JSON schema with constrained decodingPrompt asking for JSON in a text responseSchemas enforce structure at generation time, prompt-based JSON is probabilistic and will produce malformed output.
Which tool must runtool_choice any for choice, forced type tool name for mandatory steptool_choice auto when structured output must be guaranteedauto may return text instead of a tool, any guarantees a tool call, forced guarantees the specific tool.
Fields where source may lack dataOptional or nullable fields with unclear and other plus detail stringRequired fields for every propertyRequired pressures the model to fabricate, nullable plus unclear and other allow honest null and long-tail capture.
Schema versus correctnessSemantic validation with Pydantic plus retry with specific errorSchema validation alone with naive retrySchema catches syntax, semantics catches wrong values, and error feedback tells the model what to fix rather than repeating the mistake.
Fixable versus unfixable extraction failureRetry with document plus failed JSON plus specific error on fixable casesRetry on absent information or inverseFormat, structure, misplacement, and arithmetic are fixable, genuinely absent data is not, threshold is typically three retries then human review.
Latency class for a workflowSynchronous for blocking where someone waitsBatch API up to 24 hours with no SLABatch gives 50 percent savings for tolerant overnight and weekly work, synchronous keeps merge gates and real-time screens responsive.
Batch schedulingWork backwards from consumer deadline minus 24 hours, submit every 4 to 6 hoursPoll for status or design around best-case minutesThere is no SLA, plan around worst case and keep a fresh batch in flight.
Batch failure handlingResubmit only the failed custom_id values with pattern-targeted modificationsResubmit the entire batch or resubmit with no changeAlready successful documents should not be billed again, and each failure pattern needs its own fix such as chunking or a format-specific example.
Review quality for generated outputIndependent review instance with no generation historySelf-review in the same sessionSame-session review carries prior reasoning and confirms prior decisions, independent judges the output fresh.
Large multi-file audit coveragePer-file local passes in parallel plus one sequential cross-file integration passSingle pass even with a larger context windowPer-file ensures consistent depth including middle files, integration catches data flow and contradictions that no single-file pass can evaluate.
Confidence for automated routingCalibrated thresholds validated on labelled sets across finding typesRaw self-reported scoresRaw confidence is poorly calibrated, calibrated thresholds separate usually correct from often wrong by measured accuracy.
Why wrong answers keep looking correct
Be conservative or only report high-confidence findings are valid prompt improvements. They sound engineering grade but give no actionable decision boundary. The exam uses them as distractors because conservative varies by context and high-confidence is an uncalibrated subjective threshold that does not define what counts as a valid finding.
More detailed instructions will fix inconsistent formatting the way examples would. Prose descriptions still rely on interpretation and more precise prose does not eliminate interpretation variance. Few-shot examples demonstrating the exact desired format eliminate that variance by showing the pattern rather than describing it.
Tool schemas prevent all extraction errors, so extra validation is unnecessary. Schemas eliminate JSON syntax errors but not semantic errors such as wrong sums, values in the wrong field, or plausible inventions for absent data. Those require semantic validation and retry with error feedback.
Required schema fields are more rigorous than nullable fields. Required pressures the model to fabricate plausible values when the source lacks information, which is worse than an honest null. Nullable and optional fields with unclear and other allow the model to be honest and keep the long tail without validation failure.
Retries always improve extraction, so retry even when information is absent from the source. Retries fix format mismatches, structural errors, misplaced values, and arithmetic errors but cannot produce information genuinely absent from the document or available only in an external document. Absent data should route to human review or null, not infinite retry.
Batch savings apply equally to blocking workflows, so move everything to batch. Batch has no latency SLA and may take up to 24 hours. Blocking workflows where developers wait for a merge gate must stay synchronous, the 50 percent saving is only for latency-tolerant overnight and weekly work.
A larger context window fixes attention dilution in large reviews. The problem is attention quality, not capacity. A larger window holds more text but the model still spreads attention unevenly across files and still produces detailed feedback on some files and superficial comments on others. Focused per-file passes are the correct fix.
Last five minutes
Rules
  • If the system prompt uses be conservative or high-confidence, treat it as the vague distractor and look for explicit categorical criteria with concrete code examples per severity.
  • If output formatting or judgement is inconsistent despite detailed instructions, choose 2 to 4 few-shot examples with reasoning, not more prose, not confidence thresholds, and not temperature changes.
  • If schema-valid JSON must be guaranteed, choose tool_use with JSON schemas or tool use with a JSON schema with constrained decoding over prompt asking for JSON in text.
  • If tool_choice is offered, remember auto may return text, any guarantees a tool call with model choice, and forced type tool name guarantees the exact tool and 400s on a name mismatch, plus strict true requires additionalProperties false.
  • If a field may be absent, choose nullable or optional with unclear and other plus detail string over required, required invites fabrication.
  • If validation fails, choose retry that sends the original document plus the failed extraction plus the specific validation error, capped around three retries, and route genuinely absent information to human review.
  • If a workflow is described as overnight, weekly, or results consumed later, choose batch with custom_id correlation and 50 percent savings, if someone is waiting for a merge result, choose synchronous.
  • If the SLA is 30 hours, subtract 24 hours to get the 6 hour buffer and require the final batch to be submitted at least 24 hours before the consumer deadline, submitting every 4 to 6 hours.
  • If a large pull request review shows detailed feedback on some files and superficial comments on others, choose per-file local passes plus a cross-file integration pass over single pass or larger context window.
  • If review is already done in the same session, choose an independent instance with no prior reasoning, and if routing uses confidence choose calibrated thresholds on labelled sets over raw scores.
Trigger phrases

Look for be conservative versus explicit criteria, detailed instructions still inconsistent versus few-shot, prompt JSON versus tool schema or structured outputs, auto versus any versus forced, required versus nullable with other, retry with versus without the specific error, genuinely absent versus misplaced value, blocking versus latency-tolerant, best-case minutes versus guaranteed 24 hours, custom_id missing versus correlated, self-review same session versus independent fresh session, single pass fourteen files versus per-file plus integration, raw 0 point 8 confidence versus calibrated labelled threshold.

If you see X, think Y

If you see review the code be conservative or only report high-confidence findings think vague boundary that fails verifiability and replace with categories plus examples. If you see detailed instructions produce different structures across invocations think few-shot with reasoning not more prose. If you see output the JSON in the response think prompt-based risk and choose schema with constrained decoding. If you see tool_choice auto for guaranteed structured output think the model may still return text and choose any or forced. If you see purchase order required think fabrication risk and make it nullable. If you see line_items sum does not match stated_total think calculated_total versus stated_total plus retry with the specific mismatch. If you see weekly audit consumed Monday morning think batch eligible, if you see pre-merge check where developers are blocked think synchronous. If you see fourteen files and missed SQL injection in the middle think per-file plus integration, not larger window. If you see please review carefully in the same session think independent instance without prior reasoning.

Official documentation
Every claim on this page traces to Anthropic documentation or a lesson on this site. Verify version-specific limits, flags, and pricing against the live docs.