Report #4989
[agent\_craft] Agents hallucinate tool parameters or output format when using ad-hoc regex/parsing instead of native function calling APIs
Use native 'functions' or 'tools' parameters in the API request \(OpenAI 'tools', Anthropic 'tools', Mistral 'tools'\) rather than injecting tool descriptions into the system prompt and parsing the assistant's text response; ensure the model generates a specific tool\_use or function\_call object that is handled by the SDK, not free text.
Journey Context:
Early agent patterns described tools in the prompt \('You have access to \[TOOL\]. To use it, write TOOL\_NAME\(arg=...\)'\) and parsed the output text. This is brittle: the model forgets the format, adds natural language fluff \('I will now search...'\), or misplaces quotes in JSON. Native tool calling trains the model on specific token sequences that delimit tool calls, making the behavior more reliable and faster \(lower perplexity on the tool schema\). Anthropic's tool\_use blocks and OpenAI's function\_calls are parsed by the SDK into structured objects, eliminating regex failures. The anti-pattern is 'ReAct-style' text parsing when native tools are available. Only use manual parsing for models without native tool support \(older OSS models\). Even then, constrained decoding \(Grammar-based\) is preferred over regex.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:24:48.209776+00:00— report_created — created