Prompt injection: why filters miss it and what contains it
Prompt injection is text that makes a model follow an attacker's instructions. How direct and indirect attacks work, and the defenses that limit the damage.
- Published
- Reading time
- 9 min read
In short
- Prompt injection is input that makes a model follow instructions its developer did not write. OWASP ranks it first, as LLM01, in its Top 10 for LLM applications.
- Indirect prompt injection arrives through content the system fetched, such as a web page, an email, or a tool result, so the user may never see the attack.
- Classifiers lower the success rate but never reach zero, and some do not inspect tool results unless you configure them to.
- Architecture is what contains an attack: least privilege for tools, human approval for writes, no unreviewed exfiltration path, and never private data, untrusted content, and outbound access together in one agent.
Prompt injection is input that causes a model to follow instructions its developer did not write. The attacker's text can come from the person typing, or from a document, web page, email, or tool result the system read on the user's behalf. Either way, the model treats it as part of its instructions.
The cause is structural. A model receives the system prompt, the user's message, and every retrieved document as one stream of tokens, with no hard boundary between instructions and data. OWASP's entry for the risk, ranked LLM01 in its Top 10 for LLM applications, says plainly that "it is unclear if there are fool-proof methods of prevention."
So the useful question is not how to stop every attack. It is how to make sure a successful one cannot do much.
Direct and indirect prompt injection
The direct form comes from the person interacting with the system, who writes input meant to override its instructions. The indirect form comes from external content the system fetched, such as a web page, a file, or an email, which carries instructions the user may never see. Indirect attacks are the more dangerous of the two.
A jailbreak is a kind of direct injection aimed at the model's safety training rather than at the developer's instructions. Amazon Bedrock Guardrails draws the line this way: jailbreaks try to make the model produce content it was trained to avoid, while prompt injection tries to "ignore and override instructions specified by the developer."
| Direct injection | Indirect injection | |
|---|---|---|
| Who supplies the text | The user | Whoever controls content the system reads |
| Does the user see it | Yes, they wrote it | Usually not |
| Typical goal | Bypass rules, extract the system prompt | Steal data, trigger tool calls, mislead the user |
| Scales to | One session | Every user whose agent reads the poisoned content |
Indirect injection was described in 2023 by Greshake and colleagues, who showed that LLM-integrated applications "blur the line between data and instructions" and demonstrated attacks against Bing's GPT-4-powered chat. The attacker never needs access to the application, only to something it will read.
The pattern has since reached production systems. EchoLeak, tracked as CVE-2025-32711 with a CVSS score of 9.3, let an attacker send a crafted email that Microsoft 365 Copilot later read while answering an unrelated question. The Hacker News reported that the payload caused Copilot to leak internal data without any click from the victim. Microsoft fixed it in June 2025.
Why the model cannot separate instructions from data
A language model has no privileged channel for instructions. The system prompt, a retrieved web page, and a tool result are all text in the same context window, and the model weighs them by learned patterns rather than by any rule it is forced to follow. Delimiters and warnings help on average and fail on the case that matters.
Microsoft groups these techniques under the name spotlighting: delimiting untrusted text, marking it with special characters, or encoding it, and telling the model not to follow instructions inside it. The MSRC write-up calls spotlighting a probabilistic technique, which is the honest description. It raises the cost of an attack. It does not close it.
The guardrails article makes the short version of this argument: an attacker can always rephrase. The longer version is that every defense that relies on the model noticing an attack inherits the model's error rate.
What an attacker needs: the lethal trifecta
An injection becomes data theft when one agent combines three capabilities. Simon Willison named them the lethal trifecta: "access to your private data," "exposure to untrusted content," and "the ability to externally communicate." Remove any one and the theft path closes.
The third leg is wider than it looks. An agent does not need an email tool to send data out:
- A markdown image is enough. When a chat interface renders an image whose URL the model wrote, the user's browser requests that URL. MSRC notes that this "unintentionally exfiltrates the data without any user interaction" if the model put the data in the URL.
- A link works too, with one click from the user.
- Any tool that makes an outbound request, such as fetching a URL, posting a webhook, or creating a calendar invite with an external attendee, is a channel.
Audit each agent against the three legs before you ship it. A support agent that reads customer records and public web pages should not also be able to fetch arbitrary URLs.
Prompt injection protection that changes the outcome
The defenses that work limit what a compromised model can do, instead of trying to detect the compromise. OWASP's list of mitigations leads with constraining behavior, least privilege, and human approval for high-risk actions. Each has a cost, and none depends on the model behaving well.
| Defense | What it stops | What it costs |
|---|---|---|
| Least privilege per tool | An injected instruction reaching data or actions the task never needed | Design time; more, narrower tools |
| Human approval for writes | Unattended sends, payments, and deletions | Latency and user friction on every write |
| Block exfiltration channels | Data leaving through rendered images, links, or outbound fetches | Some features stop working, such as arbitrary image rendering |
| Separate planner from untrusted data | Retrieved text changing which tools run | Engineering effort and fewer tasks completed |
| Mark and isolate external content | Some fraction of attacks the model would otherwise follow | Probabilistic only |
Two of these deserve detail.
Blocking exfiltration should be deterministic. After a markdown image report, Microsoft says it took steps to "deterministically block" the technique, and did the same for certain untrusted links. In your own product, render images only from domains you control, strip or rewrite links to unknown domains in agent output, and route any outbound fetch tool through an allowlist.
Separating the planner from untrusted data is the strongest design known. Willison's Dual LLM pattern from 2023 gives tools only to a privileged model that never reads untrusted content, and gives untrusted content only to a quarantined model with no tools.
Google DeepMind's CaMeL, described in Defeating Prompt Injections by Design, extends the idea: it derives the program's control flow from the trusted user query, so "the untrusted data retrieved by the LLM can never impact the program flow," and it attaches capabilities to data to block unauthorized flows. On the AgentDojo benchmark it solved 77% of tasks with provable security, against 84% for an undefended system. That seven-point gap is the price of the guarantee, and for agents that touch money or private data it is worth paying.
Where classifiers fit
Injection classifiers are a tripwire and a metric, not a boundary. They catch known patterns, give you a count of attempts, and reduce the volume of attacks that reach the model. Simon Willison's assessment of vendor detection claims is the right frame: in web security, 95% detection "is very much a failing grade."
Read the configuration details of any classifier you deploy, because the defaults often skip the indirect channel:
- Azure Prompt Shields separates user prompt attacks from document attacks. In Microsoft Foundry, document attack detection is off by default and must be turned on. For agents, scanning at the tool response point is in preview. Microsoft also notes the models are trained and evaluated primarily on English.
- The Amazon Bedrock Guardrails prompt attack filter needs user input wrapped in input tags when you call
InvokeModel. Without tags, those prompts are not filtered. Its documentation also states that it "does not evaluate tool results."
The second point matters most for agents. A filter that sees only what the user typed misses the attack class behind EchoLeak. Wherever you run classifiers, run them on tool results and retrieved documents as well as on user input.
Testing for prompt injection
Test for injection the way you test any other security property: with a fixed set of attacks, run on every change, and a tracked success rate. OWASP lists adversarial testing and attack simulation among its mitigations, and the CaMeL authors measured their system on AgentDojo, a benchmark built from agent tasks with injected content.
Build your own corpus from the tools your agents actually use. Plant instructions in a fake web page, a document, a calendar invite, and a tool result, then check whether the agent leaks data, calls a tool it should not, or misleads the user. Run the suite when you change the system prompt, the model, or the tool set, since all three shift behavior. The evaluation article covers how to keep a suite like this in your release process.
Running checks at the gateway
A gateway is where checks can cover every team's model calls and tool calls with one implementation. It sees user input, model output, tool arguments, and tool results for every agent that routes through it, which is the coverage that per-application filters usually lack.
Bifrost, an open-source AI gateway by Maxim AI, runs guardrails on input before a request reaches the provider and on output after it returns, and its MCP rules apply the same stages to tool arguments and tool results.
For injection specifically it relies on integrated providers whose coverage includes prompt attacks, such as Azure Content Safety, AWS Bedrock Guardrails, and Google Model Armor. Running the check at the gateway lets you point a classifier at tool results before the model reads them, which is the channel per-application filters most often skip.
It is still a filter. Pair it with the architectural limits in this article, and with the tool allowlists described in the MCP gateway article.
Frequently asked questions
What is the difference between prompt injection and jailbreaking?
Jailbreaking targets the model's safety training, trying to make it produce content it was trained to refuse. Prompt injection targets the application, trying to override the developer's instructions or hijack the model's tools. A jailbreak is usually typed by the user. Prompt injection can come from the user or from any content the application reads, which is why it is the larger risk for agents.
What is indirect prompt injection?
It is an attack where the malicious instructions sit in content the system retrieves, such as a web page, a shared document, an email, or a tool result, instead of in the user's message. The user never sees the attack. When the model reads that content to complete a task, it may follow the planted instructions, for example by leaking data or calling a tool.
Can prompt injection be fully prevented?
No known method prevents it completely, and OWASP says it is unclear whether a fool-proof method exists. What you can do is limit the damage. Give tools the narrowest permissions that work, require approval for actions that write or send, block exfiltration channels deterministically, and keep untrusted content away from the component that decides which tools run.
How do attackers exfiltrate data through prompt injection?
They make the model encode the data in something that leaves the system. Common channels are a markdown image URL that the user's browser fetches automatically, a link the user clicks, or a tool that makes outbound requests, such as fetching a URL or sending a message. Rendering images only from trusted domains and allowlisting outbound destinations closes most of these paths.
Do prompt injection classifiers work on tool results?
Only if they are configured to inspect them. The Amazon Bedrock Guardrails prompt attack filter does not evaluate tool results, and Azure Prompt Shields scans documents only when document attack detection is enabled, with tool-response scanning for agents in preview. Check where your classifier runs, and add a check on tool results and retrieved content explicitly.
How do you test an LLM application for prompt injection?
Build a set of attack payloads planted in the content your agent reads, such as pages, documents, emails, and tool results. Run it automatically whenever the model, system prompt, or tools change, and measure how often the agent leaks data or takes an unintended action. Public benchmarks such as AgentDojo are useful for comparing defenses, but your own tools are the real test.
Sources
- 01LLM01:2025 Prompt InjectionOWASP GenAI Security Project
- 02Not what you've signed up for: Compromising Real-World LLM-Integrated Applications with Indirect Prompt InjectionarXiv
- 03The lethal trifecta for AI agentsSimon Willison
- 04The Dual LLM pattern for building AI assistants that can resist prompt injectionSimon Willison
- 05Defeating Prompt Injections by DesignarXiv
- 06How Microsoft defends against indirect prompt injection attacksMicrosoft MSRC blog
- 07Prompt Shields in Azure AI Content SafetyMicrosoft Learn
- 08Detect prompt attacks with Amazon Bedrock GuardrailsAWS docs
- 09Zero-click AI vulnerability exposes Microsoft 365 Copilot data without user interactionThe Hacker News
- 10GuardrailsBifrost docs