What is tool calling?
Tool calling is the mechanism by which a language model proposes calling a defined tool or function by name and parameters, while the application runs the tool and returns the result to the model.
It differs from Model Context Protocol in level: tool calling is how a model uses a tool, while MCP is the protocol defining how tools and data sources are offered to applications in a standard way. The model does not run the tool itself; the application layer validates and executes the call.
- Topic
- Agents and protocols
- Also known as
- Function calling, tool use
How tool calling works
- The application gives the model each available tool's name, description and parameter schema (tool definition).
- If the model decides a tool is needed, it produces a structured call with the chosen tool and parameters.
- The application validates the call against the schema, checks user permissions and runs the API or function.
- The result goes back to the model, which completes the answer or makes another call (agent loop).
In more detail
Constrained decoding and parallel tool calling
To prevent smaller or quantised on-premise models from emitting malformed JSON or hallucinated argument names, inference servers use constrained decoding (grammar or finite-state machine enforcement such as `xgrammar` or Outlines). Modern models also support parallel tool calling, proposing multiple independent calls in a single turn to reduce loop latency; they also support tool-choice modes (`auto`, `required` or a fixed tool).
Indirect prompt injection from tool output
Prompt injection does not only come from user messages: untrusted data returned by a read-only tool (such as an email, support ticket or web page) can contain hidden instructions that hijack subsequent tool calls. Combining private data access, untrusted external content and state-changing or external-egress tools creates high exfiltration risk unless strict data-flow boundaries and human approvals are enforced.
Tool schema bloat and dynamic tool selection
Passing dozens of verbose tool schemas in every prompt consumes thousands of input tokens and degrades tool-selection accuracy. Production agent architectures mitigate this context bloat through dynamic tool retrieval or hierarchical tool routing, injecting only relevant schemas per turn.
Error feedback, idempotency and loop limits
Agent loops must enforce maximum iteration caps, per-tool timeouts and structured error messages back to the model so it can recover gracefully rather than spinning infinitely. Tools that modify records or trigger transactions should require idempotency keys to guard against duplicate execution on retries.
Commonly confused terms
| Term | How it differs |
|---|---|
| Structured outputs | Structured output constrains the model's final text generation to match a JSON schema or grammar; tool calling uses structured arguments specifically to invoke external application logic and return observations back into a multi-turn loop. |
| Agentic RAG versus classic RAG | Traditional RAG executes a fixed retrieval pipeline before prompting the model; tool calling lets the model dynamically decide whether, when and with which query or parameters to invoke search, database or write APIs (agentic RAG). |
Why tool calling matters for on-premises AI
It lets an in-house assistant look up records, run calculations or start workflows instead of only writing text. The most common risk is prompt injection leading the model to produce unexpected parameters or call an unauthorised tool (prompt injection), so each tool gets least privilege and parameters are validated. Tools that change data, move money or send messages outside need human approval; every call is logged.
When a user gives a policy number, an insurer's claims assistant calls the policy lookup tool; the application checks permissions and returns current cover details.
Common questions
Does a language model run tools directly?
No. The model only produces the tool name and parameters. The application validates the call, checks permissions and runs the tool.
What is the most common security risk in tool calling?
Prompt injection causing unexpected parameters or unauthorised tool calls. Least privilege, parameter validation and human approval for critical actions reduce the risk.
Related terms
- Tool definition
- Model Context Protocol
- Tool choice
- Parallel tool calling
- Agent tool
- Agent loop
- AI agent
- Structured output
- Prompt injection
- AI excessive agency
Sources
- Schick et al., Toolformer: Language Models Can Teach Themselves to Use Tools, 2023
- Yao et al., ReAct: Synergizing Reasoning and Acting in Language Models, 2022
- OWASP Top 10 for LLM Applications 2025, LLM06: Excessive Agency
Related page on this site: Related FAQ · In the glossary: Glossary, R to Z