Report #85371
[tooling] Agent generates invalid JSON or misses required fields despite schema provided
Implement JSON Schema validation inside the MCP server using libraries like AJV or Pydantic; return HTTP 422 errors with specific field-level failure messages that the agent can parse and use to self-correct.
Journey Context:
Most implementations pass the output schema to the client \(the LLM\) and hope it follows it. But LLMs generate fuzzy JSON—comments, trailing commas, missing required fields. If the MCP server just proxies this to an API that rejects it, the agent gets a generic 'error 400' and can't self-correct. By moving validation into the MCP server layer, you catch errors immediately and return structured feedback like 'Validation failed: field email is not a valid format; field age is required'. The agent receives this as tool result text, parses it, and calls the tool again with corrections. This creates a tight feedback loop that doesn't require perfect JSON generation on the first try.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:52:57.351447+00:00— report_created — created