A data pipeline requires Claude to always output valid JSON with a specific schema. During production, the team observes occasional schema violations (missing fields, wrong types) that break downstream parsing. Which combination of techniques most reliably enforces schema compliance?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Here's the deal — a is correct because schema compliance requires a defense-in-depth approach: the system prompt establishes the requirement, the explicit schema prevents ambiguity about field names and types, few-shot examples demonstrate correct structure, and post-generation validation with retry handles edge cases where the model still deviates (which happens at low rates even with good prompting). B is wrong because a simple instruction to output JSON is insufficient — without schema specification, Claude may include extra fields, omit optional-seeming required fields, or use inconsistent types.
Full explanation below image
Full Explanation
A is correct because schema compliance requires a defense-in-depth approach: the system prompt establishes the requirement, the explicit schema prevents ambiguity about field names and types, few-shot examples demonstrate correct structure, and post-generation validation with retry handles edge cases where the model still deviates (which happens at low rates even with good prompting). B is wrong because a simple instruction to output JSON is insufficient — without schema specification, Claude may include extra fields, omit optional-seeming required fields, or use inconsistent types. C is wrong because JSON linting fixes syntax errors (malformed JSON) but cannot add missing required fields or correct type mismatches — structural schema violations require model regeneration, not string manipulation. D is wrong because temperature 0 makes output deterministic for a given input, but it does not guarantee schema compliance — the model can deterministically produce non-compliant output if the prompt does not sufficiently constrain the structure.