Lesson 08 of 13 · AI that takes action
Tools and function calling
A model can only produce text, but it can produce text that asks your software to do something: 'call get_weather with city = Pune'. Your software runs the tool and sends the result back. How a tool is described, the round trip step by step, why the application (not the model) is in control, and how to decide what a model may do on its own.
Text in, text out, and yet it acts
A language model only outputs tokens. It cannot open a website, run a query or send an email. Tool use (also called function calling) is a convention: the application tells the model which tools exist, and the model can reply with a structured request to use one instead of a normal answer.
The round trip
1. App → model: question + tool definitions
"What's the status of order 1042?"
tools: get_order(order_id: string) — "Look up an order's status and ETA"
2. Model → app: a tool call, not an answer
{ "tool": "get_order", "input": { "order_id": "1042" } }
3. App runs it: checks permissions, calls the order system
→ { "status": "shipped", "eta": "2026-11-10" }
4. App → model: the tool result
5. Model → app: the final answer
"Order 1042 has shipped and should arrive on 10 November."
Steps 2–4 can repeat: the model may call several tools, one after another, before answering.
The model is like a manager on the phone who can't leave the desk. They can say "Please check the order system for 1042" but someone else (the application) actually walks over, checks, and reads back the answer. That someone also decides which requests they're allowed to carry out.
How a tool is described
name: get_order
description: Look up the current status and delivery estimate of ONE order
by its number. Use when the user asks where an order is.
input: order_id (string, required): the order number, digits only
The model has nothing but this to go on, so good descriptions say when to use it, what each input means, and what it returns. Vague or overlapping tools are a common source of wrong calls.
Structured output
The same idea is used without tools to get data in a fixed shape: "Return JSON with fields category, priority and summary". Many model APIs can enforce a schema, so the result can be passed straight to other software. Still validate it; never trust it blindly.
Who is in control
The application is always in control, which is where safety belongs:
- It decides which tools exist for this user and this conversation.
- It checks every call (is this user allowed to see order 1042?) before running it.
- It can ask a person before risky calls.
- It logs calls and results.
The model can be tricked (lesson 12), so any rule that matters must be enforced in the application, not just written in the prompt.
Deciding what may run automatically
| Kind of tool | Examples | Typical policy |
|---|---|---|
| Read-only, low sensitivity | search docs, get weather, list open tickets | Automatic |
| Read-only, sensitive | read HR records, customer data | Automatic only for authorised users, filtered |
| Reversible write | create draft, add label, open a ticket | Automatic with logging, or confirm |
| Irreversible or outside-facing | send email, pay, delete, deploy, change permissions | Human approval every time |
Recap
- With tool use, the model writes a structured request; the application runs the tool and returns the result.
- Clear names and descriptions are what make the model call the right tool correctly.
- Structured output gives machine-readable answers; validate them.
- Put permissions, approvals and logging in the application, never only in the prompt.
This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.