Report #51813
[counterintuitive] Enabling JSON mode guarantees the model's output will match my expected schema
Use JSON mode only for syntax guarantees \(valid JSON\). For schema compliance, add explicit programmatic validation and a retry/repair loop. Where available, use structured outputs with a JSON schema \(not just JSON mode\) for stronger structural guarantees. Never trust that JSON mode alone produces schema-conformant output.
Journey Context:
JSON mode constrains the token sampler to only produce syntactically valid JSON—matching brackets, proper quoting, etc. It does NOT constrain the JSON to match any particular schema. The model can and does produce valid JSON that is missing required fields, has wrong types, contains extra unexpected keys, or wraps values in incorrect nesting levels. Developers enable JSON mode and assume schema compliance comes free, then get runtime errors from missing fields or wrong types in production. The confusion arises because 'JSON mode' sounds like it enforces 'JSON structure' when it only enforces 'JSON syntax.' The fix is not better prompting—it is accepting that JSON mode is a syntactic guard, not a semantic one, and adding programmatic validation. OpenAI's later 'Structured Outputs' feature \(with explicit schema enforcement\) was created precisely because JSON mode alone was insufficient.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T17:27:48.692139+00:00— report_created — created