Skip to main content

Function Calling

Function Calling allows an AI model to request external software tools or APIs to perform actions and retrieve live information instead of relying only on its trained knowledge.

Intermediate5 min readv1.0Updated Jul 2, 2026
AI-assisted content β€” reviewed by the author, but verify important details independently

Visual SummaryClick to explore

Learning Objectives

  • Explain what Function Calling is.
  • Understand why LLMs need external tools.
  • Describe the complete Function Calling workflow.
  • Understand how AI interacts with APIs.
  • Recognize real-world Function Calling applications.
  • Differentiate prompting from Function Calling.

Why This Matters

Large Language Models are excellent at reasoning. But they cannot naturally send emails, book meetings, query databases, check today's weather, create Jira tickets, read your calendar or process payments.

Without external tools, an LLM can only generate text.

Function Calling connects AI to real software, allowing it to perform useful work.


The Problem

Imagine asking: "Schedule a meeting with my team next Tuesday at 10 AM."

Without Function Calling the AI might respond: "You could create a calendar event." Helpful, but nothing actually happens.

With Function Calling: AI β†’ Calendar API β†’ Meeting Created β†’ Confirmation Returned.

The AI becomes capable of taking action instead of only giving advice.


Everyday Analogy

Imagine a restaurant waiter.

The waiter does not cook the food. Instead, they receive your order, send it to the kitchen, wait for the result and deliver the finished meal.

The waiter coordinates the work. Similarly, an LLM coordinates external tools. It decides which function should be called but does not execute the underlying business logic itself.


What Is a Function?

A function is a reusable piece of software that performs a specific task.

Examples include get weather, send email, search database, create invoice, book appointment, calculate tax, translate text and generate PDF.

Each function accepts input and returns output.


The Function Calling Workflow

User Request β†’ LLM Understands Intent β†’ Select Appropriate Function β†’ Generate Function Arguments β†’ Application Executes Function β†’ Function Returns Result β†’ LLM Creates Final Response.

The LLM does not directly execute the function. Instead, it requests that the application execute it.


Example 1 β€” Weather

User: "What is the weather in Amsterdam today?"

LLM selects get_weather() β†’ Application calls Weather API β†’ Temperature returned β†’ LLM writes: "It is currently 22Β°C with light rain."

Without Function Calling, the model might rely on outdated knowledge.


Example 2 β€” Calendar

User: "Book a meeting tomorrow at 2 PM."

LLM calls create_calendar_event() β†’ Calendar Service β†’ Meeting Created β†’ LLM: "Your meeting has been scheduled."


Example 3 β€” Database

User: "Show my five latest orders."

LLM calls get_recent_orders() β†’ Database β†’ Results Returned β†’ LLM summarizes the information.


Functions vs Prompts

Prompt: Produces text. Example: "Explain machine learning." β†’ Response.

Function Calling: Performs actions. Example: "Create a Jira ticket." β†’ Function β†’ Jira API β†’ Ticket Created.


Function Parameters

Functions require structured inputs.

Example: create_calendar_event() parameters include Title, Date, Time, Participants, Duration and Location.

The LLM automatically extracts these values from natural language.


APIs and Function Calling

Many functions communicate with APIs such as Calendar API, Email API, GitHub API, Jira API, Slack API, CRM API, Payment API and Weather API.

The AI decides which API should be used. The application performs the secure communication.


Safety and Validation

Applications should never execute every function automatically.

Best practices include validating parameters, requiring user approval for important actions, limiting available functions, authenticating users, logging all requests and handling errors gracefully.

This keeps AI systems reliable and secure.


Function Calling in AI Agents

Function Calling is one of the core abilities of modern AI Agents.

An agent may: Plan β†’ Search β†’ Retrieve Documents β†’ Read Calendar β†’ Create Meeting β†’ Send Email β†’ Generate Report β†’ Finish.

Each action is usually performed through one or more functions.


Real-World Applications

Customer Support: Create support tickets.

Project Management: Create Jira stories.

Finance: Generate invoices.

Healthcare: Retrieve patient records.

HR: Book interviews.

Sales: Update CRM records.

IT Operations: Restart services.

Travel: Book hotels and flights.


