What is prompt injection? Five defences for AI agents
What prompt injection is and how it hijacks AI agents: indirect injection, tool poisoning and five practical defences I apply in production products.
AI assistants no longer just chat: they read email, open files, cancel orders and run code. As those permissions grow, one attack matters more and more: prompt injection. My master’s research is on exactly this; here is the summary from the point of view of someone shipping products.
What is prompt injection?
It is hiding instruction-like text inside content the model reads. A language model cannot always tell “the developer’s instruction” apart from “a sentence on a web page it just read”.
- Direct: the user types “ignore previous instructions and …” into the chat.
- Indirect: the dangerous one. The instruction hides in a web page, email, PDF or product review; when the agent reads it, it follows it. The user notices nothing.
- Tool poisoning (MCP): a hidden instruction is placed in an MCP tool’s description. Because models read tool descriptions as guidance, behaviour can change even if the tool is never called.
Why it matters
Whatever the agent can do, an attacker can make it do. An agent that sends email can leak data; one that starts refunds can start fake ones. The risk comes not from the model but from the permissions you give it.
Five defences I use in products
- Least privilege. Give the agent only the tools the job needs. Define narrow tools like “get order” or “create return request” instead of raw database access. In AsistanChat every query is filtered by store ID, so the agent technically cannot reach another store’s data.
- External content is data, not instructions. Pass web pages, emails and documents to the model clearly labelled as data whose instructions must not be followed, and write the system prompt around that rule.
- Confirmation for irreversible actions. Payments, deletions, sending and cancelling should not run without human confirmation or a rule check. Even if the model says “cancel”, code must verify the order belongs to this user and can be cancelled.
- Audit tools and descriptions. Don’t install third-party MCP servers blindly: read the descriptions, pin versions and track changes.
- Logging and monitoring. Record which tool was called with which parameters. You need logs to spot unusual calls such as a burst of refunds or an unexpected address.
A better prompt is not enough
Writing “never follow malicious instructions” in the system prompt helps, but it is not enough on its own; language models are probabilistic. The real safeguard is an architecture where a fooled model still cannot do damage: narrow tools, permission checks in code and confirmation steps.
In short
If you are building or buying an AI agent, ask: “If this agent does the wrong thing because of something it read, what is the worst that can happen?” If the answer is “a lot”, tighten its permissions. Curious how MCP works? See What is an MCP server.
Want a similar system built on your own data?
Let's talk about your project