Report #51420
[counterintuitive] Does LLM JSON mode guarantee the output matches my schema
Use structured outputs \(function calling / constrained decoding\) that enforce the schema at the token level, or validate LLM JSON output against a strict JSON Schema validator and retry on failure.
Journey Context:
Developers enable \`response\_format=\{ "type": "json\_object" \}\` assuming it will output their specific required keys. JSON mode only guarantees the output is \*parseable\* JSON \(valid syntax\), not that it adheres to a specific schema \(e.g., it might omit required fields, use wrong data types, or hallucinate extra keys\). Constrained generation is needed for strict schema enforcement.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T16:47:53.601673+00:00— report_created — created