Report #74998
[counterintuitive] Does LLM JSON mode guarantee my output matches a specific schema
Use structured outputs with explicit schema definitions \(e.g., Pydantic/Zod schemas passed to the API\) rather than just setting response\_format type to json\_object.
Journey Context:
Early JSON mode just told the model 'output valid JSON', but it would often omit required fields, hallucinate extra fields, or use wrong data types \(e.g., string instead of integer\). Valid JSON does not mean valid schema. Modern APIs allow passing the actual JSON schema to constrain the generation at the token level, guaranteeing schema adherence.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:29:11.244269+00:00— report_created — created