What is the dual LLM pattern?
The dual LLM pattern is an architectural defence against prompt injection that splits an assistant into a privileged model with tools, seeing only trusted input such as the user's, plus a quarantined model handling untrusted content with no tools.
Unlike an input guardrail, which tries to detect malicious instructions and fails open when detection misses, the pattern draws the boundary architecturally: untrusted content never enters the tool-using model's context; the model handles quarantined output only through symbolic references such as variable names.
- Topic
- AI security
- Also known as
- Privileged and quarantined LLM
- Origin
- Simon Willison, 2023
How the dual LLM pattern works
- The user's request reaches the privileged model, which plans the steps.
- Untrusted content such as an email, document or web page goes to the quarantined model to summarise or extract.
- Its output is stored in a variable the privileged model refers to by name only.
- The variable is shown to the user or passed to a tool, never mixing into the privileged model's instructions.
In more detail
Low-bandwidth side channels and control-flow leakage
If the privileged model needs to branch on untrusted data (for instance, 'escalate if the email is urgent'), passing even a boolean or category from the quarantined LLM re-introduces a control-flow side channel: an attacker can manipulate the quarantined model's classification to hijack the privileged execution path. Strict designs therefore avoid data-dependent branching or gate sensitive branches on deterministic rules or human confirmation.
Output poisoning, Markdown injection and confused deputy risk
Because the quarantined LLM still processes raw untrusted text, a prompt injection can coerce it into embedding tracking Markdown images, phishing links or fabricated summaries inside the variable itself. When that variable is rendered in a UI or forwarded by an email tool, sanitisation (stripping active links/images) and capability-based data-flow checks are mandatory to prevent exfiltration.
Task fit and limits in dynamic agent loops
Although the Dual LLM pattern enforces architectural isolation, it still relies on the privileged model's planner and cannot handle tasks that require open-ended iterative reading and tool adaptation over untrusted pages (such as dynamic web browsing). Modern security architectures choose between Dual LLM, Plan-Then-Execute, Context-Minimisation or CaMeL-style interpreter sandboxing depending on the utility-versus-assurance trade-off.
Commonly confused terms
| Term | How it differs |
|---|---|
| AI input guardrail | Input guardrails rely on probabilistic classifiers or heuristics to detect malicious instructions in untrusted text and fail open if bypassed, whereas the Dual LLM pattern enforces an architectural boundary so untrusted text never enters the tool-privileged model's context. |
| Plan-then-execute pattern | Plan-Then-Execute generates a fixed tool-call sequence from the trusted user query before reading untrusted data, whereas the Dual LLM pattern uses a separate quarantined model to process untrusted content and return symbolic variable references to the planner. |
| Capability-based security (CaMeL) | Privilege separation isolates data access at the LLM context level, whereas capability-based security (as implemented in CaMeL) attaches formal access-control and data-flow policies to every variable and tool argument so even symbolic references cannot exfiltrate sensitive data. |
Why the dual LLM pattern matters for on-premises AI
The post first describing the pattern pairs a privileged model with tools, working only on trusted input, with a tool-less quarantined model for untrusted content. A paper on defeating prompt injections by design extends it, extracting control and data flows from the trusted query so untrusted data never steers the program; it solved 77% of tasks in an agent benchmark with provable security. A study of agent design patterns weighs utility against security.
In an investment firm's email assistant, a tool-less quarantined model summarises incoming mail; the privileged model with calendar and email tools carries summaries only as variables, never seeing their instructions.
Common questions
Does the dual LLM pattern fully prevent prompt injection?
It architecturally stops untrusted content from mixing into the tool-using model's instructions. How quarantined output is displayed or passed to tools still needs careful design.
What does the dual LLM pattern cost?
Extra model calls and a more complex architecture; some tasks lose utility because the privileged model cannot see content directly.
Related terms
- Prompt injection
- Indirect prompt injection
- AI input guardrail
- AI least agency
- System prompt
- Data exfiltration via AI
Sources
- Simon Willison, The Dual LLM pattern for building AI assistants that can resist prompt injection, 2023
- Debenedetti et al., Defeating Prompt Injections by Design, 2025
- Beurer-Kellner et al., Design Patterns for Securing LLM Agents against Prompt Injections, 2025
In the glossary: Glossary, A to D