What Is Function Calling (Tool Use)?

Function calling, also called tool use, is the mechanism that lets a language model ask an application to run a specific function, such as “look up order 4512” or “get the weather in Kyiv”, and then use the result in its answer. The model does not run anything itself. It returns the name of the function and the arguments in a structured format; the application decides whether to run it, runs it, and sends the result back.

Function calling is what turns a model that can only write text into a component that can read live data and take actions. It is the foundation of every AI agent.

How Function Calling Works

OpenAI’s documentation describes the loop in five steps (OpenAI function calling), and other vendors work the same way:

  1. The application sends the user’s request together with a list of available tools. Each tool has a name, a description of what it does and a JSON Schema describing its parameters.
  2. The model decides whether a tool is needed. If so, it returns a tool call: the tool name and the arguments.
  3. The application validates the arguments and runs the function with its own code and credentials.
  4. The application sends the result back to the model.
  5. The model writes a final answer, or asks for more tool calls, and the loop continues until the task is done.

Most APIs also let the application control the choice: let the model decide, require at least one tool call, force a specific tool, or allow only a subset of tools. Models can request several calls at once (parallel calls) when the steps are independent.

Strict Schemas

Early function calling was best effort: the model usually produced valid arguments, but sometimes invented fields or wrong types. Current APIs offer a strict mode in which the arguments reliably match the declared schema; OpenAI’s version requires every property to be listed as required and no extra properties to be allowed. This is closely related to structured outputs. Strict mode guarantees the shape of the arguments, not that the values are correct: a well-formed call can still ask for the wrong customer.

Designing Good Tools

The model chooses tools by reading their names and descriptions, so tool design is a large part of the work:

  • Few, distinct tools. Overlapping tools (“search_orders” and “find_order”) lead to wrong choices.
  • Clear descriptions. Say what the tool does, when to use it and what it returns.
  • Small, relevant results. Return the fields the model needs, not the full API response. Large results fill the context window and lower accuracy.
  • Useful errors. “Order not found; check the number format, e.g. 4512” lets the model recover; a stack trace does not.
  • Safe defaults. Read operations by default; write operations separate and clearly named.

Function Calling and MCP

Function calling is defined per vendor API. The Model Context Protocol (MCP) standardises how tools are described and served, so one tool server works with many AI applications and model vendors. The MCP specification defines tools as functions for the model to execute (MCP specification), so the host application presents them to the model through the same function calling mechanism.

Risks and Failure Modes

  • Wrong tool or wrong arguments. The model picks a plausible but incorrect tool, or fills an ID from a similar-looking record.
  • Invented tools or parameters, mostly in setups without strict schemas.
  • Excessive permissions. A tool that runs with an administrator account gives the model, and anyone who manipulates it, administrator power.
  • Prompt injection through tool results. A web page or email returned by a tool can contain instructions the model then follows.
  • Loops. An agent calls the same failing tool repeatedly, adding cost and delay.
  • Unconfirmed side effects. The model reports “email sent” when the call failed, because the error was not passed back clearly.

Function calling is the building block of AI agents, agent orchestration and text-to-SQL assistants, where the “tool” is a database query. AI guardrails decide which calls are allowed and which need approval, and LLM evaluation checks tool choice and arguments on real tasks.

Function Calling in Practice

Every tool is built as a small API with its own tests. The model proposes a call; application code checks the arguments against the schema and the business rules, runs the function with the signed-in user’s credentials, and returns either a short result or an error message the model can act on. Tool descriptions are written and reviewed as carefully as the code behind them, because a vague description is the most common reason a model picks the wrong function or fills an argument with a guess. See a text-to-SQL reporting assistant built this way.

Back to Glossary

Let's talk about your project

We'll help you harness AI and ML technologies to create innovative software solutions

File requirements: pdf, doc, docx, rtf, ppt, pptx — max 15 MB

No file selected