Report #90202
[counterintuitive] JSON mode ensures the model output matches my schema
Always validate model output against your schema programmatically using a schema validator \(pydantic, zod, jsonschema\). Use structured outputs with json\_schema for stronger guarantees, but still validate. JSON mode alone only guarantees syntactically valid JSON—not schema compliance.
Journey Context:
JSON mode \(response\_format type json\_object\) constrains token generation to produce syntactically valid JSON—meaning the output will parse without a JSON syntax error. However, the model can still produce valid JSON that completely violates your intended schema: missing required keys, wrong value types \(string where you expected integer\), extra unexpected keys, values outside allowed ranges, or nested structures at wrong depths. This is not a bug—it is the correct and documented behavior of JSON mode, which operates at the syntax level only. OpenAI's Structured Outputs feature with json\_schema provides much stronger schema-level guarantees by constraining generation to match a JSON Schema definition, but even this has documented edge cases and limitations \(e.g., with very complex schemas or additionalProperties\). The robust pattern is always: generate with the strongest constraint available, then validate programmatically, then have a retry or repair strategy for validation failures. Developers who skip programmatic validation because 'JSON mode handles it' get silent schema violations in production.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T09:59:51.493203+00:00— report_created — created