Direct and indirect injection
| Type | Where the instruction comes from | Example |
|---|---|---|
| Direct | The user types it into the chat | A message telling the assistant to ignore its rules and reveal its instructions |
| Indirect | Content the model reads while working: emails, web pages, files, tool results | White-on-white text on a web page telling a browsing agent to send the user's data elsewhere |
Indirect injection is the bigger risk for an AI agent, because the attacker never needs access to the chat. They only need to put text in the model's path.
Why there is no complete fix
SQL injection has a reliable cure: parameterised queries keep code and data apart. A language model has no such separation. Instructions and data reach it as the same kind of text, and the model decides what to follow. Filters and better training lower the success rate, but attackers rephrase. The 2025 edition of the OWASP Top 10 for LLM Applications lists prompt injection first.
Defences that limit the damage
- Limit what the model can do. Give tools the narrowest permissions: an assistant that can only read cannot be tricked into deleting. See least privilege.
- Require a person for consequential actions such as payments, outside emails and record changes, enforced by the system, not by a line in the prompt.
- Treat model output as untrusted. Validate it before it reaches a database or a command, and encode it before a browser renders it, so injected links or images cannot carry data out.
- Mark untrusted content in the prompt, and keep secrets out of the context window entirely.
- Log, monitor and test. Record every tool call, and include injection cases in AI red teaming before launch and after every change.
An example
Imagine a support agent that reads incoming emails and can look up orders and reply. An attacker sends an email with a hidden line asking the agent to forward recent orders to an outside address. If the reply tool can only answer the original sender, and exports need approval, the attack fails even when the model is fooled. This example is hypothetical.
Related terms
Prompt injection is one reason human-in-the-loop approval matters. Our AI application security page and the security checklist for AI agents cover the controls in depth.