What is function calling in LLM applications?

From User Request to Function Call
Title: From User Request to Function Call
Source: AIML.com Research

Introduction

Large language models are good at interpreting natural language and generating text, but many useful tasks require something outside the model itself. A model cannot know the current weather from its parameters, query a private customer database, or update a calendar simply by generating a sentence.

Function calling, also commonly called tool calling, provides a structured interface between an LLM and external software. Instead of asking the model to perform an external action directly, an application gives it descriptions of available functions. The model can then decide which function is appropriate and generate the structured arguments needed to call it. The surrounding application, not the LLM, executes the function. (Ref: Function Calling by OpenAI)

This distinction is the key idea behind function calling:

The model chooses and describes an action, the application performs it.

From natural language to a function call

Suppose a user tells an assistant: “What’s the weather in Boston?”

The application might provide the model with a function such as:

JSON
{

  "name": "get_weather",

  "description": "Get the current weather for a location",

  "parameters": {

    "location": "string",

    "unit": "celsius | fahrenheit"

  }

}

The model receives both the user’s request and the available function definition. Rather than answering from its training data, it can determine that get_weather is relevant and produce something conceptually like:

JSON
{

  "name": "get_weather",

  "arguments": {

    "location": "Boston",

    "unit": "fahrenheit"

  }

}

This output is not the weather result, and the model has not contacted a weather service. It has generated a structured request telling the application what it wants to call.

The application can validate those arguments, execute the corresponding weather API, and return the result to the model. The model can then turn that result into a natural-language response for the user.(Ref: Function Calling with the Gemini API by Google AI for Developers)

Function Calling Flow Between an Application and an LLM
Title: Function Calling Flow Between an Application and an LLM
Source: Function Calling with the Gemini API

How does the model choose a function?

The model is not typically choosing from arbitrary code. Developers expose a specific set of available tools, each described using a function name, a description of what it does, and a schema specifying its accepted parameters. Clear descriptions help the model associate a user’s intent with the appropriate tool.

For example, an application might expose:

  • get_weather(location)
  • search_products(query, max_price)
  • create_calendar_event(title, date, time)

If the user asks, “Find headphones under $200,” the model can match the request to search_products and extract the relevant arguments. If the user instead asks a general question that requires no external information or action, it may simply produce a normal text response.

Applications can also constrain this choice. Depending on the API, developers may allow the model to decide automatically, require it to use a tool, restrict it to particular tools, or prevent tool use entirely. (Ref: Function Calling by OpenAI)

Why structured arguments matter

Without function calling, developers might prompt an LLM to write something like:

“Search for headphones with a maximum price of 200 dollars.”

Software would then have to interpret this free-form text before it could reliably call an API.

Function calling replaces that ambiguous handoff with structured data:

JSON
{

  "query": "headphones",

  "max_price": 200

}

Because the output follows a predefined schema, the application knows which values correspond to which parameters. Modern APIs can further constrain outputs to conform to a supplied JSON schema. For example, OpenAI’s Structured Outputs can enforce schema adherence for supported function definitions. (Ref: Structured Model Outputs by OpenAI)

Structured output therefore creates a much cleaner interface between the probabilistic world of language models and conventional software, which expects predictable inputs.

Function calling does not give the model direct control

It is easy to describe an LLM as “calling an API,” but that wording can hide an important architectural boundary.

In the standard function-calling pattern, the LLM generates a request to use a function. The host application receives that request and decides what happens next. Google’s function-calling documentation explicitly separates model-generated function calls from execution, which remains the application’s responsibility. (Ref: Function Calling with the Gemini API by Google AI for Developers)

That separation also gives developers a control point. Before executing a requested action, an application can validate parameters, check permissions, require user confirmation, reject unsafe operations, or log the request.

Why tool access requires safeguards

Function calling can connect a model to systems that read data or perform real actions, so applications need to control what happens after a function call is generated. A model might select the wrong tool, produce incorrect arguments, or act on instructions contained in untrusted external content. These risks become more consequential when tools can modify files, send messages, access private data, or execute code.

For this reason, applications should treat a model-generated function call as a request rather than an automatically trusted command. Developers can restrict which tools are available, validate arguments, enforce permissions, and require user confirmation before sensitive actions are executed.

Function calling is therefore less like giving an LLM direct access to external systems and more like giving it a structured language for requesting capabilities.

That interface is what allows an LLM application to move beyond generating text: the model interprets intent and proposes structured actions, while ordinary software provides the mechanism that actually carries them out.

Videos

  • This video “AI + your code: Function Calling” from Google Cloud Tech gives an intuitive introduction to function calling and shows how an LLM can select a function, generate the required arguments, and pass the request back to application code for execution. It directly reinforces the article’s central distinction between model-generated function calls and application-side execution. (Runtime: 8 mins)
YouTube video
AI + your code: Function Calling by Google Cloud Tech on Youtube
  • This practical walkthrough shows function calling in a real application using Gemini and a weather API. The 1:12–2:06 section gives a focused explanation of what function calling is and is the most relevant segment for this article; the rest of the video moves into implementation and deployment details. (Runtime: 11 mins)
YouTube video
How to use Gemini function calling with Cloud Run by Google Cloud Tech on Youtube

References

Author

Help us improve this post by suggesting in comments below:

– modifications to the text, and infographics
– video resources that offer clear explanations for this question
– code snippets and case studies relevant to this concept
– online blogs, and research publications that are a “must read” on this topic

Leave the first comment

Partner Ad