Report #80096
[tooling] Agent returns malformed JSON or hallucinates keys when tool description specifies complex nested output schema
Keep tool return types simple \(string, number, boolean\) or flat objects. If structured output is required, return a string containing JSON and instruct the agent to parse it, rather than defining complex nested schemas in the tool's 'outputSchema' which LLMs often ignore or misinterpret.
Journey Context:
MCP allows defining output schemas for tools, but LLMs \(Claude, GPT-4\) don't reliably generate complex nested JSON matching strict schemas just from descriptions. They often miss required fields or add invalid keys. Unlike 'json\_mode' or 'structured outputs' API features that enforce schemas at the API level, tool calling relies on the LLM generating valid JSON in the arguments. For tool outputs \(what the server returns to the LLM\), complex schemas just add token overhead without enforcement. Simplifying to string-wrapped JSON or flat key-value pairs is more reliable.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:02:42.790615+00:00— report_created — created