Skip to content

Function Calling and Tool Use in LLM APIs

How language models call functions you define, how to implement the request-response loop, and best practices.

Editorial team 1 min read

Function calling (or tool use) lets a language model request that your code run a function, such as looking up an order or checking the weather.

How It Works

  1. You describe available tools with names, descriptions and JSON Schema parameters.
  2. The model decides whether a tool would help and returns a structured tool call with arguments.
  3. Your code executes the function.
  4. You send the result back, and the model uses it to continue.

Best Practices

  • Write clear tool descriptions, including when to use each tool.
  • Use precise parameter schemas with enums and descriptions.
  • Validate arguments before executing.
  • Return concise, informative results and errors.
  • Require confirmation before actions with side effects.

Controlling Tool Use

APIs often let you let the model decide, force a specific tool, or disable tools.

Parallel Calls

Models may request several tool calls at once; execute them concurrently when independent.

Structured Output

Function calling is also a reliable way to get structured data, even if the "tool" just records the output.

Security

Treat tool arguments as untrusted input, and limit what tools can do.

More in Generative AI

All Generative AI guides →
Generative AI Guide · 2 min

Prompt Engineering Fundamentals

The building blocks of a good prompt — context, task, constraints and format — with before-and-after examples.

Generative AI 2 min read 24 Jul 2026

Generative AI Guide · 2 min

Few-Shot Prompting With Examples

Showing a model a few examples of the input and output you want is often clearer than describing it. How to choose good examples.

Generative AI 2 min read 23 Jul 2026

Generative AI Guide · 2 min

Getting Structured Output From LLMs

How to get JSON and other machine-readable output reliably from a language model, and how to validate it.

Generative AI 2 min read 22 Jul 2026

Generative AI Guide · 2 min

Why Language Models Hallucinate

What hallucination is, why it happens, and practical ways to reduce and catch it.

Generative AI 2 min read 21 Jul 2026