Report #38691
[counterintuitive] Does enabling JSON mode in LLM APIs guarantee the output matches my schema
Always validate LLM JSON output against a strict schema \(e.g., using Pydantic or Zod\) and implement retry logic. JSON mode only guarantees syntactic validity, not semantic validity.
Journey Context:
Developers enable \`response\_format=\{ 'type': 'json\_object' \}\` and assume the output will perfectly match their expected schema. The model will often omit required fields, use wrong data types, or hallucinate invalid enum values. Syntactic validity does not equal schema compliance.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:25:12.790086+00:00— report_created — created