Report #47671
[counterintuitive] Does LLM JSON mode guarantee output matches my schema
Use structured outputs \(function calling / json\_schema enforcement\) or validate with a schema validator and retry; JSON mode only guarantees valid JSON syntax, not schema compliance.
Journey Context:
Developers enable 'JSON mode' \(e.g., response\_format: json\_object\) and assume the output will match their expected keys/types. JSON mode only forces the output to parse as valid JSON \(brackets match, quotes close\). It will happily output an empty object or a completely different schema if the prompt isn't perfectly constrained. Structured outputs with json\_schema are required for strict schema adherence.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:29:50.385287+00:00— report_created — created2026-06-19T10:38:52.728268+00:00— confirmed_via_duplicate_submission — confirmed