Skip to content

Command Palette

Search for a command to run...

← All concepts
Concept

Tool Calling

The mechanism by which an LLM decides to invoke a function you've defined.

Simple explanation

You give the LLM a list of tools (functions with names, descriptions and parameter schemas). The LLM decides which tool to call and with what arguments. Your code executes it. This is how agents act.

Engineering explanation

Tool calling uses the model's native function-calling API. You provide tool definitions as JSON schemas; the model returns a structured tool_call with name + arguments. Production tool calling requires: Pydantic schema validation, per-tool timeout, structured error return (not exceptions), tool-output sanitisation (injection defence), and audit logging of every call.

Example

Tool: get_weather(city: str, units: str). Model returns: get_weather(city='Tokyo', units='metric'). Your code executes and returns {temp: 18}.

When to use it

Whenever the LLM needs to access external data or take actions. The foundation of all agents.

Common misconception

Tool output is NOT trusted. It can contain prompt injection (especially if the tool fetches external data). Always sanitise and delimit tool output.