Tool Use in LLMs: How Models Call Tools Safely
Tool use in LLM architecture lets a model call functions and run actions in a plan, call, observe, answer loop, with schemas, permissions and checks at each step.
On this page
Short answer
Tool use in LLM architecture is the design that lets a language model go beyond text: the model plans a task, calls a declared tool such as a search function or an API, reads the result, and then answers or calls another tool. The architecture wraps that loop in schemas, permissions and validation, so the model can act without reaching systems it should not touch.
What is tool use in LLM architecture?
Tool use in LLM architecture is the design that lets a language model call external functions instead of answering from its training data alone. The model receives a list of tools, each described by a name, a purpose and a schema of its inputs, and it decides which tool to call, with what arguments, as part of answering a request.
The architecture has four parts: the model that reasons and picks tools, a tool registry that holds the declarations, an execution layer that runs the call and returns the result, and a control layer that checks permissions, validates inputs and logs everything. The model never touches a database or an API directly; it only asks the execution layer to run a named tool.
This matters because it turns a chatbot into a working assistant. A model that can look up an order, check a calendar or file a ticket is far more useful than one that can only describe how to do those things. For the basic mechanism, see what is function calling.
How does the tool-call loop work?
The tool-call loop runs in four steps: plan, call, observe and answer. The model first reads the request and decides whether a tool is needed. If so, it produces a structured call with the tool name and arguments. The execution layer runs the tool and returns the result as text. The model then reads the result and either calls another tool or writes the final answer.
Most tasks need more than one loop. A request such as "refund my last order" needs a lookup tool, then a policy check, then a refund tool, with the model deciding each next step from the previous result. The loop continues until the task is done or the model reaches a step limit.
Set a step limit, usually between five and ten calls, and stop the loop when it is reached. Without a limit, a confused model can call tools in circles, repeating the same lookup or alternating between two tools, and the cost and latency grow with every extra step.
How do you design tool schemas?
Design tool schemas so the model can use them without guessing. Each tool needs a short, plain name, a one-sentence description of what it does and when to use it, and a typed list of inputs with a description for each field. Names such as search_orders and cancel_order beat vague names such as run_query every time.
Keep tools narrow. A tool that does one thing, such as fetching an order by number, is easier for the model to pick and easier to secure than a tool that accepts any database query. If a tool needs more than five or six inputs, it is probably doing two jobs and should be split.
Write the descriptions for the model, not for a human developer. State what the tool returns, what it does not do, and which tool to use instead when the request is close but different. Good descriptions cut wrong-tool errors more than any prompt trick. How to implement function calling shows the schema pattern in code.
How do you keep tool use safe?
Keep tool use safe by treating every call as untrusted input. Validate the arguments against the schema before running anything, reject values that do not fit, and never let the model pass raw text into a query or a command. The execution layer, not the model, decides what runs.
Scope permissions per tool and per user. A read-only search tool can run freely, but a refund or delete tool needs a human approval step or a narrow spending limit. The model should not hold a shared admin credential; each tool runs with the smallest permission that fits its job.
Log every call with its arguments, the result and the user who asked. Logs are how you find out why a wrong action happened, and they are the evidence you need when a customer asks what the system did. They also feed your evaluation set, so the next version of the system can be tested on real failures.
When should the model call a tool, and when not?
The model should call a tool when the answer depends on live data, a calculation, or an action in another system. Order status, prices, availability, account details and file contents are all tool jobs, because the model's training data cannot know them.
The model should not call a tool for general knowledge, explanations or drafting. Asking a search tool for the definition of a concept wastes a call and adds latency, and the model already knows most of it. The same applies to summarising text the user already pasted into the chat.
Teach the choice with examples, not with rules alone. A few worked examples in the prompt, showing a request, the tool choice and the reason, guide the model better than a long list of do-and-don't rules. Review the examples after launch and replace the ones the model keeps getting wrong. ReAct agents versus function calling agents compares two ways of structuring this choice.
| Task | Call a tool? | Why |
|---|---|---|
| Order status or price | Yes | Depends on live data |
| Calculate a total | Yes | Needs exact arithmetic |
| Explain a concept | No | General knowledge suffices |
| Draft from pasted text | No | The text is already in the chat |
| File a ticket or refund | Yes | An action in another system |
How do you handle failures and retries?
Handle failures by expecting them. Tools fail: an API times out, a lookup returns nothing, or the model passes a bad argument. The execution layer should return a short, plain error message to the model, such as "order not found" or "service timed out", and let the model decide what to do next.
Retry once for transient errors such as timeouts, then stop. Retrying the same failing call five times burns tokens and rarely helps, and it can trigger duplicate actions if the tool is not safe to repeat. For actions that change data, use an idempotency key so a retry cannot create the same refund or ticket twice.
Give the model a graceful fallback. If the lookup fails, the model should tell the user what it tried, what went wrong and what happens next, instead of inventing an answer or repeating the failed call. A clear failure message is better than a confident guess.
Example (hypothetical): an order-status assistant
Example (hypothetical): a shop builds an assistant that answers "where is my order?" with three tools: find_order, get_tracking and create_ticket. A customer asks about order 48210. The model calls find_order with the number, gets the order and its tracking reference, then calls get_tracking and learns the parcel is two days late.
The model answers with the status and offers to open a ticket. The customer says yes, so the model calls create_ticket with the order number and a short summary. Three calls, each with a clear purpose, and the whole exchange takes under a minute.
The numbers: without the assistant, an agent spends about 6 minutes per order query. With 200 queries a week, that is 20 hours. The assistant handles 160 of them end to end, each in about 40 seconds of model time, leaving 40 for a human. The team saves roughly 16 hours a week, and the human agents handle the cases that need judgement.
What are the common mistakes?
The most common tool-use mistakes are giving the model too many tools, writing vague schemas, and letting tools run without validation or logging.
- Too many tools. A registry of forty tools confuses the model; twenty narrow, well-named tools work better than forty broad ones.
- Vague descriptions. If two tools sound alike, the model will pick the wrong one. Say what each tool does not do.
- No input validation. Passing model output straight into a query or command is how prompt injection becomes a real breach.
- Shared admin credentials. One credential for every tool means one mistake can reach every system.
- Unlimited loops. Without a step limit, a confused model can call tools in circles and run up the bill.
- No logs. Without a record of calls and results, you cannot debug a wrong action or prove what happened.
Key takeaways
- The model plans, calls, observes and answers in a loop, with a step limit to stop runaway calls
- Narrow tools with plain names and clear descriptions are picked correctly far more often
- Validate every argument and scope permissions per tool, never with a shared admin credential
- Retry a failed call once, then fall back to a clear message instead of guessing
- Log every call, so wrong actions can be traced and the next version can be tested on real failures
Frequently asked questions
What is the difference between tool use and function calling?
Function calling is the mechanism: the model outputs a structured call to a named function. Tool use is the wider architecture around it: the registry, the execution layer, the permissions, the loop and the logging. You need both, but the architecture is what makes function calling safe in production.
How many tools should I give an LLM?
Start with fewer than twenty, and keep each one narrow. If the model often picks the wrong tool, the fix is usually better descriptions or splitting a broad tool in two, not adding more tools. Most production assistants work well with ten to fifteen tools.
Can tool use work without a step limit?
It can, but it should not. A step limit of five to ten calls stops the model from looping when it is confused or when a tool keeps failing. When the limit is hit, the model should summarise what it tried and hand over to a human.
How do I stop prompt injection through tools?
Validate arguments against the schema, never pass model output into raw queries or commands, and scope each tool to the smallest permission it needs. Treat tool arguments as untrusted input, even when they come from the model, and log every call.
Should tools return full records or short summaries?
Return short summaries with the fields the model needs, not full records. Long tool results eat context and slow the model down, and they make it harder for the model to find the one field that matters. Fetch detail only when the next step needs it.
Do I need human approval for tool calls?
You need it for irreversible actions: refunds, deletions, sending messages and changing records. Read-only lookups can run freely. A simple rule is to approve anything that changes data or spends money, and to log everything else.