Benefits

Function Calling enables AI to perform actions, access live information, integrate with business systems, automate workflows, reduce manual work and improve accuracy.


Limitations

Function Calling depends on available APIs, correct permissions, secure implementation and reliable software services.

The LLM cannot call functions that have not been provided by the application.


Common Misconceptions

The LLM does not directly control external systems. It suggests which function should be executed.

Your application remains responsible for authentication, authorization, validation, execution and error handling.


Best Practices

Keep functions small and focused. Use descriptive names. Validate every input. Confirm high-impact actions. Return structured results. Log every function call.


Worked Example: The Full Round Trip

A weather assistant with one registered tool:

{"name": "get_weather", "parameters": {"city": "string", "unit": "C|F"}}

User: "Should I carry an umbrella in Chennai today?"

  1. Model output β€” not prose but a call: {"tool": "get_weather", "args": {"city": "Chennai", "unit": "C"}}
  2. Your code runs the real API β†’ {"temp": 31, "condition": "thunderstorms", "rain_prob": 0.85}
  3. Result is appended to the conversation; model is called again.
  4. Model output: "Yes, 85% chance of thunderstorms in Chennai today. Take the umbrella."

Two model calls, one tool execution, and the critical division of labor: the model only ever writes JSON; your code does the actual calling. The model cannot access anything you didn't wire up, which is precisely the security boundary (AI-027).

Try It Yourself

  1. Play the executor: tell a chatbot "You have a tool calculator(expression). When needed, output ONLY the call in JSON." Ask it "What is 847 Γ— 39?" β€” watch it emit the call. Reply with {"result": 33033} and watch it compose the answer. You just ran the protocol by hand.
  2. Break the schema: give it a tool with a required date field and ask a question with no date. Does it ask you, guess, or hallucinate a date? That behavior gap is what schema descriptions and prompt guards (AI-010) exist to close.

Common Mistakes

  • Vague parameter descriptions. The model fills fields exactly as well as the schema explains them; "date (YYYY-MM-DD, must be future)" beats "date".
  • Executing calls without validation. Treat model-generated arguments as untrusted user input: validate, sanitize, and authorize before running (AI-027).
  • No error path β€” when the API fails, return a structured error so the model can recover or apologize, instead of pretending success.
  • Registering fifty tools at once. Selection accuracy drops as the tool list grows; curate per task (AI-020).

Key Takeaways

  • Function Calling connects AI to software.
  • The LLM chooses functions based on user intent.
  • Applications execute functions securely.
  • APIs enable access to external systems.
  • Function Calling is a foundation of modern AI Agents.

Glossary

Function Calling
The capability where a model, instead of writing prose, outputs a structured request like {"tool": "get_weather", "args": {"city": "Chennai"}} for your application to execute. The critical division of labor: the model only ever writes JSON; your code does the actual calling.
Function
A reusable piece of software with defined inputs and outputs: get weather, send email, create invoice. Like the restaurant waiter, the LLM coordinates which function to call but never cooks the food itself.
Parameter
A named input a function requires, like Title, Date, and Participants for create_calendar_event(). The LLM extracts these values from natural language, and it fills fields exactly as well as the schema describes them: "date (YYYY-MM-DD, must be future)" beats "date".
Schema
The declared name, parameters, and descriptions of a tool the model can call. Vague schemas produce guessed or hallucinated arguments; registering fifty tools at once dilutes selection accuracy. (see AI-020)
API (Application Programming Interface)
The interface a function typically calls behind the scenes: Calendar API, Jira API, Payment API. The AI decides which to use; the application performs the secure communication.
Validation
Treating model-generated arguments as untrusted user input: validate, sanitize, and authorize before executing. Applications, never the model, remain responsible for authentication, authorization, and error handling. (see AI-027)
Round Trip
The full flow: user request β†’ model emits a call β†’ your code executes it β†’ result appended to the conversation β†’ model composes the final answer. Two model calls, one tool execution.
Error Path
Returning a structured error when an API fails so the model can recover or apologize, instead of observing a false "success" that sends the reasoning off a cliff.

References

Diagram

Loading diagram…

Knowledge Check

7 questions