Design Patterns for Securing LLM Agents against Prompt Injections is a 2025 paper that offers six ways to build AI agents so that injected instructions can't make them do anything harmful. The trade-off is that each pattern limits what the agent can do.
The paper (arXiv 2506.08837) has authors from IBM, Invariant Labs, ETH Zurich, Google, Microsoft, EPFL, Swisscom and others. Simon Willison called it "an excellent addition to the literature on prompt injection and LLM security" in his summary.
The core principle
Everything in the paper follows from one rule. Once an agent has read untrusted input, it should be constrained so that input can't trigger any consequential action.
That's a shift from trying to detect attacks. The patterns assume an injection might succeed in fooling the model, and they make sure a fooled model has no harmful moves available.
The authors are frank about the cost. Willison quotes them saying it's unlikely that general-purpose agents can give meaningful and reliable safety guarantees. So the patterns are for agents built for specific jobs.
The six design patterns for securing LLM agents
1. Action-Selector
The agent maps a request to one of a fixed set of actions and never sees the results. Willison compares it to a switch statement driven by the model. Since nothing comes back into the model's context, there's nothing to inject.
2. Plan-Then-Execute
The agent decides its full list of tool calls before it reads any untrusted data. Tool outputs can change the data passed along but not which actions run.
3. LLM Map-Reduce
Each untrusted item, like a file or a review, goes to its own isolated model call that returns a constrained answer, such as yes or no. A final step combines those answers. One poisoned file can only spoil its own answer.
4. Dual LLM
A privileged model with tools plans, and a quarantined model with no tools reads untrusted text and hands back symbolic variables. This is Willison's 2023 idea, covered in our post on the dual LLM pattern.
5. Code-Then-Execute
The model writes a program that calls tools and quarantined models, and the program then runs. Willison describes this as the approach used by Google DeepMind's CaMeL, which tracks tainted data through the program.
6. Context-Minimization
Content that's no longer needed, including the user's original prompt, gets removed from context after it has done its job, so it can't shape later output. Willison admits he finds this one a little confusing, and it's the least intuitive of the six.
The ten case studies
The paper applies the patterns to ten example agents: an OS assistant with fuzzy search, a SQL agent, an email and calendar assistant, a customer service chatbot, a booking assistant, a product recommender, a resume screening assistant, a medication leaflet chatbot, a medical diagnosis intermediary, and a software engineering agent.
Each case shows the same tension. Stronger isolation means fewer automated decisions or more refusals. The authors recommend combining patterns, since no single one fits every threat model.
Willison raises one useful doubt. In the software engineering case, a limit of 30 characters on method names is used as a constraint, and he's not convinced a creative attacker couldn't fit something harmful in that space. It's a good reminder that constraints need testing too.
How to pick a pattern
A rough guide based on what the agent must do:
| If your agent... | Consider |
|---|---|
| Only needs to trigger one of a few actions | Action-Selector |
| Has a predictable workflow | Plan-Then-Execute |
| Processes many untrusted items independently | LLM Map-Reduce |
| Must summarize or extract from untrusted text | Dual LLM |
| Needs flexible multi-step plans with tight data rules | Code-Then-Execute |
| Keeps old content around that it doesn't need | Context-Minimization |
Whichever you choose, check it against the lethal trifecta. If the agent can read private data, read untrusted content and send data out, at least one pattern should break that chain.
Testing your design
Patterns only help if they hold up in your actual code. A simple routine:
- List every place untrusted content enters the agent.
- Plant a harmless canary payload in each one.
- Check whether the canary changes which tools run, what arguments they get, or what the user sees.
- Scan incoming documents with the analyzer to catch obvious injection text early.
Next step: start with the canary tests and see which of your agent's actions an injected line can reach.