Report #44042
[counterintuitive] Does LLM JSON mode guarantee the output matches my schema
Always validate LLM JSON output against a strict schema \(e.g., using Pydantic/Zod\). Use structured outputs \(like OpenAI's function calling or structured outputs with json\_schema\) rather than just basic JSON mode.
Journey Context:
Developers enable JSON mode assuming it forces the model to output their specific JSON schema. Basic JSON mode only guarantees the output is parsable JSON \(valid syntax\), not that it conforms to your specific schema \(e.g., required keys, correct types, allowed enums\). It might output an empty object or omit required fields. Newer 'Structured Outputs' features constrain the grammar to match a provided schema, but older JSON modes do not.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T04:23:55.892185+00:00— report_created — created