Tool Use Errors — Claude, GPT, Gemini Function Calling Errors Fix Guide | AI Error Hub
AI Error Hub/Categories/Tool Use & Function Calling Errors
Category Hub

Tool Use & Function Calling Errors

Every function calling error across Claude, GPT, and Gemini — with the fix.

24 documented errors
Tool use (function calling on OpenAI) is the pattern where the model calls your functions with structured arguments. When it works, agents feel magical. When it breaks, the failure modes are subtle: schema violations that pass provider validation but fail your code, arguments the model invented, tools the model called that don't exist, or execution timeouts that leave your agent in an inconsistent state. This hub is every documented tool-use error and its fix.

Errors in this category

Related pillar guides

Related blog posts

Frequently asked questions

Why do function calls sometimes have malformed JSON arguments?

Almost always because you're using prompt-only extraction rather than the provider's function calling API. Providers with schema-enforced generation (Anthropic tool_use, OpenAI strict mode) guarantee syntactically valid arguments. If you're seeing malformed JSON, upgrade to the structured API first before adding repair logic.

What's the difference between tool_use in Claude and function calling in OpenAI?

Underlying mechanics are equivalent — model outputs structured arguments to a defined schema. Differences: OpenAI enforces strict mode (all fields required, additionalProperties: false); Anthropic accepts more permissive schemas but recommends explicit constraints. Message shapes differ too: OpenAI uses tool_calls array in message, Anthropic uses content blocks with type='tool_use'.

How do I handle tools that the model called but don't exist?

Return a tool_result with is_error=true and a message like 'Unknown tool: X. Available tools are: Y, Z.' The model will typically pick a valid tool on the next turn. If it keeps hallucinating tools, review your system prompt — the model is inferring tools from context that don't exist in your tools array.

Can I execute multiple tool calls in parallel?

Yes on both Anthropic (via multiple tool_use blocks in one turn) and OpenAI (via multiple entries in tool_calls). Execute them in parallel in your code (Promise.all or asyncio.gather), then return all tool_results in a single follow-up message.

What's the max number of tools I can define per request?

No hard limit, but practical limits: OpenAI recommends under 20; Anthropic under 30. More tools = larger token budget spent on definitions and more model confusion. See G7 Chapter 6 for the pattern of dynamic tool selection per turn.

Why do my tool arguments come back as strings instead of the JSON types I specified?

On OpenAI, arguments come as a JSON string in tool_calls[i].function.arguments — you have to JSON.parse it. This is a common gotcha. On Anthropic, input is a parsed object in tool_use.input. Same for Gemini's functionCall.args.

How do I test tool-use flows without burning API credits?

Mock the provider client. Return synthetic tool_use responses that match your expected schemas. Test that your tool executor handles them correctly. Only run the real model in periodic golden dataset evaluations, not on every commit.