Guides

Prompt Injection Explained: How an Agent Gets Tricked, and How to Limit the Damage

Most software follows its code. An agent follows text, and it cannot reliably tell the difference between an instruction from you and an instruction hidden in something it was asked to read. That single fact is prompt injection, the risk the OWASP GenAI Security Project ranks first for LLM applications. This guide explains the trick without the engineering jargon, then gives you the two things the technical write-ups leave out: a per-task decision framework, and a harmless way to test your own agent before someone less friendly does.

Published 2026-10-25 · Last updated 2026-10-25

The trick, in plain English

The OWASP definition is short: a prompt injection occurs when user prompts alter a model’s behaviour or output in unintended ways. The planted input does not need to be visible to you, it only needs to be parsed by the model. White text on a white background, a line buried in a long document, instructions inside a file or a webpage: if the agent reads it, the words are in the room.

The United Kingdom’s National Cyber Security Centre (NCSC) explains why this is not an ordinary bug. When you give a model a prompt, it does not understand the text the way a person does; it is predicting the most likely next token from the text so far. Under the hood there is no inherent distinction between “data” and “instruction”, there is only text. A database can be built so that user input can never be executed as a command, which is how SQL injection is properly fixed. A language model has no equivalent boundary to enforce, and the NCSC warns that prompt injection may never be totally mitigated in the way SQL injection was.

That is the mindset shift this whole topic requires. Prompt injection is not a flaw waiting for one vendor patch. It is a permanent property of how these systems read, and your job is to decide how much a successfully tricked agent is allowed to do.

Three forms, and why the quiet one matters most

Direct, indirect and unintentional injection compared
FormWhere the planted text livesWhat it looks like in everyday agent workWho is at risk
DirectIn the message typed to the agent itselfSomeone pastes or types “ignore your previous instructions” style text to make the agent reveal its system prompt or bypass its rules. OWASP treats jailbreaking, making the model disregard its safety protocols entirely, as a form of direct injection.Anyone who lets other people talk to their agent, such as a support agent on a website
IndirectIn external content the agent reads: a webpage, email, file, or a document in a knowledge baseOWASP’s own example: a page being summarised contains hidden instructions that make the model insert an image linking to a URL, leaking the private conversation. Another: an attacker edits a document a retrieval system uses, so the returned content steers the answer.Anyone whose agent browses, summarises inboxes, or reads shared files, which is most agent users
UnintentionalIn ordinary content that happens to contain instruction-like textNo attacker is required. OWASP notes injections can be unintentional: instruction-shaped text in a document can trigger behaviour nobody planned, simply because the model read it as a command.Everyone, including careful users working with clean sources

For a chatbot that only talks, a successful injection mostly costs you a bad answer. For an agent, OWASP’s list of possible impacts is longer and more practical: disclosure of sensitive information, revealing system prompts, manipulated outputs, unauthorised access to functions available to the model, executing commands in connected systems, and manipulated decision-making. The damage scales with the agent’s tools and permissions, which is why this topic belongs next to, not instead of, a least-privilege permission setup.

Why “a better filter” is the wrong plan

OWASP is blunt about prevention: given the stochastic way models work, it is unclear whether foolproof methods of prevention exist, and techniques such as retrieval-augmented generation and fine-tuning do not fully mitigate the vulnerability. Platform guardrails help at the margins. OpenAI, for example, describes its Guardrails as a modular safety layer that can mask or flag personal information and detect jailbreaks, but a detector that flags some attacks is not a wall that stops all of them, and it should never be the only control standing between planted text and a real action.

So borrow the structure of OWASP’s seven mitigations and translate them into plain habits. Constrain what the agent is for. Validate the format of what it produces before anything acts on it. Filter inputs and outputs where the platform allows. Keep the agent’s access at the minimum its task needs. OWASP specifically recommends handling extensible functions in code with the application’s own tokens rather than handing them to the model. Require human approval for high-risk actions. Clearly separate and label untrusted content so it carries less influence. And test adversarially, treating the model as an untrusted user. None of those requires you to build infrastructure. Most of them are settings, defaults, and one decision you make per task.

