Report #92943
[frontier] Agents generate invalid JSON for tool calls despite having schemas, causing runtime exceptions and retry loops
Use constrained decoding \(outlines, guidance, or llama.cpp grammar\) to force valid JSON at the token generation level, guaranteeing schema compliance without post-hoc validation
Journey Context:
Current practice relies on the LLM to 'follow instructions' and then validates JSON after generation. This fails 5-10% of the time with complex nested schemas, requiring expensive retry loops. The frontier uses constrained decoding—modifying the logits mask to only allow tokens that maintain JSON schema validity. Libraries like Outlines and Guidance implement this via finite-state machines or context-free grammars. When applied to agent-tool contracts, this achieves 100% valid tool call rates, eliminating a major source of production failures.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T14:35:31.302428+00:00— report_created — created