Skip to content
Tools and function calling

02.01 · Concept · Free

Function calling, concretely

Expose a function to a model and handle the call it makes.

The player loads only when you ask for it, so this page stays fast.

Curated for this lesson1/3

Tools and function calling

Build Hour: Agentic Tool Calling

Official OpenAI session on tool calling, appropriate for understanding the modern agentic framing.

Also worth watching

Function calling is a controlled handoff where a model returns a structured request for your application to execute. You define the callable interface, validate the model’s arguments, run the real code yourself, then pass the result back so the model can answer using production code paths.

What this lesson answers

  • how does function calling work with language models
  • does the model execute my function directly
  • how should I validate model tool call arguments

Notes

Function calling means giving a language model a small menu of functions it is allowed to request, including each function’s name, purpose, and expected arguments. The model does not actually run your code. It reads the user request, decides whether one of the available functions would help, and returns a structured request such as “call get_weather with city = London.” Your application receives that request, runs the real function, and sends the result back to the model so it can produce the final answer.

A good mental model is a dispatcher sitting between the model and your codebase. You describe a callable interface to the model, usually with a JSON schema for the arguments. The model fills in the arguments; your program validates them, executes the function, handles errors, and decides what to do with the result. This is very similar to receiving an HTTP request: parse, validate, authorize, execute, and return a response. The difference is that the first request was drafted by a model rather than a human or another service.

The common misconception is that function calling gives the model direct access to your tools. It does not. The model is only proposing a function call in a structured format. Your application remains responsible for deciding which functions are exposed, checking arguments, preventing unsafe actions, managing credentials, retrying failures, and logging what happened. Treat model-produced arguments as untrusted input, not as commands from a trusted component.

After this lesson, you should be able to define a simple function, describe it to a model with a name and argument schema, detect when the model asks to call it, run the function yourself, and pass the output back into the conversation. You should also understand why schemas matter: they turn vague natural-language intent into data your program can inspect, validate, and route through normal production code paths.

Common questions

What is function calling in an AI application?
Function calling lets a model choose from functions you have described and return a structured request for one of them. The request includes the function name and arguments. Your application receives that request, validates it, executes the actual code, and returns the output to the model.
Does function calling give the model access to my codebase?
No. The model only produces a proposed call in a format your program can read. It cannot run your code unless your application decides to execute that request. You still control which functions are exposed, how inputs are checked, and whether the action is allowed.
Why use schemas for function call arguments?
Schemas make the model’s requested arguments predictable enough for normal application handling. Instead of parsing vague text, your code receives structured data it can inspect, validate, reject, or route. This is what makes tool use safer and easier to integrate with existing services.