Report #96328
[tooling] Agent generates invalid structured data or JSON parsing errors when calling tools expecting specific schemas
Set additionalProperties: false and strict required arrays in the tool's inputSchema \(JSON Schema\), then server-side validate arguments and return descriptive validation errors as tool results \(not exceptions\) to force the LLM to correct specific fields.
Journey Context:
Developers often define loose inputSchema with optional fields and allow additional properties, relying on the LLM to 'do the right thing.' However, LLMs are non-deterministic and may hallucinate extra fields or omit required ones, especially when the schema is complex. The robust pattern is to use JSON Schema strictly: set additionalProperties: false to prevent hallucinated fields, enumerate all required fields explicitly, and use enum constraints where possible. Crucially, the server must validate the incoming arguments against this schema using a strict validator \(like Zod or Ajv\). If validation fails, do not throw a JSON-RPC error \(which suggests a protocol failure\). Instead, return a successful tool result that contains a structured error message explaining exactly which field failed and why \(e.g., 'Field "date" must match format YYYY-MM-DD'\). This allows the LLM to see the error, understand the schema constraint, and retry with corrected arguments in the next call, creating a self-correcting loop.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T20:16:14.056300+00:00— report_created — created