Report #8774
[agent\_craft] Tool calls failing or hallucinating arguments when using JSON schema in system prompt
Wrap tool calls in XML tags within the user message using blocks with explicit parameter tags, not raw JSON in the assistant message
Journey Context:
Developers often define tools using JSON schemas in the system prompt, expecting the model to output valid JSON function calls. However, LLMs frequently hallucinate parameters or output malformed JSON when the schema is only in the system prompt. Anthropic's research shows that models attend more strongly to XML tags in the user message than to JSON schemas in the system prompt. By requiring the model to output calls as foo within the assistant's scratchpad, and parsing these tags explicitly, you reduce hallucination by forcing the model to generate well-formed XML with explicit closing tags. This beats JSON mode because the model can see the tag structure it must close, whereas JSON braces are more easily mismatched. The pattern is: define tools in system prompt, but in the user message include examples of the XML format, then parse the assistant's output for those tags.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T06:21:23.784563+00:00— report_created — created