"Tool use without trust: the model requests, your code decides"
Giving a model tools does not mean giving it authority. Every tool call is a request from an untrusted client, and the layer that decides whether to honour it is ordinary code you write. Here is how I build that permission boundary, allowlists, argument validation, and deciding in code, not in the prompt.

There is a moment in every agent project where someone wires a model up to a function that does something real, sends an email, writes to a database, calls an API that costs money, and the demo works, and everyone relaxes. That is precisely the wrong moment to relax. What just happened is that a probabilistic text generator gained the ability to trigger side effects in your systems, and the only thing standing between its output and those side effects is whatever code sits in the middle. That code is the most important part of the system, and in most demos it barely exists.
The mental model I use is simple: the model requests, my code decides. A tool call coming back from an LLM is not a command to be executed. It is a suggestion from an untrusted client, the same trust level you would assign to a form submission from the open internet. You would never take a user-supplied string and pass it straight into a shell command or a SQL query. A model-supplied tool call deserves exactly the same suspicion, because the model can be wrong, can hallucinate a tool that does not exist, can pass arguments that are plausible but destructive, and can be steered by whatever text found its way into the context window.
That last point deserves emphasis. If your agent reads emails, web pages, or documents, then anyone who can write to those sources can write to your agent's context. Prompt injection is not exotic, OWASP has kept it at the top of its LLM security list in every edition, and Simon Willison gave the worst configuration a useful name: the lethal trifecta, an agent with access to private data, exposure to untrusted content, and a way to communicate externally. Grant all three in one session and anyone who can plant text in front of your agent can pull your data out, no exploit code required. You will not solve it with a system prompt that says "ignore malicious instructions". The model cannot reliably distinguish your intent from an attacker's, so the enforcement has to live somewhere the attacker's text cannot reach, in code.

The first layer is an allowlist. The model can only invoke tools you have explicitly registered for this task, in this context, and the dispatch is an exact match against that list. Anything else, a misspelled name, an invented tool, a tool that exists elsewhere in your codebase, is rejected before anything runs. This sounds obvious, and yet plenty of frameworks make it easy to expose a broad surface by default. I register the minimum set per task, not per system. An agent that summarises documents gets a read tool, not the whole toolbox.
The second layer is argument validation, and it is where most of the real protection lives. Every tool has a schema, I use Pydantic in Python and Zod in TypeScript, and every argument the model supplies is parsed against it before execution. Types, ranges, enums, formats. But the schema is only the start. The stronger move is validating arguments against business rules the model never sees: this refund tool accepts amounts up to £200; this email tool only sends to addresses on the customer record; this query tool only touches these three tables. The model does not need to know the limits exist. It requests, the validator decides.
The third layer is deciding in code what the model is not allowed to decide at all. Some parameters should never come from the model: which database credentials to use, which account is being acted on, which environment we are in. Those are injected by your code from the authenticated session context. If the model can specify the customer ID and the model can be steered by injected text, then an attacker can act on someone else's account. Bind the sensitive parameters server-side and let the model fill in only the genuinely variable parts.
It helps to notice that none of this is new engineering. It is the same discipline as building a public API: authenticate the caller, validate the input, authorise the action, scope the credentials, log the request. When I mentor developers on their first agent build, this is the moment it clicks, the tool boundary is just another public endpoint, and they already know how to defend one of those. Yet teams that would never ship an unvalidated endpoint somehow ship unvalidated tool dispatch because the framework made it look safe. It is not the framework's job to know that a £40,000 refund is wrong. It is yours.
There is a cost to all this, and I will not pretend otherwise. Tight allowlists mean the agent sometimes cannot do something genuinely useful, and you have to widen the boundary deliberately. Validation rules need maintaining as the business changes. But every one of those rejections is visible and debuggable, which is a far better failure mode than an agent that quietly did the wrong thing with full authority. I run agents in my own business operations, and the boundary layer is the part I trust, not the model.
This is the work I do: designing and building the permission boundary between models and real systems, so tool use is useful without being trusted. If you are putting an agent anywhere near production, I can help you get that layer right, get in touch via the contact form.
Senior engineering roles — or production AI consulting?
I'm open to senior AI and software engineering roles and to selective consulting on agents, RAG, and LLM automation in production. If this post resonates — as a hiring manager or as someone shipping similar work — get in touch.
Get in touch