← All news

News / Learn / Working with model APIs

What is tool calling (function calling)?

You'll be able to give a model a list of tools it can request, run them yourself, and feed the results back.

Tool calling lets a language model ask your code to run a function. You describe the functions in a schema. The model replies with the function name and arguments it wants, but it does not run anything itself. Your code runs the function and sends the result back to the model.

Models cannot see live data, your database, or your payment system on their own. Tool calling is how a product connects the model to those things. It is the basic building block behind most AI agents and assistants you will ship.

You send a request that includes a list of tools. Each tool has a name, a short description, and a JSON Schema for its parameters. The description matters, because the model uses it to decide when a tool fits.

When the model decides a tool is needed, it does not return normal text. It returns a tool call. That call contains the tool name and arguments as JSON. The model may request several tool calls in one turn.

Your code parses the call, checks the arguments, and runs the real function. Then you send the output back as a tool result message, linked to the call by its ID. The model reads the result and either answers the user or asks for another tool.

This loop repeats until the model returns a normal text reply. You stay in control at every step. The model suggests actions, and your code decides whether to carry them out.

A sketch of the request shape. Exact field names vary by provider, so check your provider's docs.

{
  "tools": [
    {
      "name": "get_order_status",
      "description": "Look up the shipping status of an order by its ID.",
      "parameters": {
        "type": "object",
        "properties": {
          "order_id": { "type": "string", "description": "The order ID, such as A-1042" }
        },
        "required": ["order_id"]
      }
    }
  ],
  "messages": [
    { "role": "user", "content": "Where is my order A-1042?" }
  ]
}

A short sketch to show the idea. Check the official docs of the tool you use.

  • Trusting the arguments blindly Validate every argument against your schema and your business rules before running the function. The model can produce wrong or unexpected values.
  • Vague tool descriptions Write a clear one-line description of what the tool does and when to use it. The model chooses tools from these descriptions, so vague ones lead to wrong calls.
  • Letting the model run anything Expose only the functions you intend. Use least privilege, and require confirmation for destructive or costly actions.
  • Forgetting to return results Every tool call needs a matching tool result sent back with the same ID. Otherwise the conversation breaks or the model loops.

Learn about structured output, which constrains the model's text to a schema. Then study the agent loop, retries, and how the Model Context Protocol (MCP) standardizes how tools are exposed to models.

Does the model run the function itself?

No. The model only returns a request with a function name and arguments. Your code runs the function and returns the result.

Is tool calling the same as structured output?

They are related but different. Tool calling asks the model to request an action. Structured output forces the model's reply to follow a schema. Both use JSON schemas.

Why does the model sometimes skip a tool?

The model decides from the conversation and the tool descriptions. If descriptions are unclear or the answer seems known, it may answer directly. Clearer descriptions usually help.

Can a model call several tools at once?

Many providers allow multiple tool calls in one turn. Your code should handle each one and return every result.

Written with AI by CapyLaunch. Spotted a mistake? Email hello@capylaunch.com.