Lesson · ⏱ 8 min read

🧰 Tool use (function calling): letting an LLM take actions

EnglishHinglish

🏠 Real-life example

A smart receptionist can't see the doctor's calendar herself, but she can call the calendar system: 'Is Dr. Mehta free at 4 pm?' She uses the answer to reply to you. Tool use gives an LLM the same ability. It can't fetch live data by itself, but it can ask your code to run a function and then use the result.

💡 In simple words

You describe tools to the model: a name, what each does, and its input parameters as a JSON schema. When a question needs a tool, the model replies with a tool call ('get_order_status', order_id='A123') instead of text. Your code runs the real function and sends the result back, and the model writes the final answer using it. This is how chatbots check orders, book tickets or query databases. Your code stays in control: validate inputs, check permissions, and require human approval for risky actions like refunds.

🎬 See how it works

UserLLMYour codeOrders APIWhere is order A123?tool_call get_order_status(A123)GET /orders/A123out for delivery · 7:40 pmtool resultArriving by 7:40 pm 🛵

The model never calls the API itself. It asks your code to, your code runs it, and the model writes the answer from the result.

🪜 Step by step

  1. Write a normal function, for example get_order_status(order_id).
  2. Describe it to the model: name, what it does, and a JSON schema of its parameters.
  3. When the user asks "where is order 4512?", the model replies with a tool call: get_order_status with order_id 4512.
  4. Your code validates the arguments, checks permissions, runs the function and sends the result back.
  5. The model uses the result to answer the user, or calls another tool if needed.

🔑 Key terms

Tool / function
An action your code exposes to the model, like search or a calculator.
JSON schema
A description of a tool's inputs and their types.
Human-in-the-loop
A person approves important actions before they happen.

👀 See it in action

text
User:   "Where is my order A123?"
Model → tool_call: get_order_status(order_id="A123")
Your code runs it → {"status": "out for delivery", "eta": "7:40 pm"}
Model:  "Your order is out for delivery and should arrive by 7:40 pm 🛵"

The model decides when to use a tool. Your code does the real work.

⚠️ Common mistakes to avoid

  • Trusting arguments blindly. The model can invent an order ID or a wrong amount; validate everything.
  • Giving powerful tools without limits, like delete or refund with no confirmation step.
  • Too many similar tools with vague descriptions. The model picks the wrong one; keep tools few and clearly described.

✅ Quick check

Who actually executes a tool call?

  1. Your application code
  2. The user
  3. The LLM itself, inside the model
Show answer

A. Your application code: The model only requests the call. Your code runs it, so you control permissions and safety.

🙋 Questions learners ask

Does the model run my code?

No. It only says which tool to call with which arguments. Your application runs it and decides whether to allow it.

Can it call several tools at once?

Many models support parallel tool calls, for example checking stock in three warehouses at once. Your code runs them and returns all results.

📌 Remember

The model asks, your code acts. Validate everything.

📖 Words from this lesson (AI dictionary)

Learn this as part of a full course

Track your progress, take the quick checks and follow the lessons in the right order. This lesson is part of:

AI Product Engineer · LLM / Agent Engineer · AI Forward Deployed Engineer

Continue in the course