# Tool Calling

> The Tool Calling is a capability of a language model to request the execution of external functions with structured arguments.

## How does tool calling (function calling) work in LLMs?

The capability of a model to decide that it needs an external function, such as search, a calculator or an API, and return its name with arguments. The application executes the function and passes the result back to the model.

- Topic: AI Agents
- Type: technique

## Example

Wrong:

```json
{
  "name": "search",
  "description": "Search stuff",
  "parameters": { "type": "object" }
}
```

Right:

```json
{
  "name": "search_orders",
  "description": "Find a customer's orders by email. Use before answering order questions.",
  "parameters": {
    "type": "object",
    "properties": { "email": { "type": "string", "description": "Customer email" } },
    "required": ["email"]
  }
}
```

A clear description and a JSON Schema with required fields help the model pick the right tool and pass valid arguments.

## Common mistakes

- Running model-generated arguments directly in a shell or SQL query.
- Vague tool descriptions, so the model picks the wrong tool.

## Key points

- Tool arguments are validated against the schema before the function runs.
- Each tool result is sent back with the matching tool call ID.
- Tool errors are returned to the model as a result with a clear message.
- Tools that write or delete data check permissions on the server side.

## Interview questions

### Does the model run the function itself?

No. It returns the tool name and arguments; your code runs the function and sends the result back.

### Can a model call several tools at once?

Many APIs support parallel tool calls in one response. Return each result with its matching call id.

### Tool calling vs MCP: what is the difference?

Tool calling is the model's ability to request functions. MCP is an open protocol that exposes tools from servers so many apps can reuse them.

## Related cards

- [JSON Schema](https://wonderium.dev/ai/json-schema.md)
- [MCP Tool](https://wonderium.dev/ai/mcp-tool.md)
- [AI Agent](https://wonderium.dev/ai/ai-agent.md)
- [Structured Output](https://wonderium.dev/ai/structured-output.md)
- [SQL Injection](https://wonderium.dev/web/sql-injection.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/tool-calling
- Last updated: 2026-11-25
