A8gent
GlossaryAgent concepts

What is function calling?

Also called: structured function output, OpenAI function calling

Function calling is the original provider name for tool calling: the model returns a structured JSON request naming one of your declared functions and its arguments, rather than free text.

Written by A8gent
Contents
  1. At a glance
  2. What function calling is
  3. How you declare and handle a function
  4. Cost, limits and structured output
  5. What you should know
  6. FAQ
  7. Related terms

At a glance

Category
Core agent concept
Introduced as
OpenAI function calling, mid-2023; now usually called tool use
Declaration
Name, description, JSON-schema parameters
Return
Structured JSON arguments, not prose
Cost
Declarations are input tokens on every request
Best practice
Enable strict or structured-output mode and validate before executing

What function calling is

Function calling is the feature that lets you declare functions to a model in a JSON schema and receive back a structured request to call one, complete with arguments, instead of prose you would have to parse. OpenAI shipped it under that name and the rest of the industry followed; most providers now describe the same capability as tool calling or tool use.

Its real contribution was not autonomy - it was reliability. Before function calling, getting structured data out of a model meant asking nicely for JSON and writing defensive parsers for the times it added a friendly preamble. Function calling made the structured path a first-class output type that the provider constrains, which is why it also gets used for pure extraction jobs where nothing is ever executed.

How you declare and handle a function

A declaration has three parts: a name, a description, and a parameter schema. The description is not decoration - it is the only thing the model reads to decide whether this function fits the situation, so write it the way you would brief a new employee: what it does, when to use it, and when not to. Ambiguous descriptions produce the classic failure where the model reaches for search_orders when it should have called get_order_by_id.

On the receiving side, treat the arguments as untrusted input, because they are generated text. Validate types, ranges and enums; check that the referenced record exists; and never interpolate an argument straight into a query or a shell command. The model is not adversarial, but anything it read along the way might have been - see prompt injection.

Cost, limits and structured output

Function declarations count as input tokens on every request, so a long function list is a fixed cost paid per step of every run. Providers cap the number of functions and the schema depth, and in practice accuracy degrades well before the cap does. Keep parameter schemas flat where you can; deeply nested objects are filled in wrong more often than they are filled in right.

Most providers also offer a strict or structured-output mode that guarantees the returned JSON matches your schema. Turn it on. It removes an entire class of parsing bugs at no extra cost, and it makes the failure mode "wrong value" rather than "unparseable", which is far easier to catch with validation.

What you should know

Function calling is per-provider plumbing. Every model family has its own wire format, so an agent written directly against one provider's function-calling API is coupled to that provider. Two things loosen that coupling: an agent framework that abstracts the format, and MCP, which moves the tool definitions out of your application into a server that any compatible client can use. Compare the two approaches on MCP vs function calling.

Also remember that function calling is not RAG. A function can fetch a document, but retrieval quality still depends on chunking, embeddings and reranking; wrapping a bad search in a function call makes it a fast bad search.

Function calling FAQ

Is function calling the same as tool calling?

Yes, in practice. Function calling was the original name for the mechanism; providers renamed it tool use once the menu grew to include hosted capabilities like web search alongside your own functions. If a doc says one and your framework says the other, they are describing the same request-and-result loop.

How do I write a good function description?

Write it for a competent new hire who cannot ask questions. Say what the function does, what it returns, when to use it, and explicitly when not to use it relative to your other functions. Most wrong-tool failures are description failures, not model failures - two functions whose descriptions overlap will be confused.

Can I use function calling just to get structured JSON?

Yes, and it is a very common use. Declare a function you never execute, whose parameters are the fields you want extracted, and read the arguments as your result. Provider structured-output or strict modes do the same job more directly and are usually the better choice for pure extraction.

How many functions can I declare?

Providers publish a hard cap, but accuracy falls off long before it. Beyond roughly a dozen, selection errors climb noticeably, especially where descriptions overlap. If you need a large surface, group the functions behind a smaller number of intent-shaped ones, or split the work across specialised agents.

Is function calling secure?

The mechanism is; your handler decides. Arguments are model-generated text and must be validated like any user input - never interpolate them into SQL, shell commands or file paths. Also assume any text a function returns could carry injected instructions if it came from email, a web page or a document.

Should I use function calling directly or use MCP?

Use function calling directly for one application with a handful of bespoke tools. Use MCP when several agents or clients need the same tools, or when you want a tool server maintained separately from the agent. MCP does not replace function calling - the client still surfaces MCP tools to the model as ordinary tool definitions.

Primary source

OpenAI - Function calling guide

Checked August 2026. Anything priced or rate-limited moves, so verify against the source before you budget.

Want this built rather than explained?

Knowing what function calling means is one thing; having it running in your business is another. We scope one workflow at a time, quote a fixed price in writing after a free consult, build it, and hand it over with documentation you own.