AI Workspace Loading

We’re preparing your intelligent learning experience. Our AI systems are processing content, optimizing resources, and setting everything up for you.

Preparing Learning Paths...
AI Processing
Smart Automation
Learning Engine
Good things take a moment.

LearnLess.ai

LEARN LESS. UNDERSTAND MORE.
Intermediate7 min read

Function Calling

Function calling lets a model request that a specific function be executed with structured arguments it generates — the application runs the function, not the model.

What Is Function Calling?

A language model can't directly look up today's weather, query a database, or send an email — it only generates text. Function calling is the pattern that closes that gap: you describe a function to the model (its name, purpose, and expected arguments), and when the model decides that function is needed, it generates a structured request to call it with specific arguments.

User

Asks a Question

Something the model can't answer from text alone.

asks

Model

Decides to Call

Recognizes a described function is needed.

generates

Function Call

Structured Request

Generated with specific arguments, not executed by the model.

sent to

Application

Actually Executes

Runs the function — the model never does.

executes, returns

Function Result

Real Data

The weather, a database row, an email's status.

read by

Model

Reads Result

Incorporates the result into its answer.

produces

Response

Grounded Answer

Now backed by real, current information.

Important

The model does not execute the function. It only generates a structured request — the application or runtime is what actually runs the function and returns the result back to the model.

The Pieces

Tool Schema
A description of a function's name, purpose, and expected input format, given to the model so it knows how — and when — to call it.
Tool Input
The structured arguments the model generates to call a function, matching the schema it was given.
Tool Result
The output returned from executing the function, which is sent back to the model so it can continue generating a response.

Code Example

A schema and the resulting execution flow — illustrative pseudocode, not a specific provider’s SDK:

function_calling_example.py
tool_schema = {
    "name": "get_weather",
    "description": "Get current weather for a city",
    "parameters": {"city": "string"},
}

response = llm.generate(prompt=user_message, tools=[tool_schema])

if response.tool_call:
    # The application executes the function — not the model
    result = get_weather(**response.tool_call.arguments)
    final_response = llm.generate(
        prompt=user_message,
        tool_result=result,
    )

Common Mistakes

  • Assuming the model runs the function itself

    The model only produces a request to call a function with specific arguments — your application is responsible for actually executing it.

  • Trusting model-generated arguments without validation

    Arguments come from a language model, not a trusted user form — validate them before executing anything with real side effects.

  • Vague function descriptions

    A poorly described function, or one whose purpose overlaps with another, makes it harder for the model to choose correctly and reliably.

Interview Question

What is function calling, and who actually executes the function?

Function calling lets you describe a function's name, purpose, and expected arguments to a model. When the model determines the function is relevant to the user's request, it generates a structured call with specific argument values — but it doesn't execute anything. The application or runtime receives that request, runs the actual function, and sends the result back to the model so it can incorporate it into its final response. It's what lets a model take real actions or fetch live information despite only being able to generate text.

What an interviewer may ask next

  • What happens if the model generates arguments that don’t match the expected format?
  • Why should you validate arguments before executing a function?
  • How is function calling different from tool calling more broadly?

Explain It in 30 Seconds

Function calling lets a model request that a specific function be executed, by generating structured arguments that match a schema you gave it. The model never runs the function itself — your application executes it and returns the result, which the model then uses to continue its response. It's the mechanism that lets a text-only model trigger real actions, like looking up live data or calling an API.

On this page