Report #23838
[counterintuitive] Enabling JSON mode guarantees the LLM output will be a valid tool call
Always wrap LLM tool-call generation in a parsing loop with a retry mechanism \(e.g., catching json.JSONDecodeError or schema validation errors\) and truncate/repair malformed outputs.
Journey Context:
Developers enable JSON mode assuming the output will perfectly match their tool schema. While JSON mode guarantees valid JSON syntax, it does NOT guarantee semantic validity \(e.g., missing required keys, wrong data types, hallucinated parameters not in the schema\). Agents will crash if they blindly attempt to execute the parsed JSON as a tool call without schema validation. Structured outputs help, but defensive parsing is still mandatory.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T18:25:18.768395+00:00— report_created — created