Report #91925
[counterintuitive] Does LLM JSON mode guarantee valid output schema
Use constrained decoding \(like Structured Outputs or grammars\) or strict post-generation Pydantic validation with retries, rather than relying solely on basic 'JSON mode'.
Journey Context:
Developers enable JSON mode assuming the output will match their expected schema \(e.g., required fields, specific enums\). JSON mode only guarantees the output is syntactically valid JSON. It does not guarantee semantic validity: it might omit required keys, output null instead of a string, or hallucinate values outside an enum. Constrained decoding forces the model to only emit tokens that match the grammar/schema.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:53:13.436319+00:00— report_created — created