Course contentsShow
← Machine Learning and Deep Learning
Lesson 1921 of 3,53841. Structured Output and Tool CallingFree lesson

What is Function Calling in LLMs

Understanding how LLMs can invoke external tools and functions through structured API calls.

What is Function Calling in LLMs

What you'll learn: How large language models can intelligently invoke external tools and functions through structured API calls to extend their capabilities beyond pure text generation.

The Core Idea

Function calling (also called "tool use") enables LLMs to recognize when they need external help and generate structured requests to invoke specific functions with appropriate parameters. Instead of just describing what should happen ("You should check the weather in Paris"), the model outputs a formal function call like get_weather(city="Paris", units="celsius") that your application can execute.

Think of it like a smart assistant who doesn't just tell you "someone should look up that address" but actually picks up the phone, dials the right department, and asks the specific question in the exact format they need.

How It Works

You provide the LLM with:

  1. Function definitions: Descriptions of available tools, their parameters, and what they do
  2. User request: The actual task or question

The model then:

  • Determines if a function call is needed
  • Selects the appropriate function
  • Generates a structured output (typically JSON) with the function name and arguments
  • Your code executes the function and returns results
  • The model incorporates those results into its final response

Why This Matters

Function calling bridges the gap between LLMs' reasoning abilities and real-world actions. Models can now:

  • Query databases
  • Call APIs (weather, stock prices, search engines)
  • Perform calculations
  • Access current information beyond training data
  • Take actions in external systems

This builds directly on structured output techniques (JSON mode, schemas) you've already learned — but now the structure has executable meaning.

Key Takeaway: Function calling transforms LLMs from pure text generators into orchestrators that can reason about which tools to use and generate precise, structured API calls to extend their capabilities.