AI Agent Tool Calling Safety: The Model Proposes, Tools Act
Make AI agent tool calls safe: let the model propose a structured action, then have narrow tools check scope, policy and live state before anything executes.
The short answer: Stop letting model output be the action. Give the model one job: turn messy input into a structured proposal in a fixed shape. Then hand that proposal to a narrow tool that checks the requester's scope, the current policy, the live record, the time window and the limits, and refuses or escalates when anything is unclear. Make retries harmless with idempotency keys, treat "not sure" as a real outcome, and grade the record's end state.
Before and after: where the decision lives
In most first-generation agents, the model's output is the action. The agent reads a customer email, decides the customer wants a new shipping address, and calls a general update tool with whatever fields it filled in. The tool writes them. If the email was ambiguous, the record had changed, or the sender was not the account owner, nothing between the model and the database noticed.
The pattern that replaces it is easy to say: the model suggests, code decides. The model still does the part only a model can do, which is reading fuzzy language and working out what is being asked. Everything that touches a record or a customer goes through a narrow tool that checks the request against the facts before it acts. One bad instruction, whether it comes from a confused model or a hostile email, then produces at most a refused proposal.
| | Before | After | |---|---|---| | Who acts | The model, through a general tool | A narrow tool, after its own checks | | Model output | Open text or loosely shaped arguments | A proposal in a fixed schema with quoted evidence | | Scope | Assumed from the prompt | Checked against the requester's identity and region | | Record state | Whatever the model read earlier | Re-read and compared at execution time | | Retry after a timeout | Can act twice | Same key, same result, one effect | | Unclear case | The model guesses | The tool refuses or routes to a person | | How you grade it | The agent says "done" | The record ends in the expected state |
Here is how to get from the left column to the right one.
Step 1: Limit the model to a proposal in a fixed shape
Give the model exactly one output channel: a structured proposal validated against a schema, ideally with schema or grammar-constrained decoding so malformed output cannot be produced at all. For an account-change request it might look like this:
{
"intent": "change_shipping_address",
"new_address": {"line1": "...", "city": "...", "postal_code": "...", "country": "..."},
"evidence": "exact quote from the new part of the message",
"unsure": false
}
Notice what is missing: the account. The account comes from the authenticated session, never from text in the email.
Three design choices matter. Fields are nullable, so the model is never forced to invent a value to fill a required box. Each value carries an exact quote that code searches for in the new text of the message, not in the quoted history below it. And "unsure" is an allowed answer, not a failure.
A typed answer guarantees shape, not truth. A perfectly valid proposal can still misread a date or describe a change the customer never asked for. The schema is where the control starts, not where it ends.
Decide up front which intents are never automated, whatever the model's confidence. Bank details and changes to terms are the usual examples. The model can still recognise them; the only thing it can propose is a hand-off task for a person.
Step 2: Make each tool narrow and self-checking
A tool called update_customer that accepts any field is just the model with extra steps. Replace it with tools that each do one thing, such as change_shipping_address, and give each tool checks that run at execution time, in this order:
- Requester and scope. Is the caller the account owner, or someone with delegated authority over this account? The tool acts with the requester's scope, not a broad service credential. Delegated tokens in the style of OAuth 2.0 Token Exchange (RFC 8693) are one way to carry that scope down to the tool.
- Region. Is this change allowed for this account's region through this channel?
- Policy version. Which version of the change policy applies right now? Store it with the action so you can later tell which rule allowed it.
- Live record state. Re-read the record. If it changed since the model saw it, or an order has already passed the point where the address can change, stop.
- Date windows and limits. Is the request inside the allowed window? Has this account or this tool already hit its daily cap?
Any check that cannot answer cleanly returns refuse or escalate, never "probably fine". The tool returns a status to the agent, not a prose explanation the model can argue with.
Step 3: Make retries harmless by design
Agents retry. Networks drop replies. Queues deliver the same message twice. If any of those can produce two address changes or two customer emails, you have a correctness bug that no prompt will fix.
Build five properties into every tool that changes state:
- An idempotency key built from the request, the account and the change, so the same proposal executed twice returns the stored first result. Idempotence is the property you are designing for.
- An outbox, so the record change and the outgoing notification commit together and the notification goes out once from the outbox, not from the agent.
- A daily cap per account and per tool.
- An allowed time window for actions that reach customers or other systems.
- One-step undo, with the previous value stored next to the change.
The test is concrete. Deliver the same request twice. Separately, simulate a lost reply followed by a retry. Both runs must show exactly one change and one notification.
Step 4: Treat "not sure" as a result, not an error
The riskiest moment for an agent is a timeout after a write. The tool may have acted, and the agent cannot tell. The tempting moves are to try again, or to reach the same goal through a different tool.
The rule: an unknown effect never authorizes a second action. The tool returns a status such as in_progress or unknown. The agent tells the user the request is being processed, and the case goes to a person or to a reconciliation job that reads the record and settles what actually happened. Nothing else happens on that request until the effect is known.
Step 5: Break at least one of the three legs
An agent becomes dangerous when it holds three things at once: access to private data, exposure to untrusted content, and a way out (any channel that can send data or trigger actions outside). Prompt injection, which leads the OWASP Top 10 for LLM applications, does the most damage when an agent holds all three.
For each agent, write the three legs down and break one by design. An email-intake agent reads untrusted content and touches private account data, because that is its job. So take away the open-ended way out: it can trigger only templated notifications to the address already on file, never compose a message to an address it found in an email.
How to measure it: grade the end state
An agent saying "done" is a claim. The evidence is the record. Build your evaluation set as requests paired with the expected end state of the system, and grade by reading the record after each run.
Include the negative cases that matter, each with its expected end state:
- a request from someone who is not the account owner (record unchanged, refusal logged)
- a record that changed between proposal and execution (no write, escalation)
- an email carrying an instruction aimed at the agent (nothing beyond the legitimate request)
- a duplicate delivery, and a lost reply plus retry (exactly one change each)
- a bank-details request (a hand-off task, nothing else)
Add a control that must fail. A deliberately broken build that automates bank details, or skips the idempotency key, has to turn your tests red. If it passes, your tests are not checking what you think.
Then measure consistency, not a single pass. If an agent handles a task correctly 90% of the time, the chance it gets 8 runs of that task all right is 0.9 to the 8th power, about 43%. At 97% per run it is about 78%; at 99%, about 92%. Chained steps compound the same way: five steps at 95% each finish cleanly about 77 times in 100.
Before letting a tool act without review, size the evidence. Zero failures in 73, 189 or 381 end-state checks supports a success rate of at least 95%, 98% or 99%. The rule of three) gives a quick read: zero errors in 300 runs puts the error rate below about 1%. Below those counts, the action stays in review.
What changes for your team
Not every request type needs an agent. If you can write the steps down, run them as a fixed workflow and use the model only to interpret the input. Earn autonomy one request type at a time, with the measurements above as the gate.
Ownership moves too. Rules stop living in the prompt, where nobody can test them, and start living in tool checks that policy and product owners can read, version and test. The model can change; the checks stay.
This is the action half of the problem. The review half, deciding when a person should look and proving the review catches anything, is covered in human in the loop that works. For more on the governance side, see the enterprise governance hub. Eric's essay agents should only suggest walks through the traps and judgment calls behind this pattern.
FAQ
How does an AI agent decide which tool to call? In a safe design the model only proposes a tool call in a fixed schema, with quoted evidence and an allowed 'unsure' answer. A narrow tool then decides whether the call can run by checking the requester's scope, the current policy, the live record and its limits.
How do you stop an AI agent from doing something it shouldn't? Do not let model output be the action. Route every state change through narrow tools that check scope, region, policy version, record state, time windows and caps, refuse or escalate when anything is unclear, and break at least one of the three legs: private data, untrusted content and a way out.
Will a stronger model or a better prompt make agent actions safe? No. A stronger model misreads less often, but a typed, confident proposal can still name the wrong account or act on a stale record. Safety comes from checks in code that run at execution time, whatever the model said.
How do you make agent retries safe? Give every state-changing tool an idempotency key, an outbox, a daily cap, an allowed time window and one-step undo. Test it by delivering the same request twice and by simulating a lost reply plus retry. Both must produce exactly one change.
The live Field Guide lesson "Agents, workflows and harnesses" shows how to start with a recipe and earn autonomy with limits and checks; it is part of the Field Guide.
If you are drawing the line between what your agents propose and what your systems allow, connect with Eric MacDougall on LinkedIn to compare notes and discuss.
FAQ
- How does an AI agent decide which tool to call?
- In a safe design the model only proposes a tool call in a fixed schema, with quoted evidence and an allowed 'unsure' answer. A narrow tool then decides whether the call can run by checking the requester's scope, the current policy, the live record and its limits.
- How do you stop an AI agent from doing something it shouldn't?
- Do not let model output be the action. Route every state change through narrow tools that check scope, region, policy version, record state, time windows and caps, refuse or escalate when anything is unclear, and break at least one of the three legs: private data, untrusted content and a way out.
- Will a stronger model or a better prompt make agent actions safe?
- No. A stronger model misreads less often, but a typed, confident proposal can still name the wrong account or act on a stale record. Safety comes from checks in code that run at execution time, whatever the model said.
- How do you make agent retries safe?
- Give every state-changing tool an idempotency key, an outbox, a daily cap, an allowed time window and one-step undo. Test it by delivering the same request twice and by simulating a lost reply plus retry. Both must produce exactly one change.