---
title: "LLM Tools Explained: Tool Calling, Examples & Best Practices"
description: "LLM tools are functions a model can ask your code to run. How tool calling works, the anatomy of a tool definition, writing descriptions models follow, function vs server vs MCP tools, the tools most agents need, and common failures."
category: "guides"
url: https://keirolabs.cloud/blog/llm-tools
published: 2026-11-24
updated: 2026-11-24
---

# LLM tools: what they are, how tool calling works, and which tools to give your model

## The 60-second version

**LLM tools are functions a language model can ask your code to run.** You describe each tool (name, what it does, the arguments as JSON Schema). The model replies either with text or with a request to call a tool. Your code runs it and sends back the result, and the model continues. This is called **tool calling** or **function calling**, and it's how a model searches the web, reads files, queries databases or takes actions.

| Kind of tool | Who runs it | Examples |
|---|---|---|
| **Function tools (client tools)** | Your code | Your search API, your database, sending an email |
| **Provider-hosted (server) tools** | The model provider | Claude's web search and web fetch tools, code execution |
| **MCP tools** | An MCP server you connect | Any tool exposed over the Model Context Protocol |

**The model never runs anything itself.** It only produces a structured request; something else executes it.

## How does tool calling work?

**One round trip looks like this:**

1. **You send** the user's message plus the tool definitions.
2. **The model decides** whether it needs a tool. If so, it returns a tool call: the tool's name and arguments as JSON.
3. **Your code runs** the function with those arguments.
4. **You send the result back** as a tool result message.
5. **The model continues:** it answers, or calls another tool.

**Repeat steps 2 to 5 in a loop and you have an agent** ([AI agent vs agentic AI](/blog/ai-agent-vs-agentic-ai)).

## Anatomy of a tool definition

**A tool is a name, a description and an input schema.** Here's a web search tool in the format Claude's Messages API uses:

```json
{
  "name": "web_search",
  "description": "Search the live web. Returns numbered results with title, URL and snippet. Use it for anything recent, or anything you are not sure about. Keep queries short: 2 to 10 words.",
  "input_schema": {
    "type": "object",
    "properties": {
      "query": {"type": "string", "description": "A short search query"},
      "count": {"type": "integer", "description": "Number of results, 1 to 10", "default": 6}
    },
    "required": ["query"]
  }
}
```

**OpenAI-style APIs use the same JSON Schema,** under `parameters` instead of `input_schema`. Ollama's Python library can even build the definition from a Python function's signature and docstring ([Ollama web search](/blog/ollama-web-search)).

**When Claude calls the tool,** its reply contains a `tool_use` block with an `id`, the `name` and the `input`. You answer with a user message containing a `tool_result` block that carries the same `tool_use_id` and your output.

## The description is the most important line

**The model decides when and how to call a tool almost entirely from its description.** Most tool-calling bugs are description bugs. Write it like documentation for a new colleague:

- **Say when to use it,** not just what it does: "Use it for anything recent, or anything you are not sure about."
- **Say what comes back,** so the model knows how to use the result.
- **Give argument guidance:** "Keep queries short: 2 to 10 words." Models default to long, over-specific queries.
- **Say when *not* to use it,** if two tools overlap.
- **Keep tool names distinct.** `search_web` and `search_docs` beat `search` and `search2`.

When Anthropic had an agent test a tool and rewrite its flawed description, later agents using the new description saw a 40% decrease in task completion time ([How we built our multi-agent research system](https://www.anthropic.com/engineering/multi-agent-research-system)).

## What tools does an LLM actually need?

**Most useful agents start with a small set:**

| Tool | Why |
|---|---|
| **Web search** | Current facts beyond the training cutoff; the most-called tool in most agents |
| **Read page / fetch URL** | Full text when snippets aren't enough |
| **Code execution** | Exact math, data analysis, charts |
| **Your own data** | Database queries, internal search, the user's account |
| **Actions** | Send, create, update: the risky category |

**Start with two or three tools.** Every extra tool costs context (its definition is sent with every request) and gives the model another way to choose wrong.

## Function tools vs server tools vs MCP

- **Function tools:** you define them, you run them, you control them completely. Any API, any logic, any provider. The default choice.
- **Server tools:** the provider runs them, so there's no code for you to host. Claude's web search tool is one ([Claude web search tool](/blog/claude-web-search-tool)). The trade-off is less control over sources, pricing and data handling, and they only work with that provider's models.
- **MCP tools:** tools packaged as a server that any MCP-capable client can connect to (Claude Desktop, Claude Code, IDEs, agent frameworks). Write a tool once and use it everywhere ([how to build an MCP server](/blog/how-to-build-mcp-server)).

## A tested search tool in Python

**The function behind the definition above.** It returns compact, numbered text, which models handle better than raw JSON:

```python
import os, requests

def web_search(query: str, count: int = 6) -> str:
    r = requests.post("https://api.keirolabs.cloud/api/v2/search/lite",
                      headers={"Authorization": f"Bearer {os.environ['KEIRO_API_KEY']}"},
                      json={"query": query, "count": max(1, min(count, 10))}, timeout=30)
    r.raise_for_status()
    return "\n\n".join(f"[{i+1}] {x['title']}\n{x['url']}\n{x.get('snippet', '')}"
                       for i, x in enumerate(r.json()["results"])) or "No results."
```

**Clamp arguments** (`count` here) instead of trusting the model, and **return errors as text** ("No results.", "Page could not be loaded") so the model can recover instead of crashing your loop. The full loop with a real model is in [LLM web search tool calling](/blog/llm-web-search-tool-calling).

## Common problems with LLM tools

- **The model doesn't call the tool.** Make the description say when to use it; put today's date in the system prompt so the model knows its knowledge is old.
- **It calls tools in a loop.** Cap the number of steps, and return clear "no results" messages instead of empty strings.
- **Bad arguments.** Validate against the schema and return the validation error as the tool result; models fix their own calls well.
- **Huge tool results.** Trim outputs before returning them; a full web page can be tens of thousands of tokens ([context engineering for search agents](/blog/context-engineering-web-search-agents)).
- **Tool results carry instructions.** Text from the web or from users can try to redirect the model. Treat tool output as data ([prompt injection from web search results](/blog/prompt-injection-web-search-results)).
- **Risky actions.** Require human confirmation for anything that sends, buys or deletes.

## Checklist

- **Name, description, JSON Schema: write the description for a new colleague.**
- **Start with 2 to 3 tools; web search is usually the first.**
- **Return compact text, clamp arguments, return errors as text.**
- **Cap the loop; trim results; confirm risky actions.**

Keirolabs gives LLM tools web search (`/search/lite`), page reading (`/extract`) and both together (`/search/content`) through one API key. New accounts get up to 2,000 free credits with no card ([get a key](https://platform.keirolabs.cloud/register)).
