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
Don't just ask for JSON and hope. You need defense in depth: tell Claude to output JSON, give the exact schema, show correct examples, then validate and retry if validation fails. That combination catches rare deviations that prompt-only approaches miss.
Full Explanation
The most reliable approach requests JSON output in the system prompt, provides the exact schema with field types and required fields, includes few-shot examples of correct output, and validates the response using JSON schema validation with retry logic on validation failure. That defense-in-depth method works because 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. The trust-only approach, requesting JSON output in the system prompt and trusting Claude to comply consistently, is insufficient because without schema specification Claude may include extra fields, omit optional-seeming required fields, or use inconsistent types. The JSON linting approach is wrong because JSON linting fixes syntax errors, such as malformed JSON, but cannot add missing required fields or correct type mismatches; structural schema violations require model regeneration, not string manipulation. The temperature-zero approach is wrong because temperature zero makes output deterministic for 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.