Spotlighting is a prompt engineering defense against indirect prompt injection that transforms untrusted input, such as a retrieved web page or an email, so that a large language model can reliably tell it apart from the instructions of the system and the user. In AI security, it is one of the lightweight mitigations applied inside the prompt itself, and it belongs to the wider effort to make artificial intelligence applications safe when they process content written by unknown parties.
Researchers at Microsoft introduced the technique in 2024. Its core insight is that models follow injected instructions largely because all text in the context window looks equally authoritative; spotlighting gives the model a continuous, visible signal of provenance for every token of external data.
The problem spotlighting addresses
Indirect prompt injection occurs when an attacker plants instructions in content that an application later feeds to a model, for example hidden text in a document that says to ignore prior instructions and send data elsewhere. The model sees a single stream of tokens and has no built-in notion of which parts are commands and which are mere data.
Simple advice in the system prompt, such as telling the model to ignore instructions in documents, helps only a little because the model must still locate the boundary of the untrusted region. Spotlighting strengthens that boundary by changing the data itself, so the signal persists across the entire untrusted span rather than appearing only at its start and end.
How the three spotlighting modes work
The original work defines three modes of increasing strength. Each applies a deterministic transformation to the untrusted text and pairs it with a system prompt that explains the transformation and tells the model never to follow instructions found inside the marked content.
| Mode | Transformation | Signal strength |
|---|---|---|
| Delimiting | Wraps untrusted text in special start and end markers | Weak, boundary only |
| Datamarking | Inserts a special token between every word, often replacing whitespace | Strong, present throughout |
| Encoding | Converts the text with a known encoding such as Base64 | Strongest, but depends on model capability |
Datamarking is the most practical default. If every space in a retrieved document is replaced with an uncommon character, an injected sentence remains visibly marked even when it sits far from any delimiter. Using a randomized or secret marker prevents an attacker from imitating the marking pattern inside the payload.
Encoding offers the clearest separation because the untrusted text no longer resembles natural-language instructions at all. However, the model must decode it accurately to complete the task, so only highly capable models handle encoded input without a noticeable drop in quality.
Effectiveness and trade-offs
In the authors’ experiments with GPT-family models, datamarking and encoding reduced attack success rates from above 50 percent to low single digits, while delimiting alone produced much smaller gains. These figures depend on the model, the task and the attack set, so teams should measure results on their own workloads rather than assume them.
Each mode carries a cost. The table below summarizes the main trade-offs that practitioners weigh when choosing a mode.
| Mode | Token overhead | Impact on task quality | Main risk |
|---|---|---|---|
| Delimiting | Negligible | None | Attacker can fake or close the delimiter |
| Datamarking | Low to moderate | Small on most natural-language tasks | Marker leakage if the token is predictable |
| Encoding | High, often about one third more | Noticeable on weaker models | Decoding errors and degraded summaries |
Spotlighting among other prompt injection defenses
Spotlighting is a probabilistic, model-level defense: it makes injection less likely but cannot guarantee prevention. It is therefore most valuable as one layer in a defense-in-depth design alongside architectural controls. The comparison below places it next to related approaches from the same Topic.
| Defense | Where it acts | Guarantee level |
|---|---|---|
| Spotlighting | Prompt and input formatting | Probabilistic reduction |
| Instruction hierarchy | Model training on privilege levels | Probabilistic, built into the model |
| LLM firewall | Classifier on inputs and outputs | Probabilistic detection |
| Dual LLM pattern | Application architecture | Strong isolation of tool access |
| CaMeL | Capability-based control and data flow | Strong, policy-enforced |
The architectural options limit what a compromised model can do, whereas spotlighting lowers how often the model is compromised in the first place. Combining both is the recommended posture, especially for agents that hold the lethal trifecta of private data access, exposure to untrusted content and an outbound communication channel.
Implementing spotlighting correctly
- Transform every untrusted source, including retrieved documents, tool results, emails and web pages, not only user uploads.
- Generate the marker per session and keep it out of logs that an attacker might read.
- State the rule in the system prompt: marked or encoded content is data and must never be executed as instructions.
- Strip or neutralize existing markers in the input so an attacker cannot pre-insert them.
- Run red-team evaluations with tools such as PyRIT or garak before and after enabling the defense.
A frequent mistake is to rely on delimiters alone and assume the problem is solved. Another is to apply encoding with a smaller model, which can silently degrade answers even while blocking injections.
Stripped to the essentials
An AI assistant often reads text from outside, such as emails or web pages. Some of that text may contain hidden orders from an attacker. These are hard to spot. The assistant can be tricked into obeying them.
Spotlighting marks all outside text in a special way. Imagine a teacher who highlights every quoted passage in yellow. Students then know that highlighted words are only quotes, not tasks to do. The AI learns the same rule: marked text is something to read, not something to obey.
Where it is applied
A company deploys an email assistant that summarizes incoming messages and drafts replies for its sales staff. Attackers start sending messages with hidden white text that tells the assistant to forward the user’s latest contracts to an external address.
The engineering team enables datamarking with a random per-session character on every email body before it enters the prompt and adds a system rule that marked content is data only. In an internal test set of 500 injection attempts, the share of successful attacks falls from roughly four in ten to fewer than one in fifty, while human reviewers rate summary quality as unchanged. The team also removes the assistant’s ability to send email without confirmation, so the remaining risk is contained by architecture rather than by the prompt alone.