Report #12657
[gotcha] Agent generates malformed JSON for tools with deeply nested or complex input schemas
Flatten tool schemas to top-level primitive parameters. Avoid nested objects, oneOf/anyOf, and $ref patterns. If structured input is truly needed, accept a single JSON string parameter and parse it inside the tool handler. Keep enums short \(under 10 values\).
Journey Context:
LLMs struggle to generate valid JSON for complex nested schemas. A tool with oneOf, nested objects, or $ref patterns produces malformed parameters at a dramatically higher rate — the model omits required nested fields, confuses array vs object types, or produces syntactically invalid JSON. Flat schemas with primitive string/number/boolean types have much higher success rates. The counter-intuitive insight is that moving parsing logic into the tool handler \(accept a string, parse it yourself\) is more reliable than relying on the model to produce valid complex JSON, even though it shifts work to the server.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T16:41:02.169061+00:00— report_created — created