esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

What Is Tool (Function) Calling?

How an AI model asks your code to run a function, why your code still makes the final call, explained simply for your AI interview.

In short

Tool calling is when an AI model asks your code to run a function, such as a refund lookup, by returning the function's name and its arguments. Your code (or the vendor, for hosted tools) does the work and sends the result back, so the model never runs anything itself.

11 min readBeginnerVery common · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

Tool calling lets a language model ask my code to run a function. I describe each tool with a name, what it does and the inputs it takes. When the model needs one, it replies with the tool name and the arguments it wants used. My code checks the request, runs the real function and sends the result back. So the limits live in my code.

What is tool calling, in plain words?

A language model writes text. On its own it can't check an order, look up a balance or send a message. Tool calling gives it a way to ask for those things, and your own code does them.

You describe each tool to the model with three parts: a name, a line saying what it does, and a JSON schema. JSON is a plain text format for structured data. A JSON schema is a formal list of the inputs a tool takes, with their names and types. For example, a transaction ID must be text and an amount must be a whole number. The model reads these descriptions with the customer's message and decides when a tool would help.

Think of a bank's support agent who can't open the core banking system. They fill in a request form, and a back-office team does the work after checking it. The form is the tool call. The back office is your code, and it can say no.

Key words

Tool call
The model's request to use a tool, with the tool's name and its arguments.
Tool result
What your code sends back after it runs the tool. The model reads it next.
JSON schema
A formal list of a tool's inputs, with their names and types.
Client tool
A tool your own application runs. The other kind is a server tool, which the vendor runs for you.

One open standard for connecting tools to AI apps is the Model Context Protocol (MCP). It is an open-source standard for connecting AI applications to external systems, so a tool built to the standard can be plugged into many apps.

How does the tool call loop work?

Tool calling is a back-and-forth between your application and the model. Each round follows the same five steps.

  1. 1

    Send the message and the tools

    Your app sends the customer's message, plus the description of every tool the model may use.

  2. 2

    The model asks for a tool

    It replies with the tool's name and the arguments as JSON. It runs nothing. The reply is a request your code can check before anything happens.

  3. 3

    Your code runs the tool

    It checks the arguments, calls the real payments system and gets a result or an error.

  4. 4

    Send the result back

    The result goes into the chat as a tool result, so the model can read it.

  5. 5

    The model writes the answer

    It turns the result into a reply for the customer, or asks for another tool if it needs one.

One request, two model calls

Customer's message

asks for a refund on a double charge

Model

decides a tool would help

Your application

Check the arguments

shape first, then business rules

Run the real tool

calls the payments system

Model reads result

turns the result into words

Reply to customer

refund queued, or handed to a human

  1. 1The customer's message goes to the model, with the list of tools.
  2. 2The model asks for issue_refund with its arguments. It runs nothing.
  3. 3Your code checks the request, then runs the real tool if it passes.
  4. 4The tool's result goes back into the chat for the model to read.
  5. 5The model writes the reply the customer reads.
For one tool call, the model is called twice. Between the two calls, your code checks the request, runs the real tool and sends back the result. The numbers mark the steps in order.

Worked example. A mid-size bank's support assistant gets this message: "I was charged twice for order TXN-88412. Please refund the second charge." The model asks for the transaction first. Your code finds that the customer paid 4,200 and returns it. The model then asks for a refund of 4,200. That is within the paid amount and the bot's cap of 5,000, so your code queues it. That is two tool calls, so the model runs three times: to ask for the lookup, to ask for the refund, and to write the reply. If the model had asked for 9,000, your code would stop it, whatever the model wrote.

Who decides whether a tool call is allowed?

The model only asks, and your code decides. Both vendors put the model in the same role. Anthropic says Claude calls a tool based on the request and the tool's description, and then returns a structured call for your application to run.

  • The model

    Asks

    It picks the tool and writes the arguments. It can get them wrong, or be steered by text it read.

  • Your code

    Decides

    It checks the shape (the types and required fields), then the rules, and runs the call only if both pass.

  • “It then returns a structured call that your application runs (client tools) or that Anthropic runs (server tools)”

    Anthropic, tool use docs

  • “Setting strict to true will ensure function calls reliably adhere to the function schema, instead of being best effort”

    OpenAI, function calling guide

  • “For trust & safety and security, there SHOULD always be a human in the loop with the ability to deny tool invocations”

    MCP specification, tools

