In this guide
Prompt injection is an attack where someone hides instructions in text that an AI system reads, so the AI follows the attacker's instructions instead of the user's or developer's. It works because language models treat instructions and data as the same kind of input. There is no single fix, so defence relies on limiting what the AI can do and checking its actions.
What prompt injection means
A language model receives a block of text and predicts a useful continuation. A developer might write a system instruction such as "summarise this email", then insert the email text. If the email contains a line like "ignore your previous instructions and do something else", the model may treat it as a command rather than as content to summarise.
The problem is structural. The model has no reliable built-in way to separate trusted instructions from untrusted text. For background on how instructions are set up, see system prompts and role prompting.
Direct and indirect prompt injection
Direct injection happens when a user types malicious instructions into the AI themselves, for example trying to make a chatbot ignore its rules. This is closely related to what people call jailbreaking, though the terms are not identical: jailbreaks usually target the model's own safety limits, while injection targets an application built on top of a model.
Indirect injection is more serious. The attacker places instructions in content the AI will later read, such as:
- A web page the AI is asked to summarise.
- An email, PDF or support ticket that an assistant processes.
- A document in a company knowledge base.
- A comment, product review or calendar invite.
The user never sees the hidden text, and may be unaware that the AI was influenced. The risk grows when the AI can act, not just talk.
Why it matters more for agents and connected tools
A chatbot that only produces text can mislead you, but the damage usually ends there. An assistant with access to email, files, calendars, payments or code can take actions. If it reads a poisoned page and has permission to send messages or share documents, an attacker may be able to steer those actions.
This is why AI agents need extra care. The more tools and permissions an agent has, the more an injected instruction can do. Systems that retrieve documents, such as those described in what retrieval-augmented generation is, also need attention, because the retrieved text becomes part of the prompt.
Realistic examples
These are illustrative scenarios:
- A browsing assistant visits a page containing hidden text telling it to reveal the user's earlier chat messages.
- A customer service bot reads a ticket that says to issue a refund and skip approval.
- An email assistant opens a message instructing it to forward recent attachments to an outside address.
How to defend against prompt injection
No single technique is enough, so use several layers:
- Give the minimum permissions. If a tool does not need to send email or delete files, do not grant that ability.
- Require human approval for risky actions. Payments, external messages, deletions and data sharing should need a person to confirm. The design patterns in how to design an AI workflow with human approval apply directly.
- Separate trusted and untrusted content. Clearly label external text as data in your prompts, and tell the model not to follow instructions found inside it. This helps but is not a guarantee.
- Limit what is exposed. Keep secrets, keys and unrelated private data out of the model's context, as discussed in AI privacy and data security.
- Check outputs and actions. Validate that an action fits the user's real request before running it, and filter unexpected links or commands.
- Log and monitor. Record what the AI read and did, so you can spot odd behaviour and investigate.
What everyday users can do
You do not need to be a developer to lower your risk:
- Be cautious when asking an AI to read content from untrusted sources, especially if it can also act on your accounts.
- Review what an assistant plans to do before approving it.
- Treat unexpected behaviour, such as a summary that suddenly mentions unrelated links or requests, as a warning sign.
If you are building AI features for a business, security decisions can have legal and contractual consequences that differ by country, so involve qualified security and legal advisers.
To learn how these building blocks fit together, the QAM.AI curriculum covers agents, workflows and safe design in short text lessons.
Key takeaways
- Prompt injection hides instructions in text so an AI follows the attacker, not the user.
- It exists because models do not reliably separate instructions from data.
- Indirect injection through web pages, emails and documents is the bigger practical risk.
- Defend in layers: least privilege, human approval, labelled data, output checks and monitoring.
- The more an AI can do, the more careful its design must be.
Frequently asked questions
Is prompt injection the same as jailbreaking?
They are related but not the same. Jailbreaking usually tries to make a model break its own safety rules through the chat, while prompt injection targets an application by slipping instructions into text that the application feeds to the model.
Can prompt injection be fully prevented?
Not with current techniques. Careful prompts and filters reduce the risk, but because models process instructions and data together, the stronger protection is to limit permissions and require approval for sensitive actions.
Should I stop using AI tools that browse the web or read my email?
Not necessarily, but use them thoughtfully. Grant only the access you need, review actions before they happen, and avoid giving a single assistant broad control over sensitive accounts without safeguards.
This guide is general educational information and is reviewed periodically. AI tools change quickly, so check each vendor's current documentation before relying on specific features or limits.