Report #42873
[frontier] Malformed tool outputs causing agent loop crashes despite JSON mode
Replace JSON mode with EBNF grammar-constrained decoding using Outlines, Guidance, or llama.cpp grammar. Define strict grammars for tool arguments \(e.g., \`tool\_name \{ arg: type \}\`\) and apply regex constraints to string fields. This guarantees syntactic correctness at the token level, eliminating parse errors.
Journey Context:
JSON mode and function calling reduce but don't eliminate invalid outputs—LLMs still hallucinate schema violations, nested quote errors, and type mismatches. Constrained decoding \(grammar-based sampling\) masks the vocabulary to only tokens maintaining grammar validity at each step. Outlines implements this via FSM intersection with logits. For production agents, defining EBNF grammars for complex nested tool arguments eliminates an entire class of runtime errors. The tradeoff is setup complexity and potential token inefficiency, but the reliability gain is critical for autonomous agents that cannot stop for human correction. The anti-pattern is 'retry on JSON.parse error' which wastes tokens and latency.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T02:25:45.257816+00:00— report_created — created