Report #49249
[agent\_craft] Agent produces invalid JSON or XML when calling tools, causing parsing errors and retry loops
Use constrained decoding \(grammar-based sampling\) via libraries like Outlines, Guidance, or llama.cpp grammars to force syntactically valid output at the token generation level, rather than prompting for valid JSON
Journey Context:
Prompting for valid structured output yields only 60-90% reliability due to LLM hallucination of syntax. Constrained decoding masks the logits of invalid tokens, guaranteeing 100% schema adherence \(JSON, YAML, regex-defined formats\). This is essential for agentic tool use where parsing errors trigger expensive retry loops. The tradeoff is slightly higher latency during generation setup, but it eliminates validation-retry cycles.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:09:08.557610+00:00— report_created — created