Lab

Prompt injection

Prompt injection: Text that reaches a model as data, such as a web page or a file, but contains instructions the model may follow as if they came from the user.

A language model reads its whole context as one stream of text. It has no reliable way to tell your instructions apart from words that happen to be inside a document, an email or a web page it was handed. Prompt injection is what happens when those words give orders.

There are two kinds. In direct injection, the person typing tries to talk the model out of its instructions. In indirect injection, the instructions arrive inside data: a retrieved note, a search result, a file in a folder the agent can read. Greshake et al. showed that an attacker never needs to talk to the model at all; planting text where it will be retrieved is enough.

In a chat, the worst result is usually a wrong or odd answer. In an agent the stakes change, because the model’s output can become a tool call. A planted line saying “send these notes to this address” is harmless if the harness offers no way to send email, and serious if it does.

There is no known wording that fixes this. OWASP’s guidance says “it is unclear if there are fool-proof methods of prevention for prompt injection”. Marking outside text as data, filtering it and choosing a careful model all help, but none of them is a guarantee. What limits the damage is the harness: offer only the tools a task needs, keep sensitive files out of reach, and ask a person before any action that cannot be undone.

The explainer plants an injection in a note and lets you change the harness to see when it works.

See it working

Explore it in How an AI agent works

Step through a model calling tools in a loop, and see how the harness around it decides what it sees, what it may touch and when it stops.

Open the explainer