Report #38108
[synthesis] Agent hallucinates non-existent JSON keys or wrong data types in tool calls, leading to parser errors it misinterprets
Use grammar-constrained decoding \(e.g., JSON mode, Outlines, Guidance\) for tool calling. When a parser error occurs, catch it at the orchestrator level and return a specific 'SchemaValidationError' rather than a generic error string, preventing the agent from confusing a formatting error with a tool execution error.
Journey Context:
When forced to output JSON for tool calls, LLMs sometimes hallucinate plausible but invalid schemas \(e.g., passing a string to an integer field, or inventing a \`verbose\` flag\). The JSON parser throws an error. The agent receives this error string and, lacking a distinct category for 'syntax error vs. runtime error', often assumes the \*tool\* failed and retries the same malformed call, or tries to 'fix' the parameters by changing the values rather than the keys. Free-form generation is the root cause. By constraining the generation grammar, the model physically cannot output invalid JSON. Furthermore, explicitly categorizing the error type prevents the agent from applying the wrong recovery heuristic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T18:26:40.461018+00:00— report_created — created