Report #81977
[frontier] LLM returns malformed JSON or schema violations despite JSON mode
Use constrained decoding with Outlines or XGrammar to guarantee schema compliance at the token level
Journey Context:
JSON mode reduces but doesn't eliminate schema violations; LLMs still hallucinate keys or wrong types. Constrained decoding \(Outlines, XGrammar\) masks the vocabulary logits at each step to enforce the schema grammar \(JSON Schema, regex, EBNF\). Guarantees 100% valid output vs 85-95% for JSON mode. Eliminates need for retry loops and post-validation. Tradeoff: requires specific inference engines \(vLLM, transformers with outlines\) and increases latency slightly for complex schemas. Not compatible with API-only models unless using server-side constrained generation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T20:11:21.544053+00:00— report_created — created