What is tool calling (function calling) in AI, and how does it work?

Author: Mobilina Team · Published:

Illustration of a tool call: the model asks for get_order_status with an order number, the app runs it and returns the result.

Short answer: Tool calling, also called function calling, lets a language model ask your application to run a function and then use the result in its answer. You describe the available tools to the model: a name, what each one does and which inputs it takes. When a question needs one, the model replies with a structured request, for example “call get_order_status with order number 1042”, instead of plain text. Your application runs the function and sends the result back, and the model writes the final answer. The model never runs the function itself; your code decides what actually happens.

Why does tool calling exist?

A language model only produces text. On its own it can’t check today’s stock level, read a customer’s order or book an appointment. Before tool calling, developers asked models to write their requests in a certain format and then tried to parse the free text, which broke easily.

OpenAI introduced function calling in its API on June 13, 2023: developers could describe functions, and the model would return a JSON object with the arguments to call them. Anthropic, Google and others now offer the same pattern, and OpenAI and Anthropic both use “tool calling” and “function calling” for the same thing.

How does the tool calling loop work?

  1. Your app sends the request with tool definitions. Each tool has a name, a description and a JSON Schema for its parameters (Google’s Gemini uses a subset of the OpenAPI schema).
  2. The model decides. It either answers directly or returns one or more tool calls, each with a tool name and arguments.
  3. Your app runs the tool. It checks the arguments, calls your API or database and gets a result.
  4. Your app sends the result back. The result goes into the conversation as a tool result.
  5. The model answers, or asks for another tool if it needs more information.

Google’s documentation states it most plainly: the model doesn’t execute the function itself. The exception is tools the provider runs for you. Anthropic calls these server tools, for example web search and code execution, as opposed to client tools that run in your app.

What does a tool call look like?

A customer writes: “Where’s my order 1042?”

Step What happens
Tool definition get_order_status: “Returns the shipping status of an order. Input: order_id (string).”
Model’s reply A tool call: get_order_status with {"order_id": "1042"}
Your app Looks up order 1042 in the order system: {"status": "shipped", "carrier": "…"}
Model’s answer “Your order 1042 has shipped…”

The model chose the tool and filled in the argument from the message. Your app did the lookup and controlled which data came back.

Which options are worth knowing?

Feature What it does Names in the APIs
Parallel calls The model can request several tools in one turn, e.g. order status and return policy Supported by OpenAI, Anthropic and Gemini; can be switched off
Tool choice Let the model decide, forbid tools or require one tool_choice: auto, none, and required (OpenAI) or any (Anthropic, Gemini)
Strict schemas Makes the arguments match your JSON Schema strict: true (OpenAI, Anthropic); validated mode (Gemini)

Even with strict schemas, validate arguments in your code. A well-formed order number can still belong to someone else.

How do you get tool calls right?

  • Write real descriptions. Anthropic calls a detailed description the most important factor in how well a tool is used, and suggests at least three or four sentences: what it does, when to use it, when not to, and what each parameter means.
  • Keep the list short. OpenAI suggests keeping fewer than about 20 functions available at a time; Google suggests 10 to 20 active tools. Too many similar tools make the choice harder.
  • Remember the cost. Tool definitions are sent with the request and count as input tokens.
  • Use specific types. Enums for fixed choices (“standard” or “express”) remove a whole class of mistakes.

How do you keep tool calling safe?

Tool calling is what lets an assistant act, which is also what makes it risky.

  • Treat tool results as untrusted. When OpenAI launched function calling, it warned that data returned from a tool can contain instructions that make the model take unintended actions. This is prompt injection. Anthropic recommends telling the model that tool output is untrusted and keeping untrusted content inside tool results.
  • Confirm consequential actions. OpenAI recommends asking the user before real-world actions such as sending email, posting online or making a purchase. The MCP documentation suggests approval dialogs, pre-approved permissions and activity logs.
  • Give the least access that works. A tool that reads order status shouldn’t be able to cancel orders.

How does it relate to MCP and agents?

Tool calling is how a model asks to use a tool. The Model Context Protocol standardises how tools are offered: an MCP server lists its tools, each with a name, description and JSON Schema for inputs, and the application calls them on the model’s behalf. An AI agent is, at its core, a model running this loop repeatedly until a task is done. Whether you need that freedom or a fixed sequence of steps is a separate decision: see workflow or agent.

Summary

  • Tool calling lets a model request a function call with structured arguments; your app runs it and returns the result.
  • Tools are described with a name, a description and a schema for inputs; the description matters most.
  • Validate arguments, treat results as untrusted and confirm actions that change, send or pay.

Sources

  1. Function calling – OpenAI
  2. Function calling and other API updates (June 13, 2023) – OpenAI
  3. Tool use with Claude – Anthropic
  4. Define tools – Anthropic
  5. Mitigate jailbreaks and prompt injections – Anthropic
  6. Function calling with the Gemini API – Google
  7. Understanding MCP servers – Model Context Protocol