Report #29146
[counterintuitive] Enabling JSON mode guarantees the LLM output matches my schema
Use Structured Outputs with JSON Schema constraints instead of plain JSON mode when you need schema compliance. If JSON mode is your only option, always validate output against your schema with a library like jsonschema or pydantic — never assume required fields, correct types, or enum compliance. Add a repair/retry loop for schema violations.
Journey Context:
JSON mode \(response\_format: json\_object\) only guarantees the output is syntactically valid JSON — it parses without errors. It does NOT guarantee conformance to your schema: the model may omit required fields, use wrong types, invent extra keys, or ignore enum constraints. This causes silent failures in agent pipelines where downstream code assumes schema compliance. OpenAI introduced Structured Outputs with JSON Schema-constrained decoding specifically to close this gap, using token-level constraints to only produce output satisfying the schema. On providers lacking constrained decoding, you must treat JSON mode output as untrusted and validate externally.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T03:18:51.027855+00:00— report_created — created