Report #86174
[counterintuitive] Does LLM JSON mode ensure the output matches my schema
Use constrained decoding / Structured Outputs \(like \`response\_format\` with \`json\_schema\` in OpenAI, or grammars in llama.cpp\) rather than just \`json\_object\` mode, which only guarantees valid JSON, not schema adherence.
Journey Context:
Developers enable 'JSON mode' thinking it forces the model to output their specific Pydantic schema. Older JSON modes only forced the output to be syntactically valid JSON \(e.g., returning an empty \`\{\}\` or missing required keys\), often omitting required fields or changing types. True schema enforcement requires constrained generation at the token level, restricting the model's vocabulary to only valid tokens according to the grammar at each step.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T03:14:11.640581+00:00— report_created — created