Why LLM Tool Calling Fails: Common Errors and How Models Choose Tools
Large language models can do much more than generate text.
They can search the web, query databases, call APIs, execute code, retrieve documents, and interact with external applications. This capability is one of the foundations of modern AI agents.
But there is a problem: tool calling is not always reliable.
An AI assistant might select the wrong tool, generate invalid arguments, misunderstand an API response, or claim that an operation succeeded when it actually failed.
For example, imagine asking an AI assistant to find a customer's latest order.
The assistant has access to three tools:
search_customersget_customer_ordersupdate_customer_address
It should identify the customer, retrieve the relevant order information, and present the result.
Instead, it might call update_customer_address with incomplete arguments or attempt to retrieve an order before identifying the customer.
The model may produce convincing language, but the actual operation is incorrect.
Understanding why this happens requires looking at how tool calling works, how models select tools, and how developers design reliable integrations.
What Is LLM Tool Calling?
LLM tool calling is a mechanism that allows a language model to request an external operation instead of generating a normal text response.
A tool can represent almost any capability exposed by an application.
Examples include:
- Searching a website.
- Reading a database record.
- Sending an email.
- Calculating a mathematical expression.
- Creating a calendar event.
- Retrieving information from an internal API.
- Running a code execution environment.
The important distinction is that the language model generally does not execute these operations by itself.
It produces a structured request describing which tool should be called and what arguments should be supplied.
The surrounding application interprets that request, executes the operation, and returns the result to the model.
A simplified tool definition might look like this:
{
"name": "get_weather",
"description": "Retrieve current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "Name of the city"
}
},
"required": ["city"]
}
}
The model can use this definition to understand what the tool does and what information it requires.
If a user asks, "What's the weather in Berlin?", the model may produce a structured tool call similar to:
{
"name": "get_weather",
"arguments": {
"city": "Berlin"
}
}
The application then executes the corresponding function.
This interaction is commonly called function calling or tool calling, depending on the platform and implementation.
How Do LLMs Choose Which Tool to Call?
A language model does not normally browse through available tools as a human developer would.
Instead, it receives information about the available tools as part of its model input or through the platform's tool interface.
Each tool usually has:
- A name.
- A description.
- A list of parameters.
- Parameter types.
- Required fields.
- Optional constraints.
The model uses this information to generate an appropriate response.
Consider an assistant with the following tools:
| Tool | Purpose |
|---|---|
search_products | Find products matching a query |
get_product_details | Retrieve details for a known product |
add_to_cart | Add a product to a shopping cart |
checkout | Complete a purchase |
If the user asks, "Find a wireless keyboard under $50," the assistant should select search_products.
If the user asks, "Add the second keyboard to my cart," the assistant needs to identify the selected product and call add_to_cart.
The tool selection process depends on the relationship between the user's request, the available tool descriptions, and the model's learned ability to generate structured actions.
However, the model's decision is not guaranteed to be correct.
A tool description that is unclear, incomplete, or similar to another tool's description can make selection harder.
The Typical Tool Calling Lifecycle
A tool calling workflow usually involves several steps.
Step 1: The User Makes a Request
The user asks the assistant to perform an operation.
For example:
"Find the latest invoice for customer 1024."
Step 2: The Model Receives Available Tool Definitions
The application provides the model with relevant tool descriptions and parameter schemas.
The model identifies that it needs customer invoice information.
Step 3: The Model Generates a Tool Call
The model selects an appropriate tool and produces structured arguments.
For example:
{
"name": "get_latest_invoice",
"arguments": {
"customer_id": 1024
}
}
Step 4: The Application Validates the Request
The application checks whether the requested tool exists and whether the arguments satisfy the expected schema.
It may also verify permissions and business rules.
Step 5: The Tool Executes
The application calls the relevant API, database, or internal function.
Step 6: The Result Returns to the Model
The tool response is added to the conversation.
For example:
{
"invoice_id": "INV-2026-1042",
"status": "paid",
"total": 125.50
}
Step 7: The Model Produces a Final Answer
The assistant interprets the returned information and explains the result to the user.
This final step is important.
The model should distinguish between a successful operation, an error, and an incomplete result.
A tool call is only one part of the workflow. Reliable tool use requires the entire process to work correctly.
Why Does LLM Tool Calling Fail?
There is no single reason why tool calling fails.
Most failures can be grouped into several categories.
1. Incorrect Tool Selection
The model chooses a tool that does not match the user's intention.
Imagine an application with two tools:
search_usersdelete_user
The user asks:
"Can you find the account belonging to Alex?"
The correct tool is search_users.
But if the descriptions are vague or the available context is confusing, the model might select an inappropriate operation.
This problem becomes more likely when applications expose many tools with overlapping responsibilities.
How to reduce it:
Give every tool a specific name and description.
Avoid descriptions such as:
"Handles user operations."
Prefer:
"Search for existing users by email address or username. Does not modify or delete user records."
Descriptions should explain both what a tool does and what it does not do.
2. Invalid Arguments
The model selects the correct tool but provides incorrect parameters.
For example, an API expects:
{
"customer_id": 1024,
"include_orders": true
}
But the model produces:
{
"customer": "1024",
"orders": "yes"
}
The intent is understandable, but the argument types and property names do not match the schema.
A strict application may reject the request.
How to reduce it:
Define clear parameter schemas.
Use explicit descriptions for ambiguous fields.
Specify required parameters and allowed values.
Validate every request before executing it.
3. Missing Context
Some tools require information that is not included in the user's latest message.
For example:
"Cancel my latest order."
The application may need:
- A customer identifier.
- An order identifier.
- A confirmation that the user owns the order.
- A valid cancellation status.
The model cannot safely invent these details.
It should retrieve the necessary information or ask the user for clarification.
How to reduce it:
Design workflows that can retrieve missing information through separate read-only tools.
Do not force the model to guess identifiers or business data.
4. Ambiguous Tool Descriptions
Suppose an application exposes these tools:
get_reportgenerate_reportexport_report
The descriptions may all mention reports, but their responsibilities are different.
The model might select the wrong tool because the descriptions do not clearly explain their intended use.
How to reduce it:
Use distinct descriptions with concrete examples.
For instance:
get_report: Retrieve an existing report.generate_report: Create a new report from supplied filters.export_report: Convert an existing report into a downloadable file.
The model should be able to distinguish retrieval, creation, and export operations.
5. Tool Execution Errors
Sometimes the model does everything correctly, but the external service fails.
Possible causes include:
- API timeouts.
- Authentication failures.
- Rate limits.
- Database connection problems.
- Invalid external service responses.
- Network interruptions.
These are infrastructure failures rather than necessarily model reasoning failures.
The application must return useful error information so that the model can decide whether to retry, use another method, or explain the problem.
6. Incorrect Interpretation of Tool Results
A tool can execute successfully and return information that the model misunderstands.
For example, an API might return:
{
"success": true,
"deleted": false,
"reason": "Record is protected"
}
If the model focuses only on success: true, it might incorrectly tell the user that the record was deleted.
This is a serious reliability issue.
How to reduce it:
Use explicit result fields.
Distinguish between request acceptance and actual operation completion.
For example:
{
"request_received": true,
"operation_completed": false,
"message": "The record is protected"
}
The model should report the actual operation status rather than interpreting a generic success flag as proof of completion.
Tool Calling vs Structured Output
Tool calling and structured output are related, but they are not the same thing.
Structured output is used to make a model return data in a defined format.
For example, an application might ask a model to produce:
{
"category": "electronics",
"confidence": 0.92
}
No external operation necessarily happens.
Tool calling goes one step further.
It allows the model to request an operation that the surrounding application can execute.
For example:
{
"name": "search_products",
"arguments": {
"category": "electronics"
}
}
The first example is structured data.
The second is an action request.
This distinction matters when designing AI applications because returning valid JSON does not automatically mean an external operation has been performed.
Sequential Tool Calling and Multi-Step Agents
Some user requests require more than one tool.
Consider:
"Find the latest order from customer 1024 and send them an email about its delivery status."
This workflow may require:
- Retrieve the customer.
- Find the customer's latest order.
- Retrieve the delivery status.
- Generate an appropriate message.
- Send the email.
The model must coordinate multiple operations.
This creates additional opportunities for failure.
For example, the model might attempt to send an email before retrieving the delivery status.
It might also pass the wrong order identifier between steps.
A reliable application should make dependencies explicit.
The email tool should not receive incomplete or unverified delivery information.
For operations with real-world consequences, the application may also require user confirmation before execution.
This is especially important for sending messages, modifying records, making purchases, or deleting information.
Designing Better Tool Schemas
Tool schema design is one of the most practical ways to improve tool calling reliability.
A good schema should be understandable to both the model and the application.
Consider a poorly designed tool:
{
"name": "process",
"description": "Processes a customer action",
"parameters": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
This definition leaves many questions unanswered.
What does process do?
What kind of ID is expected?
What values are accepted for type?
What does value represent?
A clearer definition might be:
{
"name": "get_customer_orders",
"description": "Retrieve orders belonging to an existing customer. Use this tool when the user asks about order history or order status. This tool does not create or modify orders.",
"parameters": {
"type": "object",
"properties": {
"customer_id": {
"type": "integer",
"description": "Unique identifier of the customer"
},
"status": {
"type": "string",
"enum": [
"pending",
"shipped",
"delivered",
"cancelled"
],
"description": "Optional order status filter"
}
},
"required": [
"customer_id"
]
}
}
The second definition communicates the tool's purpose, expected input, optional filters, and limitations.
It is also easier for developers to validate.
Practical Python Example: Validating Tool Arguments
Tool calls should not be trusted simply because they were generated by an LLM.
The application should validate them before execution.
Python's Pydantic library provides a convenient way to validate structured input.
from pydantic import BaseModel, Field, ValidationError
class GetCustomerOrders(BaseModel):
customer_id: int = Field(
description="Unique customer identifier"
)
status: str | None = Field(
default=None,
description="Optional order status"
)
def get_customer_orders(arguments: dict):
try:
validated = GetCustomerOrders(**arguments)
except ValidationError as error:
return {
"success": False,
"error": "Invalid tool arguments",
"details": error.errors()
}
# Execute the actual business operation here
return {
"success": True,
"customer_id": validated.customer_id,
"status": validated.status
}
result = get_customer_orders({
"customer_id": "1024",
"status": "shipped"
})
print(result)
Pydantic validates the input and converts compatible values when possible.
For stricter behavior, developers can use strict field types and additional validators.
A production implementation should also verify that the customer exists, that the requesting user has permission to access the record, and that the requested operation is allowed.
Schema validation is not a replacement for authorization or business logic.
How to Handle Tool Errors Properly
A reliable tool calling system should have a consistent error-handling strategy.
Consider an API that returns a timeout.
The model should not receive an empty response and be expected to guess what happened.
Instead, the application should return a structured error:
{
"success": false,
"error_type": "timeout",
"retryable": true,
"message": "The order service did not respond in time."
}
This gives the model useful information.
It can explain the problem or request another attempt.
Developers should distinguish between different failure categories:
| Error type | Recommended response |
|---|---|
| Invalid arguments | Correct arguments or ask for clarification |
| Unauthorized | Stop and explain the permission issue |
| Not found | Search again or report missing data |
| Rate limited | Retry with appropriate backoff |
| Timeout | Retry if safe |
| Business rule violation | Explain why the operation cannot proceed |
| Unknown error | Avoid claiming success |
Retries need special attention.
A read-only request can often be retried safely.
A payment, email, or record creation operation may be executed twice if the first request succeeded but its response was lost.
For operations that can create duplicate side effects, use idempotency keys or another mechanism that makes repeated requests safe.
Security Risks in LLM Tool Calling
Tool calling also creates a security boundary.
An LLM should not automatically have permission to execute every operation available in an application.
Imagine an assistant with access to:
- Customer records.
- Payment operations.
- Internal documents.
- User management.
- Administrative settings.
If the model can invoke every tool without authorization checks, an incorrect tool call can have serious consequences.
Several security practices are important.
Enforce authorization outside the model. Never rely on the model to decide whether a user is allowed to access a record.
Validate resource ownership. A customer identifier supplied by the model does not prove that the current user owns that customer account.
Separate read and write operations. Reading information and modifying information should have different permission requirements.
Require confirmation for sensitive actions. Destructive or financially significant operations may require explicit user approval.
Protect against prompt injection. Content retrieved from websites, documents, or external systems should be treated as untrusted data, not as instructions that can override application security rules.
Log tool executions. Record which tool was called, which model or workflow initiated it, whether execution succeeded, and what authorization checks were performed.
These controls remain necessary even when a model supports strict tool schemas.
A valid tool call can still be an unauthorized or harmful operation.
Best Practices for Reliable LLM Tool Calling
When building an AI agent or integrating an LLM into an existing application, the following principles provide a practical foundation.
- Give every tool one clear responsibility.
- Use descriptive names and detailed descriptions.
- Define required and optional parameters explicitly.
- Validate every argument before execution.
- Keep authentication and authorization in application code.
- Return structured success and error responses.
- Make multi-step dependencies explicit.
- Use retries carefully and protect against duplicate side effects.
- Monitor tool selection errors, validation failures, and execution latency.
- Test the system with ambiguous requests, missing information, malformed arguments, and unexpected API responses.
A particularly useful practice is to maintain a tool calling evaluation dataset.
Include examples of user requests and the expected tool, arguments, and outcome.
Run these tests whenever tool descriptions, schemas, models, or orchestration logic change.
This helps developers identify regressions before deploying them to production.
Frequently Asked Questions
What is tool calling in LLMs?
Tool calling allows a language model to request external operations using structured arguments. The surrounding application executes the operation and returns the result to the model.
Why do LLMs choose the wrong tools?
Models can select incorrect tools when descriptions are ambiguous, multiple tools have overlapping responsibilities, user requests lack context, or the model misunderstands the requested operation.
Is function calling the same as tool calling?
The terms are closely related and are often used interchangeably. Function calling commonly describes a structured mechanism for requesting a function execution, while tool calling can refer to a broader range of external capabilities.
Can an LLM execute an API directly?
Usually, the model generates a structured request and the application performs the actual API call. The application controls execution, authentication, validation, and permissions.
How can developers prevent invalid tool arguments?
Use explicit schemas, validate arguments with tools such as Pydantic or JSON Schema, provide clear parameter descriptions, and return structured validation errors.
What is the difference between tool calling and an AI agent?
Tool calling is a mechanism for requesting external operations. An AI agent is a broader system that may use tools, maintain state, plan multiple steps, and coordinate actions toward a goal.
Should every tool call require user confirmation?
No. Read-only operations may not need confirmation. However, actions with significant consequences, such as sending messages, making payments, or deleting records, may require explicit approval.
What is the biggest risk of LLM tool calling?
One major risk is allowing model-generated requests to trigger unauthorized or unintended actions. Applications should enforce permissions, validate inputs, and apply business rules independently of the model.
Final Thoughts
LLM tool calling makes it possible to connect language models with real applications, databases, and services.
But selecting a tool and generating valid arguments is only part of the problem.
A reliable implementation also needs validation, authorization, structured error handling, safe retries, and monitoring.
The most important design principle is simple: treat every model-generated tool call as a request that must be validated, not as an instruction that should automatically be trusted.
When developers combine clear tool definitions with strong application-level safeguards, AI agents become much more predictable and useful in real-world systems.