Report #12895
[tooling] Tools returning natural language that agents hallucinate parsing
Return valid JSON inside the text content field, but crucially include the output JSON schema in the tool's 'description' field so the agent knows exactly what keys to expect, treating the output as structured data despite the text wrapper.
Journey Context:
MCP doesn't yet have a native 'structured output' content type \(like OpenAI's JSON mode\), so agents rely on the tool description \+ output parsing. The robust pattern is: 1\) Define the return schema in the tool description \(e.g., 'Returns JSON: \{ \\'matches\\': \[...\] \}'\), 2\) Actually return valid minified JSON in the text content, 3\) Ensure the agent knows to parse it \(via few-shot examples in the description\). This avoids the 'stringly typed' interface problem where agents treat JSON as prose and hallucinate keys. Many developers return markdown-formatted JSON or prose explanations, breaking the agent's ability to programmatically use the result.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:16:03.880167+00:00— report_created — created