Strict settings close one gap. OpenAI and Anthropic both offer a strict mode that makes the arguments match your schema. Without it, a model might send the amount as text or leave out a required field. Strict mode fixes the shape only. A refund of 9,000 is a valid number, so it passes the shape check, and a business rule in your code still has to stop it.

So validate in two places: the shape (types and required fields), and the rules (is this customer allowed this amount, and is this action allowed at all). Keep both checks in your code, since a prompt is only a request to the model.

Tip

In the interview, say it this way: the model proposes, your code decides, and a person approves anything risky.

Here is a small dispatcher for that refund bot. The model's requests are written as plain Python data, so the code runs with no network and no model.

Python
# A simplified refund bot. The code that runs the model's requests, with no real model.
TRANSACTIONS = {"TXN-88412": {"customer": "C-1907", "paid": 4200}}
BOT_LIMIT = 5000
SCHEMAS = {
    "lookup_transaction": {"transaction_id": str},
    "issue_refund": {"transaction_id": str, "amount": int},
}

def run_tool(name, args):
    if name not in SCHEMAS:
        return "BLOCKED: unknown tool " + name
    for field, kind in SCHEMAS[name].items():
        # The shape check (strict mode does this for you at the vendor).
        if not isinstance(args.get(field), kind):
            return "ERROR: " + field + " must be " + kind.__name__
    txn = TRANSACTIONS.get(args["transaction_id"])
    if txn is None:
        return "ERROR: no such transaction"
    if name == "lookup_transaction":
        return "OK: paid " + str(txn["paid"]) + " for " + txn["customer"]
    # The business rule: the code decides, never the model.
    if args["amount"] > min(txn["paid"], BOT_LIMIT):
        return "BLOCKED: above the paid amount or bot cap, send to a human agent"
    return "OK: refund of " + str(args["amount"]) + " queued"

print(run_tool("lookup_transaction", {"transaction_id": "TXN-88412"}))
print(run_tool("issue_refund", {"transaction_id": "TXN-88412", "amount": 4200}))
print(run_tool("issue_refund", {"transaction_id": "TXN-88412", "amount": "4200"}))
print(run_tool("issue_refund", {"transaction_id": "TXN-88412", "amount": 9000}))

Output

OK: paid 4200 for C-1907
OK: refund of 4200 queued
ERROR: amount must be int
BLOCKED: above the paid amount or bot cap, send to a human agent

Lines 14 and 15 are the shape check. Lines 22 and 23 are the rule that matters most. The third call fails the shape check. The fourth passes the shape check but is blocked, because a valid number can still be the wrong refund.

What does the interviewer want to hear?

A strong answer covers

  • A plain definition: the model asks, and your code runs the function.
  • The loop: request, tool call, tool result, final answer.
  • Each tool has a name, a clear description and a JSON schema.
  • Strict mode fixes the shape, and your code checks the rules.
  • Limits and a human for risky actions, such as big refunds.
  • Where the business rules live, and why a prompt cannot enforce them.

Common traps

  • Trap"The model runs the tool itself."

    BetterIt only asks. Your application runs it, or the vendor does for hosted tools, so that is where you check and block.

  • Trap"Strict mode makes the call safe."

    BetterStrict mode checks the shape. Your code still has to check whether the call is allowed.

  • Trap"More tools make the bot smarter."

    BetterMore tools give the model more choices to get wrong. Give each job only the tools it needs.

Can you spot the problem?

Spot the risk

A refund bot's code receives a tool call from the model. Which code is the biggest risk?

Quick check

Where should the rule 'no refund above the amount paid' live?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q157What is an AI agent?11 min
  2. Q164What is the Model Context Protocol (MCP)?12 min
  3. Q175What makes a tool-calling loop reliable enough to ship?13 min
  4. Q177What makes a good tool set?13 min
  5. Q178What is parallel tool calling?Coming soon
  6. Q179Excessive agency and least privilege?11 min

Learn it in depth

Last updated on 26 November 2026

Building a bot that calls your own systems?

I design and build AI agents and the tools they call, including the checks around each call. Book a short call and tell me which systems yours would touch.