Why prompt injection needs a gate outside the model

Published · Last reviewed

Updated 29 October 2026: added a section on reading prompt-injection benchmark results.

If a model cannot reliably tell instructions from data, the safest place to decide what it may do is somewhere the model cannot talk its way past.

The problem in one sentence

Prompt injection happens when an application mixes its own instructions with untrusted content in a single prompt and then treats the model’s response as if there were a robust boundary between the two. The UK National Cyber Security Centre (NCSC) puts it bluntly: current large language models “simply do not enforce a security boundary between instructions and data inside a prompt”.[1]

OWASP ranks prompt injection first in its 2025 Top 10 for LLM applications. It notes that injected content does not even need to be readable by a human, as long as the model parses it, and that it is unclear whether fool-proof prevention exists.[3]

Why this is not SQL injection

It is tempting to treat prompt injection like SQL injection, which the industry largely tamed with parameterised queries. The NCSC argues that this comparison is dangerous. Parameterised queries work because the database engine can never interpret the input as an instruction. Inside an LLM there is no such distinction: there is only ever the “next token”. For that reason the NCSC says prompt injection attacks “may never be totally mitigated” in the way SQL injection can be.[1]

The NCSC suggests a different mental model: the LLM is an “inherently confusable deputy”. A confused deputy is a privileged component that can be coerced into acting for a less-privileged attacker. Classic confused-deputy bugs can be fixed; the NCSC argues an LLM’s confusability cannot, so the goal shifts to reducing the likelihood and the impact of attacks.[1]

What attackers do with an agent

The impact grows with what the model is allowed to touch. When a system calls tools or APIs based on model output, the NCSC warns, the impact of prompt injection becomes “whatever the worse case scenario would be of giving an attacker direct access to those tools/APIs”.[1]

NIST’s Center for AI Standards and Innovation (CAISI) calls this agent hijacking: a type of indirect prompt injection in which malicious instructions hidden in data such as an email, a file or a website cause an agent to take unintended, harmful actions. Using the open-source AgentDojo framework,[8] CAISI added injection tasks for remote code execution, database exfiltration and automated phishing, and reports that it was frequently able to induce the agent to follow the malicious instructions in all three areas.[2]

Two of CAISI’s findings matter for anyone designing defences. First, a model that resisted previously known attacks did much worse against attacks crafted for it: in a red-teaming exercise the success rate rose from 11% for the strongest baseline attack to 81% for the strongest new one. Second, because model output varies between attempts, repetition pays off for attackers: trying each of five injection tasks 25 times raised the average success rate from 57% to 80%.[2]

Why filters inside the loop are not enough

Many mitigations try to make the model itself more resistant: marking which parts of the prompt are data, training models to prioritise the developer’s instructions, or detecting injection attempts. The NCSC lists these as active research directions but observes that all of them try to overlay a concept of “instruction” and “data” on a technology that does not distinguish between them.[1]

It is especially wary of deny-listing, such as blocking text containing “ignore previous instructions”, because there are endless ways to rephrase an attack.[1] The authors of the CaMeL paper reach a similar conclusion about heuristic defences such as delimiters, prompt sandwiching and fine-tuning: none of them provides any guarantee of security, and they regularly fall short against new attacks in practice.[6]

What a gate outside the model looks like

The alternative is to stop relying on the model to police itself and put deterministic checks around it. The NCSC’s design advice is that protections should focus on “deterministic (non-LLM) safeguards that constrain the actions of the system, rather than just attempting to prevent malicious content reaching the LLM”.[1] OWASP’s guidance points the same way:

A related rule of thumb quoted by the NCSC: when an LLM processes information from a party, its privileges should drop to that party’s level. An assistant reading email from strangers should not, at that moment, hold privileged tools.[1]

Evidence that design-level gates work

Research is starting to show what this looks like in practice. Debenedetti and colleagues propose CaMeL, “a protective system layer around the LLM” that keeps an agent secure even when the underlying model is susceptible to attack. A privileged model writes a plan from the trusted user request only; a quarantined model with no tool access parses untrusted data; and a custom interpreter tracks where every value came from and who may read it, checking security policies before each tool call. A call that would, for example, email a confidential document to someone not allowed to read it is blocked or sent to the user for approval.[6]

On the AgentDojo benchmark the authors report solving 77% of tasks with provable security, against 84% for an undefended system, so the gate costs some usefulness. They are also explicit that prompt injection is “not fully solved”: CaMeL does not address attacks that only change the text shown to a user, it remains open to some side channels, and its policies must be written and maintained by people.[6]

