Tool calling explained: how an LLM uses your functions
Tool calling, also called function calling, is how a language model asks your program to run a function for it. The model does not execute anything. It returns a structured request with a tool name and JSON arguments. Your code runs the function and sends the result back.
The four steps
- You describe the tools: a name, a plain description, and a JSON Schema for the arguments.
- The model decides. It either answers directly or returns a tool request.
- Your code runs the tool, after checking the name and the arguments.
- You send the result back and the model writes its answer, or asks for another tool.
Repeat steps 2 to 4 in a loop and you have an agent.
What it looks like
import json
TOOLS = [{
"name": "get_order_status",
"description": "Look up one order by its id, for example A-1042.",
"input_schema": {"type": "object", "properties": {"order_id": {"type": "string"}}, "required": ["order_id"]},
}]
def get_order_status(order_id: str) -> str:
return {"A-1042": "shipped"}.get(order_id, "not found")
# What the model sends back when it wants the tool. It never runs anything itself.
model_reply = {"type": "tool_use", "id": "toolu_1", "name": "get_order_status", "input": {"order_id": "A-1042"}}
result = {"get_order_status": get_order_status}[model_reply["name"]](**model_reply["input"])
tool_result = {"type": "tool_result", "tool_use_id": model_reply["id"], "content": result}
print(json.dumps(tool_result))
It prints {"type": "tool_result", "tool_use_id": "toolu_1", "content": "shipped"}. The field names here follow the Anthropic Messages API.1 Other providers use different names for the same four steps.
Writing a good tool
- The description is a prompt. Say what the tool does, when to use it and what it returns. Most wrong tool choices are description problems.
- Few parameters, clear names.
order_id, notid. - Return small, useful results. The result goes into the model’s context and you pay for it.
- Return errors as results. “No order with that id” lets the model recover. An exception ends the run.
What can go wrong
| Failure | Defence |
|---|---|
| Wrong argument types or missing fields | Validate against the schema before running |
| A tool that does not exist | Look the name up in a fixed table, as above |
| Endless loops | A step limit |
| A harmful action requested by injected text | Least privilege, and human approval for anything that sends, pays or deletes |
The last row is prompt injection. Tools are what make it dangerous.
Tool calling and MCP
Tool calling is the mechanism between your code and one model. MCP is a standard way to package tools so that many applications can use the same ones.
Tool calling by hand is Week 2 of the Zero to FDE roadmap, and the full agent loop is the free Week 4 lesson.
Zero to FDE is a self-paced 16-week course, ₹2,999 once, with a 7-day full refund. Week 1 is free, and one Week 4 lesson is free if you already write backend code. It has no live classes, no mentors and no accredited certificate.
Sources
Zero to FDE is a 16-week path, for working engineers and AIML graduates, to the work Forward Deployed Engineers do: backend basics, LLMs, RAG, agents, evaluation and deployment, with a shipped deliverable every week. Week 1 is free and complete, no card needed.
Start Week 1 freeMore from the blog
- Forward Deployed Engineer jobs in 2026: what the data says
- What is RAG? Retrieval-augmented generation, explained with working code
- What is an AI agent? The agent loop, explained with code
- AI engineer roadmap 2026: what to learn, and in what order
- Will AI replace software engineers? What the data says in 2026
- Forward Deployed Engineer courses in India (2026): fees, format and how they compare
- Forward Deployed Engineer vs ML engineer: which AI role fits you?
- Forward Deployed Engineer salary in India: what the 2026 data says for 2027
- Forward Deployed Engineer interview questions: the six rounds and how to answer
- Why Forward Deployed Engineer is a smart next move for a software engineer
- Forward Deployed Engineer certification in 2026: what exists, what it costs, and what employers check
- Forward Deployed Engineer skills: what 1,000 job posts ask for
- Forward Deployed Engineer vs Solutions Engineer: the real difference
- Forward Deployed Engineer resume: what to put on one page
- Forward Deployed Software Engineer (FDSE): what the Palantir title means
- Forward deployed AI engineer, AI deployment engineer, FDE: the titles explained
- Prompt injection explained: what it is and how to defend against it
- Context engineering explained: beyond prompt engineering
- RAG vs fine-tuning: which one to use, and when
- LLM evals explained: how to test a system that gives different answers
- LLM observability explained: traces, cost and what to log
- What is MCP? The Model Context Protocol explained
- AI agent vs workflow: which one does your problem need?
- AI engineer vs ML engineer: what each one does
- AI engineer interview questions: 25 that test whether you have built anything
- What is a vector database? Explained with a 30-line example
- EY now hires Forward Deployed Engineers for audit. The role is leaving the AI labs
- LangGraph explained: state, nodes and edges, with a 30-line example
- Randstad: 90% of Indian employers are growing tech teams for AI. What it means for engineers
- AI agent memory explained: short-term vs long-term, with a tested example
- LLM cost optimization: prompt caching, batching and model routing, with the numbers
- Structured outputs from an LLM: JSON schema, validation and retries
- Embeddings explained: vectors, cosine similarity and dimensions
- Data engineer to AI engineer: what carries over and what to learn
- AWS launches a Forward Deployed Engineering Competency, with Infosys, TCS and Coforge among 22 launch partners
- Forward Deployed Architect: what the role is, certifications and courses
- Persistent launches a Forward Deployed Engineering program with Microsoft, a day after NIIT's FDE talent blueprint
- How to become an AI engineer in India: the route depends on where you start
- Self-paced Forward Deployed Engineer courses in India under ₹10,000 (and under ₹3,000)
- AWS and OpenAI will jointly staff forward deployed engineering teams inside customer environments
- Backend developer to AI engineer: what carries over and what to learn
- Claude now runs on premises in customers' own data centers through AWS AI Factories
- Agentic AI courses compared: four free options, and what a course must make you build
- AWS: attacks on AI systems grew about 800% in 2026, and an AI agent broke into a decoy MCP server in 12.7 minutes