AI & LLMs/Explainer

Prompt injection: why language models follow the wrong instructions

A language model cannot reliably tell your instructions apart from text it happens to read. How direct and indirect prompt injection work, why agents raise the stakes and which defences help.

High impact5 min readDevelopers, Admins, Small businessUpdated 31 October 2026

Fingerprint of this page: sha256("/ai-security/prompt-injection/")

A language model receives one stream of text. The instructions written by the developer, the question typed by the user, a web page it fetched, an email it was asked to summarise: all of it arrives in the same context window as tokens of the same kind. is what happens when text from one of those sources is followed as an instruction even though nobody with authority wrote it.

What prompt injection is

The OWASP GenAI Security Project describes it as input that changes the behaviour or output of a model in ways nobody intended. The comparison with SQL injection is tempting but misleading. SQL injection has a clean fix: parameterised queries keep code and data in separate channels, so data can never become a command.

A language model has no such channel. The UK National Cyber Security Centre makes this point directly: models do not enforce a security boundary between instructions and data, so the problem may never be fully solved the way SQL injection was. That shapes every defence below. You cannot filter your way to safety; you limit what a confused model is able to do.

Direct and indirect injection

Direct injection comes from the person typing. They try to talk the model out of its rules, make it reveal its or produce content the operator wanted to prevent. The main victim is the operator of the application, and the attacker is someone who already has access to it.

is the more serious variant. The instructions sit in content the model processes on someone else's behalf, often hidden from the human: white text on a white background, an HTML comment, document metadata, a line in a calendar invite or text embedded in an image. The user asks an innocent question, and the model meets the planted text along the way. Typical entry points:

  • Web pages that a browsing assistant reads or summarises.
  • Incoming emails and attachments processed by a mail assistant.
  • Shared documents, tickets and PDFs in a knowledge base used for (RAG).
  • README files, issues, code comments and package documentation read by coding agents.
  • Responses from tools and APIs that are fed back into the model.
  • Images, screenshots and audio in multimodal systems.

Why agents raise the stakes

A chatbot that can only answer can, at worst, give a wrong or embarrassing answer. An is different: it can call tools, read files, send messages, query databases or run commands. Now an injected sentence can turn into an action carried out with the permissions of the user or the service account behind the agent.

The risky combination has three parts: access to private data, exposure to content from outsiders and some way to send information out. An assistant that reads your inbox, can open any web page and can write emails has all three. Remove any one of them and the worst case shrinks considerably.

Leaking data does not require a send button. Many chat interfaces render the model's output as Markdown or HTML. If injected text persuades the model to build an image address that carries private data in its path or query string, the interface fetches that image automatically and the data travels to a server the attacker controls. Nobody has to click anything. A link works the same way, only it needs one click.

The defence belongs in the interface, not in the prompt: do not load remote images from model output, or allow only a short list of domains you trust; show link targets in full; and sanitise any HTML the model produces before it reaches a browser.

Where it sits in the OWASP Top 10 for LLM Applications

The current 2025 edition of the OWASP Top 10 for LLM Applications lists prompt injection as LLM01, the first entry. Several other entries describe what prompt injection leads to or what makes it worse:

EntryRiskConnection to prompt injection
LLM01Prompt InjectionThe root problem described in this article
LLM02Sensitive Information DisclosureA common goal of an injection: getting data out
LLM05Improper Output HandlingModel output passed unchecked to a browser, shell or database
LLM06Excessive AgencyToo many tools or permissions turn an injection into real actions
LLM07System Prompt LeakageDirect injection often aims to reveal hidden instructions

OWASP Top 10 for LLM Applications, 2025 edition, as listed on the project page in October 2026.

Defences that limit the damage

OWASP states plainly that it is unclear whether fool-proof prevention exists. So treat prompt injection as a residual risk and design for containment. The measures work best in layers:

  • Least privilege for tools: give each agent only the tools and scopes it needs, read-only where possible, with its own short-lived credentials rather than a shared admin token.
  • Human approval for consequential actions: sending, paying, deleting, publishing and changing permissions should wait for a person who sees the full action, not a summary written by the model.
  • Separate trusted and untrusted content: mark external content clearly in the prompt and lower the agent's privileges once untrusted text is in its context. Delimiters make attacks harder, not impossible.
  • Deterministic checks on output: validate formats in code, allow-list destinations such as domains and recipients, and never pass model output straight into a shell, a SQL query or a web page.
  • Logging and monitoring: keep the prompts, retrieved content, tool calls and failed calls, so you can spot probing and reconstruct what happened.
  • Adversarial testing: test with injection-style content before release and after every change to tools or data sources.

Be sceptical of any product that promises to stop prompt injection completely. Filters and classifiers reduce the success rate, and that is worth having, but they are one layer. The design decisions about tools, permissions and approvals decide how bad a successful attack can be.

Treat everything the model reads as if a stranger wrote it, because sometimes one did.

Sources and further reading

  1. OWASP Top 10 for LLM Applications 2025genai.owasp.org
  2. OWASP GenAI Security Project: LLM01:2025 Prompt Injectiongenai.owasp.org
  3. NCSC blog: Prompt injection is not SQL injection (it may be worse)ncsc.gov.uk

General information, checked on 31 October 2026. Test changes on one system first and keep a way back. Found something outdated? Tell the editors.

FAQ

Questions readers ask

Can a better system prompt stop prompt injection?

It helps a little and costs nothing, but it is not a security boundary. The system prompt is text in the same context as the attack, so a well-crafted injection can still override it. Put the real limits in code and permissions.

Is prompt injection the same as jailbreaking?

They overlap. Jailbreaking usually means a user trying to bypass a model's safety rules, which is a form of direct injection. Prompt injection is the broader term and includes instructions planted in content the model reads on someone else's behalf.

Are local models safer against prompt injection?

No. Running a model on your own hardware changes where your data goes, not how the model treats instructions. A local agent with access to your files and a web browser has the same weakness as a hosted one.

Does this matter if I only use a chat app?

Yes, as soon as the app browses the web, reads your files or connects to mail and calendars. Be selective with connectors, and switch off those you do not need.

Keep reading

More from AI & LLMs