Function Calling in LLMs

Imagine you build an AI chatbot that can answer almost anything. You ask, “What’s the weather in Delhi?” and it gives you a nice answer. But there’s one problem – it doesn’t actually know the current weather.

This is where function calling comes in.

What is Function Calling?
Function calling allows an LLM to interact with your application’s functions, APIs, databases, or other tools.

Instead of the AI simply generating an answer, it can recognize:
“I need a tool for this.”

For example, if a user asks:
“What’s the weather in Delhi today?”

The model can decide to call a function like:
getWeather(city="Delhi")

Your application executes the function, gets the latest weather data, and sends the result back to the model. The model then turns that data into a natural response for the user.

Why Does It Matter?
Without function calling, an LLM is mostly limited to the information and capabilities available to it.

With function calling, your AI can:
Fetch real-time information from APIs
Search or update databases
Calculate values
Check product availability
Create bookings or appointments
Trigger actions inside your application
Connect with internal business systems

This makes the AI much more useful in real applications.

A Simple Example
Think about an e-commerce chatbot.

A customer asks:
“Do you have the blue shirt in size M?”

Instead of guessing, the AI can call:
checkInventory(product="blue shirt", size="M")

The backend checks the database and returns the actual stock status. The AI can then reply:
“Yes, the blue shirt is available in size M.”

The important part is that the LLM doesn’t directly access the database. Your application controls the function and decides what the model is allowed to do.

Final Take
Function calling is one of the key ideas behind building practical LLM applications. It connects the language understanding of an AI model with the actual capabilities of your software.

The result is simple: the LLM doesn’t just understand what the user wants—it can help your application do something about it.