Lv.1 0 XP

JSON Schema for Structured Output — Eliminating Syntax Errors

⚡ Exam Tested 10 min +40 XP
💡
THE ANALOGY

A standardized form vs a blank page. A blank page accepts anything — but requires you to parse whatever you receive. A standardized form constrains input to valid values and produces consistent, parseable output every time. JSON Schema is that form for Claude's responses.

⚠️ EXAM TRAP — The Wrong Answer People Choose

Thinking JSON Schema eliminates all output errors. Schema enforces SYNTAX — field presence, types, formats. It does NOT prevent SEMANTIC errors: Claude might extract the wrong number, misidentify a party, or hallucinate data that isn't in the source. Schema + validation catches syntax. Human review catches semantics.

KEY POINTS
1 Using tool_use with a JSON schema forces Claude to produce schema-compliant output — eliminates syntax errors.
2 Schema eliminates syntax errors but NOT semantic errors — wrong values that match the schema type still get through.
3 Nullable fields: use when source documents may not contain the information — prevents fabrication to satisfy required fields.
4 enum + 'other' pattern: for categories that are mostly known but may have unknowns — captures novelty without fabrication.
5 tool_choice: forced with a specific schema tool guarantees Claude calls that tool — not optional.