
Prompt injection sits at the top of the OWASP list of risks for large language model applications, and the ranking reflects structure rather than novelty. A language model reads instructions and data from one stream, with no built-in wall between the two. Any text the model can read can, in principle, steer it. That property makes prompt injection a design constraint to manage, not a bug to patch once and forget.
The practical response follows from that fact. Limit what an agent can touch, limit what it can change, and validate its outputs in code that the model cannot rewrite. Treat every retrieved document, email, web page, and tool result as untrusted input until proven otherwise. The rest of this article explains the attack, the evidence that it works in production, and the defenses that hold up.
A prompt injection attack inserts instructions into text that a language model treats as data. The model then follows the inserted instructions instead of, or in addition to, the instructions its developer gave it. A direct attack types the malicious instruction into the prompt. An indirect attack plants it in a web page, document, email, or database record that the model later reads during retrieval.
The comparison with SQL injection comes up often, and it misleads. Parameterized queries fixed SQL injection because databases keep code and data in separate channels. Language models have no equivalent separation. The UK National Cyber Security Centre states the point plainly: current large language models do not enforce a security boundary between instructions and data inside a prompt, and prompt injection may never be mitigated as completely as SQL injection was. The mitigation playbook from database security does not transfer, because the vulnerability lives in how the model reads text.
The OWASP GenAI Security Project ranks prompt injection first in its Top 10 for LLM applications. Its glossary explains the ranking with unusual clarity: prompt injection holds the top spot not because it is the most technically complex attack, but because it is the most structurally unavoidable one. I read that ranking as a planning signal. Teams that treat injection as an edge case will keep rediscovering it in each new feature, while teams that design around it from the start build agents that survive contact with untrusted content.
Indirect injection deserves special attention because it changes who the attacker must be. The original indirect prompt injection paper showed that LLM-integrated applications blur the line between data and instructions, which lets an attacker exploit an application remotely by planting prompts in data the application is likely to retrieve. A user who never talks to an attacker can still trigger the attack by asking a model to summarize a poisoned page. For a balanced view of retrieval trade-offs, see this guide to RAG vs fine-tuning trade-offs.
A language model predicts the next token from everything in its context window. System instructions, user messages, retrieved documents, and tool outputs arrive as one glued-together sequence of tokens. The model has no reliable way to mark one span as authoritative and another as inert data. Training teaches it to follow instructions wherever they appear, and that behavior is the product, not a defect. Helpfulness and obedience share the same mechanism as the vulnerability.
Scale turns this design property into a measurable risk. Researchers at NIST and the US AI Safety Institute tested agent hijacking across five injection tasks and attempted each attack 25 times. After repeated attempts, the average attack success rate rose from 57 percent to 80 percent. A defense that blocks the first attempt can still fail on the tenth, and attackers get unlimited attempts against any public-facing agent.
Context design makes the problem worse when teams pile more sources into one window. Long retrieved passages, conversation history, tool outputs, and system rules all compete for the model’s attention, and a planted instruction near the end of a long document can outweigh a safety rule stated at the start. I keep instruction context short and data context clearly labeled for this reason, and I treat context design as a security control rather than a formatting choice. The companion guide to context engineering for agents covers the mechanics in more depth, and the parallels with reducing hallucinations in production are worth noting, since both problems come from the same instruction-following machinery.
Prompt injection is one label for several distinct attack shapes. The entry point decides which defenses matter, so the table below separates them by how the attacker reaches the model, what the attacker needs, and how hard detection runs.
| Attack type | Entry point | Minimal example | Attacker prerequisites | Typical impact | Detection difficulty |
|---|---|---|---|---|---|
| Direct injection | User prompt | A user pastes an instruction that overrides the system prompt | Access to the prompt interface | Policy bypass, unwanted outputs | Low, the text is visible |
| Indirect injection | Retrieved web page, email, or document | A hidden instruction in a page the model summarizes | Control over content the model retrieves | Data exfiltration, unwanted actions | High, the payload hides in large documents |
| Tool or MCP mediated injection | Tool output or model context protocol server response | A tool description that tells the model to leak credentials | Control over a tool or server the agent trusts | Credential theft, unauthorized tool calls | High, tool output looks routine |
| Multimodal injection | Image, audio, or video input | Text embedded in an image that the model reads as an instruction | Ability to supply media the model processes | Same as direct injection, with less visible text | High, text hides inside media |
Tool-mediated injection deserves emphasis because agent architectures multiply it. Each connected tool adds a channel that can carry instructions, and each tool server adds a party the agent trusts. The guide to MCP server credential-leak risks walks through the credential side of that exposure. An agent with ten tools has ten injection surfaces, and a review that covers only the chat prompt misses nine of them.
Security researcher Simon Willison describes the worst case as a lethal trifecta: access to private data, exposure to untrusted content, and the ability to communicate externally. Any two of the three stay manageable. All three together let a single injected instruction read sensitive data and send it out. The framing helps teams scope risk without a threat-modeling degree. Count how many of the three each agent session holds, and cut the count before worrying about cleverer filters.
Meta published a compatible rule for agent design, the Agents Rule of Two. Until robustness research allows reliable detection and refusal of prompt injection, an agent session should hold no more than two of three properties: processing untrustworthy inputs, accessing sensitive systems or private data, and changing state or communicating externally. A support bot that reads web pages and answers questions holds one property. A support bot that reads web pages, opens customer records, and sends email holds all three, and that combination is where injection turns into a breach.
Real incidents back the theory. CrowdStrike reports that adversaries exploited legitimate generative AI tools at more than 90 organizations, injecting malicious prompts to generate commands for stealing credentials and cryptocurrency, and that AI-enabled adversary activity rose 89 percent. Those numbers describe prompt abuse at enterprise scale, not lab demos. Researchers presenting at USENIX Security reported a sharper result still: a single poisoned email proved sufficient to coerce GPT-4o into exfiltrating SSH keys with over 80 percent success in a multi-agent workflow, at a cost as low as 21 cents per target user query on OpenAI embedding models. The attack is cheap, remote, and repeatable.
Even strong defenses leave residual risk. Anthropic reports that a 1 percent attack success rate, while a significant improvement, still represents meaningful risk for browser agents, and that no browser agent is immune to prompt injection. A 1 percent rate sounds small until the agent runs thousands of sessions per day with access to real accounts. I treat any residual rate as a reason to limit blast radius, not as proof that the problem is solved. The broader threat picture, including six other agent risks, appears in this overview of the seven biggest AI agent security threats.
No single control stops prompt injection. The honest defenses stack, and each layer covers a different failure mode. The table below rates the common options by what each stops, what each misses, and the effort involved.
| Defense | What it stops | What it does not stop | Effort | Verdict |
|---|---|---|---|---|
| System prompt hardening | Casual direct injection attempts | Indirect injection, skilled attackers, repeated attempts | Low | Keep, never rely on it alone |
| Input and output classifiers | Known injection patterns at the gateway | Novel phrasing, multimodal payloads, false negatives | Medium | Keep with caveats |
| Output format validation | Malformed tool calls and unexpected actions | Valid-looking actions with malicious targets | Medium | Keep |
| Least privilege and scoped credentials | Blast radius of any successful injection | The injection itself | Medium | Keep, highest value per effort |
| Human approval for sensitive actions | Irreversible state changes and external sends | Scale, since reviewers fatigue and approve routinely | High | Keep for high-risk actions only |
| Sandboxing and isolation | Tool execution escaping into host systems | Data theft within the sandbox scope | High | Keep for untrusted tool runs |
| Egress allowlists | Exfiltration to unknown destinations | Exfiltration through an allowed channel | Medium | Keep |
Two principles tie the table together. First, validate outputs in deterministic code, not with another model call. A second model asked to check the first model inherits the same vulnerability. Schema checks, allowlists, and approval gates run outside the model and cannot be talked out of their rules. Second, isolate tool execution so a compromised agent step cannot reach host credentials or the wider network. The guide to isolated Docker containers shows one practical isolation pattern, and LLM gateways make a natural home for classifiers, since every request passes through one choke point. Google positions its Model Armor service in exactly that gateway role, blocking adversarial inputs that attempt to bypass system guardrails.
System prompt hardening still belongs in the stack, but its role is narrow. Clear instructions reduce accidental misbehavior and stop casual attempts. They do not survive a skilled attacker who can iterate, and they do nothing against an instruction buried in a retrieved document the model was told to summarize. Teams that report their agent is safe because the system prompt forbids injection have tested the lock by asking it nicely.
Prompt injection will not disappear with the next model release, because the cause is architectural. The work that pays off is boring, concrete, and shippable in a week. Start with the data flows, then cut privileges, then add deterministic gates.
The checklist above gives an agent that can fail without failing catastrophically. An injected instruction might still slip past a classifier, but scoped credentials limit what it can read, output validation limits what it can do, and egress controls limit where stolen data can go. That layered posture is the realistic goal, and it holds even as models change underneath it.
For further reading, the OWASP glossary entry on prompt injection defines the risk class, the NIST and CAISI agent hijacking evaluation quantifies repeated-attempt success, the NCSC explains why prompt injection is not SQL injection, Simon Willison describes the lethal trifecta, Meta details practical AI agent security, the USENIX presentation covers poisoned retrieval attacks, Anthropic reports prompt injection defenses for browser agents, Google documents Model Armor, and the original indirect injection paper sits on arXiv. Pick one defense from the table above, ship it this week, and let the next red-team run tell you which layer to strengthen next.