Tool Use: Giving LLMs Access to External Systems
Tool use lets an LLM call external functions, like a brain accessing a calculator or the internet. This is the core mechanism behind AI agents that can search the web, run code, or query a database to answer questions. The biggest footgun is assuming the model will always generate a valid function call; without enforcing a strict schema to match your function's expected input, your agent can fail unpredictably.
### The mental model
Think of tool use (or function calling) as giving an LLM a set of APIs it can call. By itself, an LLM is a powerful text-prediction engine, but it's disconnected from real-time data and external systems. Tools are the bridge that allows the model to go beyond its training data to fetch live information, interact with private databases, or execute code.
### How it works
The process is an agentic loop between you and the model: 1. You define a set of available tools, including their names, descriptions, and input schemas, and pass them to the model in your API request. 2. The user provides a prompt, like "What's the latest on the Mars rover?" 3. The model analyzes the prompt and its available tools. It decides that the `web_search` tool is needed. 4. Instead of generating text, the model's response stops with a `tool_use` reason, containing a structured object like `{"name": "web_search", "input": {"query": "latest Mars rover news"}}`. 5. Your application (a *client tool*) or Anthropic's backend (a *server tool*) executes this function. 6. You send the function's output (e.g., a list of search results) back to the model in a subsequent turn. 7. The model uses this new context to synthesize a final, informed answer for the user.
### When to use it
* **Accessing real-time data:** For tasks involving current events, stock prices, weather, or any information not in the model's training data. * **Interacting with private systems:** To query internal company databases, customer relationship management (CRM) software, or personal files. * **Executing code:** To perform calculations, run data analysis scripts, or interact with system shells.
### When NOT to use it
* **For simple tasks:** If a task can be accomplished with good prompting alone, using a tool adds unnecessary latency and cost from the extra API round-trip. * **Without schema validation:** The most critical footgun is trusting the model to always generate a perfectly formed tool call. This leads to brittle agents that break on malformed inputs. Always use features like Claude's `strict: true` to force the model's output to conform exactly to your defined tool schema.
### One canonical example
A user asks: `"What's the weather in Paris?"`
1. **Tool Definition:** You've provided a tool named `get_weather` that accepts a `location` string. 2. **Model Response:** The model returns a `tool_use` block: `{"name": "get_weather", "input": {"location": "Paris"}}`. 3. **Execution:** Your code executes this function, which calls a weather API and gets back `{"temperature": "15°C", "condition": "Cloudy"}`. 4. **Final Answer:** You send this result back to the model, which then generates the user-facing response: "The current weather in Paris is 15°C and cloudy."
Read the original → docs.anthropic.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.