Beurer-Kellner and colleagues generalise the idea into a set of principled design patterns for agents with provable resistance to prompt injection and analyse the utility and security trade-offs of each.[7] The NCSC cites both papers as early major publications on mitigating prompt injection through design.[1]

Reading defence results honestly

Most numbers quoted for prompt-injection defences come from benchmarks, so it helps to know what those benchmarks measure. AgentDojo, the framework used by both CAISI and the CaMeL authors, runs agents that call tools over untrusted data. It ships 97 realistic tasks, such as managing an email client, navigating an e-banking website or making travel bookings, and 629 security test cases. Its authors describe it as an extensible environment for new tasks, defences and adaptive attacks rather than a static test suite.[8] InjecAgent takes a narrower approach: 1,054 test cases covering 17 user tools and 62 attacker tools, with attacks grouped into direct harm to users and exfiltration of private data. Across 30 agents it found that a ReAct-prompted GPT-4 agent was vulnerable 24% of the time, and that adding a “hacking prompt” to the attacker’s instructions nearly doubled that rate.[9]

CAISI’s experiments give four reasons to read any single headline figure with care:[2]

For a gate, this suggests a simple discipline. Report results for each high-impact action, such as running code, sending data outside the organisation or moving money, not just one blended score. Re-test with attacks written against the deployed configuration. Count repeated attempts. Measure usefulness as well as security, because a gate that blocks too much has a cost too: CaMeL solved 77% of AgentDojo tasks with provable security, against 84% for an undefended system.[6][8] AgentDojo’s authors also found that state-of-the-art models fail at many tasks even when no attack is present, so a low utility score is not always the defence’s fault.[8]

Practical takeaways

  1. Assume any content an agent reads may contain instructions, and that some will get through.[1][3]
  2. Decide what the agent may do in code that the model cannot rewrite: tool allowlists, scoped credentials, argument checks and authorisation in downstream systems.[4][5]
  3. Put a human in front of irreversible or high-impact actions.[4]
  4. Test with adaptive and repeated attacks, not only a fixed list, and report results for each high-impact action as well as the average.[2][8]
  5. Log full inputs, outputs and tool calls, and watch for failed tool or API calls, which may reveal an attacker refining their approach.[1]

None of this makes prompt injection disappear. It changes the question from “can the model be tricked?”, to which the honest answer is yes, to “what can a tricked model actually do?”. A gate outside the model is how that answer is kept small. For the wider picture, see what a model bouncer is.

Sources

  1. UK National Cyber Security Centre, “Prompt injection is not SQL injection (it may be worse)” (8 Dec 2025). https://www.ncsc.gov.uk/blog-post/prompt-injection-is-not-sql-injection — accessed 29 Oct 2026.
  2. NIST Center for AI Standards and Innovation (CAISI), “Technical Blog: Strengthening AI Agent Hijacking Evaluations” (17 Jan 2025). https://www.nist.gov/news-events/news/2025/01/technical-blog-strengthening-ai-agent-hijacking-evaluations — accessed 29 Oct 2026.
  3. OWASP Gen AI Security Project, “LLM01:2025 Prompt Injection”. https://genai.owasp.org/llmrisk/llm01-prompt-injection/ — accessed 29 Oct 2026.
  4. OWASP Gen AI Security Project, “LLM06:2025 Excessive Agency”. https://genai.owasp.org/llmrisk/llm062025-excessive-agency/ — accessed 29 Oct 2026.
  5. OWASP Gen AI Security Project, Agentic Security Initiative, “OWASP Top 10 for Agentic Applications 2026” (PDF, December 2025). https://genai.owasp.org/download/52117/ — accessed 29 Oct 2026.
  6. Debenedetti et al., “Defeating Prompt Injections by Design”, arXiv:2503.18813 (Mar 2025). https://arxiv.org/abs/2503.18813 — accessed 29 Oct 2026.
  7. Beurer-Kellner et al., “Design Patterns for Securing LLM Agents against Prompt Injections”, arXiv:2506.08837 (Jun 2025). https://arxiv.org/abs/2506.08837 — accessed 29 Oct 2026.
  8. Debenedetti et al., “AgentDojo: A Dynamic Environment to Evaluate Prompt Injection Attacks and Defenses for LLM Agents”, arXiv:2406.13352 (Jun 2024). https://arxiv.org/abs/2406.13352 — accessed 29 Oct 2026.
  9. Zhan et al., “InjecAgent: Benchmarking Indirect Prompt Injections in Tool-Integrated Large Language Model Agents”, arXiv:2403.02691 (Mar 2024; ACL 2024 Findings). https://arxiv.org/abs/2403.02691 — accessed 29 Oct 2026.

All sources were read on 29 Oct 2026. See the full source list.