Report #79072
[counterintuitive] Does LLM JSON mode guarantee the output matches my schema
Always validate LLM JSON output against a strict schema \(e.g., using Pydantic or Zod\) on the application side. Prefer 'Structured Outputs' \(JSON schema enforcement\) over basic 'JSON mode', and still handle validation failures gracefully.
Journey Context:
Developers enable \`response\_format: \{ 'type': 'json\_object' \}\` and assume the output will perfectly match their expected keys and types. Basic JSON mode only guarantees the output parses as valid JSON \(no syntax errors\); it does not guarantee the presence of required keys, correct data types, or adherence to an enum. The model might output \`\{'result': 'success'\}\` when you expected \`\{'status': 'completed', 'data': \{\}\}\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T15:19:09.720092+00:00— report_created — created