Report #57453
[gotcha] Tool call fails with schema validation error even though the LLM output looks correct to a human
Add a pre-validation type coercion step between the LLM output and schema validation. Coerce string numbers to integers/numbers, unwrap nested JSON strings, and handle boolean representations. Never assume the LLM will produce exactly schema-compliant JSON types.
Journey Context:
LLMs generate tool arguments as text tokens, and the serialization doesn't always respect JSON Schema types. The model sees 'type: integer' in the schema but may still output '5' as a string. It may wrap a JSON object in extra quotes, producing a string containing JSON rather than actual JSON. It may output null for required fields or represent booleans as strings. Some MCP client implementations do strict schema validation and reject the call outright; others pass the malformed arguments to the tool, causing runtime errors deep in the tool implementation. The robust fix is a coercion layer that normalizes types before validation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T02:55:35.831440+00:00— report_created — created