LLM Tool Calling Explained: How Models Ask Your Code to Act

Cover image for LLM Tool Calling Explained: How Models Ask Your Code to Act: OpenAI (official image)

Key facts

Sources checked Nov 19, 2026

  • Tool calling (also called function calling) is how a model asks your software to do something: look up a record, run a search, or call an API. The model does not run the tool itself. It returns a structured request, your code runs it, and you send the result back.
  • OpenAI’s function calling guide describes the loop as: the model emits a tool call, your application executes it, you append the tool output as a new message, and the model continues. Anthropic’s tool use docs use the same pattern on the Messages API.
  • Give each tool a clear name, a short description, and a JSON Schema for its arguments. Vague descriptions are a common reason models call the wrong tool or skip a tool they should have used.
  • Tool definitions sit in the prompt, so they cost input tokens on every turn unless your provider can cache them. That matters more than it first looks once you add more than a handful of tools.

Tool calling is the difference between a chatbot that only talks and a model that can actually do work: fetch a price, open a ticket, or query a database. This explainer covers the request loop, how to describe tools well, and the mistakes that waste tokens or produce garbage calls. It is for anyone wiring a model to real software.

What actually happens in a tool call

A language model cannot reach your database or the public internet on its own. When you enable tools, you send two extra things with the prompt: a list of tool definitions, and permission for the model to request one.

The loop looks like this:

  1. You send the user message plus the tool list.
  2. The model either answers in plain text, or returns a tool call: a tool name and a JSON object of arguments.
  3. Your application checks the name, validates the arguments, runs the function, and captures the result.
  4. You send that result back as a tool-result message.
  5. The model uses the result to answer, or it requests another tool.

Nothing in that loop is magic. If you skip validation, the model can invent an argument you never allowed. If you forget to send the result back, the model has nothing new to work with and will often retry or stall.

A typical OpenAI-style definition, following the official function calling shape, looks like this:

{
  "type": "function",
  "function": {
    "name": "get_order_status",
    "description": "Look up the current status of a customer order by its order ID.",
    "parameters": {
      "type": "object",
      "properties": {
        "order_id": {
          "type": "string",
          "description": "The order ID, for example ORD-10482."
        }
      },
      "required": ["order_id"],
      "additionalProperties": false
    }
  }
}

Keep the description concrete. “Gets order info” is weaker than “Look up the current status of a customer order by its order ID.”

Screenshot of OpenAI: Function calling | OpenAI API
Screenshot: OpenAI: Function calling | OpenAI API (official page, captured December 1, 2026).

Why the schema matters more than the prompt

The schema is the contract. A good one does three jobs:

  • Names the tool in a way a model can match to the user’s request (get_order_status, not helper1).
  • Limits the arguments to what your code can actually handle, including types and required fields.
  • Explains each field so the model fills it from the user’s wording instead of guessing.

If a field is optional, say when to omit it. If a value must be one of a few choices, use an enum. If two tools are similar, spell out the difference in the descriptions (“use this for tracking an existing order; use create_order to place a new one”).

Local runtimes follow the same idea. Ollama, LM Studio and llama-server all accept OpenAI-compatible tool definitions when you use their HTTP APIs. The guide to using a local model as an OpenAI-compatible API covers how to point a client at those servers. Smaller local models miss or mangle tool calls more often than frontier APIs, so validate every argument before you run anything that can change data.

Tokens, caching, and how many tools to send

Every tool definition is part of the prompt. Ten detailed tools can add thousands of tokens to every request. Two ways to keep that under control:

  • Send only the tools the current task needs. A support bot answering “where’s my order?” does not need your code-execution tool.
  • Use prompt caching when your provider supports it, so the stable tool list is not billed at the full input rate on later turns. Our prompt caching explainer walks through how Claude, OpenAI, Gemini and Muse bill cache hits.

Some newer models also support a tool search or deferred-loading pattern, where the full tool list stays out of the prompt until a search tool returns the one that is needed. Liquid documents this for LFM3-1.7B. Treat that as an advanced option: the basic loop above is still what most apps should implement first.

Watch: a clear walkthrough

IBM Technology explains tool calling: how a model selects a tool, sends a structured request, and uses the result (January 2025).

Common mistakes

  • Letting the model “run” the tool. It cannot. If your code does not execute the call, nothing happens.
  • Skipping argument validation. Parse the JSON, check required fields, and reject values outside the schema before they touch production systems.
  • Putting side effects in a tool the model might call twice. Models retry. Make writes idempotent, or confirm with a user before you charge a card or send an email.
  • Dumping huge tool results back into the context. Summarize or truncate. A 50-page API response will crowd out the actual question and raise the bill.
  • Forgetting that tool results become visible context. Do not return secrets, raw credentials, or other users’ data.

Bottom line

Tool calling is a tight loop: you declare tools with a schema, the model requests one, your code runs it, and you send the result back. Write precise descriptions, validate every argument, and keep the tool list small enough that it does not dominate the prompt. Once that loop is solid, you can add caching, confirmation steps, and more tools without the whole system getting sloppy.

Sources: OpenAI function calling guide, Anthropic tool use overview, Liquid AI LFM3-1.7B docs (defer loading / tool search). Facts checked November 19, 2026.

Cover image: OpenAI (official image)