Thought Leaders
A Stranger Broke Our AI Agent’s Guardrails. Here Is What It Taught Us

Key PointsPrompts are requests the model can talk its way past while real access control lives in…
View more
- Prompts are requests the model can talk its way past while real access control lives in the database.
- Every capability handed to an agent becomes a capability an attacker can try to exploit through it.
- Tests written from memory only cover what you remembered so inventory the system's own permissions instead.
A few weeks ago we published a technical walkthrough on a problem we see in almost every AI project we take on: how to stop an AI agent from reading data it shouldn’t. The short version was that you give the agent its own database role, grant it only the columns it needs, pin every query to one customer with row-level security, and write a test that tries to leak data. It’s the pattern we recommend, and we tested every snippet before publishing.
The same day, a developer we had never met left a comment. He had rebuilt the whole setup from the article, seeded it with two test customers, and run our tests. They passed. Then he tried to break it, and found three separate ways to read one customer’s data while logged in as another.
He was right about all three. We reproduced each one before changing anything, fixed the article, and credited him at the top. But the bugs themselves matter less than what they say about how most teams are approaching AI agent security right now, ourselves included.
The Prompt Is Not the Boundary
The most common mistake in “chat with your data” features is treating instructions to the model as access control. A system prompt that says “only answer questions about the current customer” is a request. Models follow it most of the time, and then a cleverly worded question, a confusing document or a prompt injection gets past it.
OWASP’s list of the top risks for LLM applications has a name for the underlying problem: excessive agency, meaning an AI system that has been given more permissions than its job requires. Their advice is the same advice security engineers have given for decades. Limit what the component can do, and enforce the limit somewhere the component cannot talk its way past. It’s the same instinct behind the argument that AI agents need job descriptions, not better prompts: an agent’s authority should be defined outside the model, not inside it.
For an agent that queries a database, that somewhere is the database itself. Our article put the limits there, and we still got it wrong in three places. That’s the part worth learning from.
Gap One: The Table We Forgot
We granted the AI role read access to two tables, orders and products. We switched on row-level security for orders. We never switched it on for products.
Every test we wrote was about orders, because orders were what we were worried about. The reader asked the agent’s “low stock” tool a question and got back both customers’ product catalogues.
The lesson isn’t “remember every table.” People don’t remember every table. The lesson is that a test written from memory only covers what you remembered. His fix was better than ours: a test that asks the database for every table the AI role can read, and fails if any of them lacks a policy. It doesn’t depend on anyone’s memory, and it keeps working when a new table is added next year by someone who never read the article.
Gap Two: The Agent Could Change Its Own Permissions
Our design told the database which customer a request belonged to by setting a session value, and the security policy compared every row against that value. The application set it, never the model.
That holds as long as the model can only call the fixed queries we wrote. We had also mentioned, as a later option, letting the model write its own SQL. The reader showed what that would mean. Postgres lets any role call a built-in configuration function that changes session settings. A single query could change the customer value halfway through and read another customer’s orders. The same function could switch off the timeout we had set to protect the database from runaway queries.
This is the pattern that worries me most about the current wave of agent tooling. Every capability we give an agent is a capability an attacker can try to use through it. The security guidance for the Model Context Protocol makes the same point at the protocol level: tools should get the narrowest permissions their task needs. Letting a model write free-form SQL is the opposite of narrow. We now tell clients plainly that named, fixed queries are the default, and model-written SQL only runs after it passes a strict allowlist that checks what the statement actually does.
Gap Three: “Fails Closed” Depended on Which Connection You Got
We had designed the policy to fail closed. If a request forgot to say which customer it belonged to, the policy returned nothing rather than everything. We tested it, and it worked.
It worked on a fresh database connection. In production, applications reuse connections through a pool, and on a connection that had already served a request, the “missing” value came back as an empty string rather than as nothing at all. The query didn’t leak data, but it crashed instead of returning an empty result, and whether it crashed depended on which connection the pool handed out.
No one would have found this from reading the code. It only showed up because someone ran it the way it would really run. The fix was one function call. Finding it took an outsider who didn’t share our assumptions about how the code would be used.
What We Changed in How We Work
The article is fixed, but the more useful changes are in our process.
First, inventory beats memory. Wherever a security rule has to cover “every table”, “every tool” or “every endpoint”, we now test it by asking the system for its own list instead of writing the list by hand.
Second, every capability an agent has is assumed to be used against us. Before an agent gets a tool, we ask what the worst person who can talk to the agent could do with it. If the answer includes changing its own permissions, the tool doesn’t ship.
Third, we test guardrails in the conditions they will actually run in: pooled connections, concurrent requests, retries, real data volumes. A guardrail that only holds on a developer’s laptop isn’t one.
Fourth, and least comfortable, we now want outsiders to look. Publishing the pattern in detail is what got it broken, and getting it broken in public, by someone friendly, within a day, is the best outcome we could have asked for. The alternative was finding these gaps in a client’s production system.
The Broader Point
Much of the conversation about AI agents is about capability: which model, which framework, how many tools. Far less is about the boring layer underneath, the permissions, policies and tests that decide what happens when the model does something nobody intended.
That layer is where the real risk sits, and it’s mostly ordinary software engineering. Least privilege, tests that don’t rely on memory, and review by people who didn’t write the code have been good practice for decades. AI agents haven’t changed that. They have made the cost of skipping it much higher, because the thing on the other side of your permissions is now a system that will try every door it’s given, as often as it’s asked.
Our walkthrough was wrong in three places and right in its main claim. Access control for AI agents belongs in the systems the agent touches, not in the prompt. We just hadn’t taken that idea as far as it needed to go.
Which raises a question worth asking of any agent you run today: if a stranger spent a day trying to break its permissions, what would they find first?












