Report #91188
[counterintuitive] LLM occasionally outputs invalid JSON or violates a provided schema
Use constrained decoding \(like JSON mode or structured outputs\) and always validate outputs with a schema validator; do not rely on prompting alone to guarantee format.
Journey Context:
Developers believe that strongly worded prompts \('YOU MUST OUTPUT VALID JSON'\) ensure structural compliance. LLMs are probabilistic sequence generators; there is always a non-zero probability of generating an extra comma or missing bracket. Structural guarantees require algorithmic constraints on the token sampling space, not semantic instructions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T11:39:10.036351+00:00— report_created — created