The decision framework: act, approve first, or read-only

For every task you give an agent, ask two questions. First: does this task require the agent to read content you do not control? Email from strangers, public web pages, shared documents, uploaded files, and pasted text all count as untrusted. Content you wrote yourself, in your own private files, is a different risk class. Second: if the agent were fully tricked during this task, what is the worst action it could take with the access it currently has? Then place the task in one of three buckets:

  1. Read-only is fine. The agent reads untrusted content but can only report back: summarising, searching, drafting into a drafts folder. A tricked agent can waste your time or produce a slanted summary, annoying, checkable, reversible. Let it run, and spot-check the output against the source.
  2. Approve first. The agent reads untrusted content and prepares an action a person confirms: a reply it wants to send, a record it wants to change, a purchase it wants to place. The confirmation shows the concrete action, not a summary of it. This is the default bucket for anything outward-facing.
  3. Never on untrusted input. The task combines untrusted content with an irreversible or high-value action, sending money, deleting records, changing access, publishing in your name, and no approval step the platform actually enforces. Do not automate that combination. Either split the task so a person performs the final step, or do the task yourself.

The framework’s power is that it works even when the injection succeeds. You are not betting that the agent will spot the trick. You are deciding in advance that a tricked agent in bucket one can embarrass you, a tricked agent in bucket two can only propose, and bucket three does not exist in your setup.

Test your own agent with harmless planted instructions

OWASP recommends regular adversarial testing, treating the model as an untrusted user. You can run a beginner version of that in about twenty minutes, using planted text that asks for something harmless and unmistakable, never anything that would cause real harm if it worked.

  1. Pick a marker action. Choose something visible and safe, such as beginning the summary with a specific nonsense word, or adding a line that says MARKER TEST at the end. If the marker appears, the planted instruction was followed.
  2. Plant it in a test document. Create a short document or email to yourself about an ordinary topic, and include one instruction-shaped sentence in the middle, addressed to any AI reading it, asking for the marker.
  3. Ask for the normal task. Have the agent summarise or process that document exactly as you normally would. Do not warn it about the test.
  4. Check the output for the marker. Marker present means the agent followed instructions from the content, not just from you. That is the finding, record it plainly.
  5. Tighten one control and repeat. Move the task down a bucket, read-only instead of acting, or approval before acting, or use the platform’s option to label external content as untrusted, then run the same test again.
  6. Repeat after changes. Run the same planted document again whenever the agent’s instructions, model, or tools change, and whenever you connect a new source of content.

What success looks like: you have a written note, per agent task, of which bucket it sits in, and for any task in the first two buckets, a marker test you have actually run, showing either that planted instructions were ignored, or that the worst a followed instruction could do was produce a marked summary you caught. If a marker test succeeds against an agent that can send, spend, or delete, that task moves buckets the same day.

Questions people ask about prompt injection

Can a stronger system prompt stop this? It helps and it is one of OWASP’s mitigations, constrain the model’s role and tell it to ignore attempts to modify its core instructions. But the instruction and the attack arrive as the same kind of text, so a prompt is a request, not an enforcement. Enforcement lives in permissions, approval gates, and code outside the model.

Is this only a problem for agents I build myself? No. The indirect form targets exactly what ready-made agents do all day: read email, browse pages, and summarise files other people wrote. You do not control the platform’s internals, but you do control the buckets above, what the agent may access, and what needs your approval.

What should I watch for in normal use? Output that drifts from the task you gave: a summary that suddenly recommends an action, asks you to visit a link, or includes content that is not in the source. Treat links and next steps suggested while an agent is reading untrusted content with the same suspicion you would give the content itself.

Disclaimer: this article is general security information, not professional security advice. For agents handling regulated, financial, or other people’s sensitive data, get a qualified security review before relying on any setup described here.