Report #85734
[counterintuitive] Does LLM JSON mode guarantee the output matches my schema
Use structured outputs \(function calling or json\_schema enforcement\) or Pydantic validation post-generation. JSON mode only guarantees valid JSON syntax, not that the keys, types, or required fields match your expected schema.
Journey Context:
Developers enable JSON mode and assume the output will perfectly map to their Pydantic model. This only forces the output to parse as JSON without syntax errors. The model can still omit required keys, output strings instead of integers, or hallucinate extra fields. Structured outputs constrain the generation to the specific schema.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T02:29:23.767201+00:00— report_created — created