Safeguard
AI Security•

Six design patterns for agents that resist prompt injection

A 2025 research paper names six agent design patterns that limit prompt injection by structure. Here is what each does and what it costs in usefulness.

Safeguard Security Team
4 min read

Researchers have proposed six agent design patterns that limit prompt injection by changing the structure of the system rather than by hoping the model behaves: action selector, plan then execute, LLM map reduce, dual LLM, code then execute, and context minimization. Each trades some flexibility for a smaller attack surface.

Why structure beats instructions

You cannot reliably tell a model to ignore malicious text hidden in data it reads. The paper behind these patterns, "Design Patterns for Securing LLM Agents against Prompt Injections" (arXiv 2506.08837, 14 authors), argues instead for architectures where untrusted text cannot change what the agent does. The authors also discuss the utility and security trade-offs of each pattern.

The six patterns

Action selector. The model maps a request to one action from a fixed list. Results of the action never feed back into the model. Very safe, and also the least flexible. Good for a support bot with five allowed answers.

Plan then execute. The agent commits to a fixed sequence of tool calls before it reads any untrusted data. Later content cannot add or change steps. Content can still corrupt the parameters of a step, so validate those.

LLM map reduce. Separate, isolated model calls each handle one untrusted item and return constrained output, such as a label or a score. A separate step combines the results. A poisoned document can only damage its own result.

Dual LLM. A privileged model with tool access coordinates a quarantined model that reads untrusted text but has no tools. The privileged side works with references to the quarantined output rather than the raw text.

Code then execute. The agent writes a program that calls tools and quarantined models, then runs it. Untrusted data never directs the control flow because the flow is fixed in code before execution.

Context minimization. After the user's request has chosen the initial action, the request is removed from context so it cannot shape later outputs. Useful when the user prompt itself might carry injected content.

Choosing a pattern

Your agentStart with
Fixed set of tasks, no need for free text answersAction selector
Multi-step task where steps are known up frontPlan then execute
Many untrusted documents to classify or extractLLM map reduce
Needs tools and also reads outside textDual LLM
Complex logic over many tool callsCode then execute

These are not mutually exclusive. A real system often combines two.

What they do not solve

Patterns reduce what a hijacked model can do. They do not make the model honest, and they do not fix bad tool design. If a tool can delete production data with no confirmation, a clean architecture will not save you. Pair patterns with least privilege and approvals for risky actions.

Test the pattern, not the diagram

After you pick one, test it with hostile inputs: a document that says to send its contents to an address, a ticket that asks for a different tool. Check that the plan or control flow does not change. The UK NCSC and NIST both stress continued testing; see what NIST found about repeated attacks.

Where Safeguard fits

Safeguard's policies and gates can enforce deterministic limits outside the model, such as which tools an agent may call, and the MCP Guardrail applies that to MCP tool use. Those are the non-LLM controls these patterns depend on.

Quick check

Which pattern is the safest?

The action selector, because the model only picks from a fixed list and tool results never return to it. It is also the least flexible.

Can I combine patterns?

Yes. Combining, for example, plan then execute with a quarantined model for reading documents, is common.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.