Prompt injection defense for AI agents: what holds, what does not
Structural controls limit what a prompt injection can do; filters and delimiters only lower the odds. Which defenses hold for agents with tools, and why.
The defenses that hold are structural: they limit what an agent can do after it has been fooled. Give it the fewest tools, keep untrusted content away from tools that can act, require approval after untrusted input, limit where data can go, and never let an untrusted sender reach your tools. Filters and delimiters help, but they only lower the odds, and no source claims they stop a determined attacker.
What is the difference between direct and indirect injection?
OWASP lists prompt injection first in its Top 10 for LLM applications and defines it as input that changes a model's behavior in unintended ways. It names two kinds.
- Direct: the person typing the prompt changes the model's behavior, on purpose or by accident. If that person is you, the risk is small. If it is a stranger who can message your agent, they are using your agent's tools.
- Indirect: the model reads outside content, such as a web page or a file, and that content contains instructions that change its behavior. The person who owns the agent never sees them.
OWASP's indirect example is a summarizer that reads a web page with hidden instructions and then leaks conversation data through an image URL. The page needed no access to the agent. It only had to be read.
Models read instructions and data as the same stream of text. That is why OWASP says it is unclear whether fool-proof prevention exists, and why its mitigations are written as ways to reduce impact.
What makes an agent dangerous to inject?
Simon Willison names three capabilities that are dangerous together, the lethal trifecta: access to your private data, exposure to untrusted content, and the ability to communicate externally. An agent with all three can be told by a web page or an email to gather your data and send it to an attacker.
His advice is to avoid the combination entirely, and he notes that vendors cannot fix this for you when you mix tools yourself. Remove any one leg and the attack loses its payoff. An agent with no outbound channel cannot leak. An agent that never reads untrusted content has nothing to be steered by. An agent with no private data has little to steal.
Which defenses hold?
These controls do not depend on the model noticing an attack. They bound the damage when it does not.
Least privilege
OWASP lists privilege control and least privilege access among its mitigations. Give the agent only the tools the task needs, with credentials scoped to the person it acts for. A tool that was never connected cannot be misused. For a browser agent, this includes the logins it holds; see sharing browser logins between AI agents.
Untrusted content away from privileged tools
Willison's dual LLM pattern splits the work. A privileged model can call tools but never sees untrusted text. A quarantined model reads untrusted text but has no tools. Ordinary code passes results between them as named variables, so the privileged model sees a reference, not the content. Willison himself calls it imperfect: if a person can be tricked into pasting untrusted text into the privileged side, it fails, and it adds complexity.
The CaMeL paper, titled Defeating Prompt Injections by Design, takes the idea further. It derives the control flow from the trusted user request, so untrusted data cannot change the program, and it attaches capabilities to data so that private values cannot flow to unauthorized places. On the AgentDojo benchmark it solved 77% of tasks with provable security, against 84% for an undefended system. The guarantees are strong, and they cost some completed tasks.
You do not need either design to apply the idea. A plain version: the step that reads a web page or an inbound email has no send, delete or pay tool in the same run.
Approval after untrusted input
OWASP lists human approval for high-risk actions as a mitigation, and OpenAI's agent safety guide says to keep tool approvals on so people can review and confirm every operation. Make the rule sharper: an action needs approval when untrusted content entered the conversation earlier, even if the same action ran silently yesterday. The approval should show the exact action and arguments. Which AI agent actions should wait for a human covers how to word and scope these requests.
Limit where data can go
Exfiltration needs a destination: an email address, a URL, a chat message, an image link. Allowlist the domains an agent may fetch or post to, and treat a new recipient or a new domain as an approval event. This works on the third leg of the trifecta, and it works even when the model has already been fooled.
Untrusted senders never reach tools
If an agent takes messages from a group chat, a webhook, a shared inbox or another agent, those senders are not you. A message from them can answer a question. It should not be able to call your tools, read your notes or see your memory. Decide per channel who may act as the owner, and identify that person by a stable account ID. The guide to agents in chat apps covers this for each platform.
Which defenses only help?
Filtering and classifiers. OWASP lists input and output filtering, and OpenAI's guide calls guardrails on user inputs an effective first wave of protection, and not foolproof. Anthropic's own measurements show both sides. For browser use, its improved safeguards (training, classifiers that scan untrusted content, and red teaming) brought the attack success rate against an adaptive attacker with 100 attempts per environment to between 1.4% and 2.4% across four models. Anthropic also says prompt injection is far from a solved problem and that a 1% rate still represents meaningful risk. Willison's view is the same from the security side: 95% detection is a failing grade in web application security, because an attacker needs only one miss.
Delimiters and labeling. OWASP recommends segregating and identifying external content, and OpenAI recommends passing untrusted input through user messages and keeping it out of developer messages. Both reduce the influence of untrusted text. Neither stops a model from following it, so use them as a backup layer.
Constraining output. OpenAI suggests structured outputs with fixed schemas and enums, which remove free-text channels an attacker could use to smuggle instructions onward. This is strong where it fits, because an enum cannot carry a sentence.
Adversarial testing. OWASP also lists red teaming. Run it, but read a pass as "I did not find a way in", not as proof that none exists.
A worked example
An assistant reads your inbox, drafts replies and can send mail. A message arrives that says to forward the last ten invoices to an outside address.
| Defense | What happens |
|---|---|
| Classifier flags the message | The next message is worded differently and passes |
| Delimiters mark the email as data | The model follows the instruction anyway |
| Sending needs approval, and shows the recipient | You see an unknown address and decline |
| Sending is limited to known contacts | The send is blocked before you are asked |
| The reading step has no send tool | The instruction has nothing to call |
The first two rows describe what can go wrong. The last three still work after the model has been fooled, which is the property to design for.
What should you do this week?
- List each agent's tools and mark which can send, delete, pay or share.
- For each agent, check which of the three trifecta legs it has, and remove one where you can.
- Turn on approval for every outbound action that can follow untrusted input, and make the approval show recipients and arguments.
- Add an allowlist for outbound domains and recipients.
- Keep filters and delimiters on, but do not rely on them alone.
Tenslo Bot follows this order. When text from a webhook or from another bot is in the conversation, the bot asks before it acts, fetches a web page or calls a connected app, so that text cannot steer your tools. Runs that answer a group, a team chat or another bot do not see your memory, notes, skills, secret names or your own conversation.
Sources
- LLM01:2025 Prompt Injection, OWASP Gen AI Security Project
- The lethal trifecta for AI agents, Simon Willison
- The Dual LLM pattern for building AI assistants that can resist prompt injection, Simon Willison
- Defeating Prompt Injections by Design, arXiv (Debenedetti et al.)
- Mitigating prompt injections in browser use, Anthropic
- Safety in building agents, OpenAI