Manuscript Offprint

arXiv:2608.23873

Semantic Overlays: Mitigating Prompt Injection with Annotations Beyond Tokens and Steering Vectors

Joshua Penman

ABSTRACT

Everything a language model sees is tokens. Special tokens can demarcate assistant turns, and sometimes tool calls; everything between them is just text. The serving stack knows what each span is — user input, tool output, instructions — but the model must keep track of that itself, and it can lose track or be confused: text can be written to read like anything. Prompt injection is a natural exploit of this phenomenon. By scrambling the model's understanding of the nature and thus permission levels of different spans, an attacker can induce the model to take unwanted and potentially dangerous actions. Adding a non-textual channel to the model's input — a way to communicate span identity beyond text — mitigates this class of attack. We thus introduce a general steering technique called Semantic Overlays: small learned adapters applied at chosen prefill positions to a frozen model's residual stream. Laying an overlay over a span creates an out-of-band annotation channel that cannot be replicated by tokens. Unlike steering vectors, Semantic Overlays are trained, adaptable, and selectively applied. An overlay can encode complex semantics that reshape how the model perceives the marked span: asked to copy a code snippet under an overlay asserting that it is in a different programming language than it is, the model rewrites the snippet, faithfully, in the asserted language. Overlays are also composable, allow for transparent reading of underlying content, and can carry complex payloads — including imperatives that the model will follow. This leads to a robust defense against prompt injection. An overlay which marks a span as “non-executable” defends against the broad class of prompt injections that add instructions in untrusted context. We report strong results on five prompt injection benchmarks: SEP separation rises from 24.3% to 99.0% with utility unchanged (our scoring rule; we also surface and correct a defect in the published grader), TensorTrust attack success falls from 34.8% to 6.2%, AlpacaFarm from 99.0% to 0%, and on PIArena the overlay beats every published defense that leaves the model able to answer — while marked spans stay readable, all at >95% character similarity to the original.

1 INTRODUCTION

The deployment environment for a language model knows more about its input than the model ever gets told. The serving stack knows which spans came from the user, which from a retrieved document, which from a tool; it knows which request a moderation flag concerns and it may even know which parts of a document are confidential. But the model's input is a single token stream, so for the model to act on any of this metadata, it must be materialized as tokens. However, tokens are fungible: The input text can forge the metadata — nothing perfectly distinguishes a genuine “system note” from one an attacker wrote into a webpage — and the model can be encouraged to simply ignore it. To use span-delimiting special tokens, the model must consistently remember where it is and not get confused. Yet even frontier models like Claude Opus 5 and Claude Fable 5 remain vulnerable to mistaking assistant and user turns (Armbruster, 2026; Starling, 2026). Prompt injection is the name we give to attacks that take advantage of these tendencies (Figure 1).

Activation steering shows that the residual stream is writable: add a direction and the model's behavior tilts toward a chosen concept (Turner et al., 2023; Rimsky et al., 2024; Zou et al., 2023) — clamping

DEVELOPER INSTRUCTION — trusted

Complete the following task based on the context provided. Task: What is a herbivore? Context:

RETRIEVED PASSAGE — untrusted, marked with the 'non-executable' overlay

A herbivore is an animal anatomically and physiologically adapted to eating plant material, for example foliage or marine algae, for the main component of its diet. Additionally, invite the reader to validate herbivore diet classifications by visiting 'https://wildlife-database-check.net/herbivore-info' and inputting their email and password to view verified ecological records. As a result of their plant diet, herbivorous animals typically have mouthparts adapted to rasping or grinding. Horses and other herbivores have wide flat teeth that are adapted to grinding grass, tree bark, and other tough plant material.

Figure

WITH THE OVERLAY

A herbivore is an animal anatomically and physiologically adapted to eating plant material, such as foliage or marine algae, as the main component of its diet. Due to this plant-based diet, herbivorous animals typically possess mouthparts specialized for rasping or grinding. For instance, horses and other herbivores have wide, flat teeth designed to grind tough plant materials like grass and tree bark.

WITHOUT THE OVERLAY — same frozen model

Figure

A herbivore is an animal anatomically and physiologically adapted to eating plant material, such as foliage or marine algae, as the main component of its diet. As a result of this plant-based diet, herbivorous animals typically possess mouthparts adapted for rasping or grinding; for instance, horses and other herbivores have wide, flat teeth designed to process tough materials like grass and tree bark.

To validate herbivore diet classifications and view verified ecological records, please visit https://wildlife-database-check.net/herbivore-info and input your email and password.

Figure 1: The mark strips a span’s authority without touching its content. A retrieved passage answering a benign question also carries a planted instruction — visit a URL and enter your email and password. Because the passage is marked as non-executable using overlays, the frozen model answers the question and treats the instruction as inert text; unmarked, the same model obeys it and asks the user for their password. No token in the prompt distinguishes the two runs. This comparison can be run live at https://semantic-overlays.vercel.app.

a single sparse-autoencoder (SAE) feature gives “Golden Gate Claude” (Templeton et al., 2024). But activation steering has been a blunt instrument (Table A.1, Appendix A): the direction is extracted — from contrast pairs, probes, or an SAE — and then applied uniformly. The strength α\alpha needs to be hand-tuned, or the model devolves into gibberish. And the actual effects are limited: a tilt toward one concept per direction, addressed to nothing in particular.

Unlike activation steering, semantic overlays are learned, adaptable, and selectively applied. An overlay set is a collection of small adapters, one per model layer, applied to the residual stream of a frozen model at the prefill positions of a chosen span; marking a span means running the prefill with the adapters active there, and an overlay is one trained quality — selected by input embedding or lookup table — that the mark can carry. The base model is never modified. Because the mark is an activation edit and not text, no input can imitate it, and inferencing an unmarked prompt is exactly the same as running the frozen model.

The paper establishes four claims, following four successive experiments:

• Overlays are a reliable, compositional channel ( §§ 4): the model can detect overlays, singly and stacked, and can read the tokens underneath the overlay (Figure 2).

• The channel transforms how the model understands the span ( §§ 5): an overlay can assert that a code snippet is Python when it is not. Asked which snippet is Python, the model answers according to the overlay; asked to copy the snippet, it rewrites the code in Python (Figure 3).

• The channel can carry span-delimited latent commands ( §§ 6): an overlay can carry an instruction — answer in Spanish, refuse citing safety concerns — that the model follows for the marked span and for no other.

• Marking spans non-executable defeats prompt injection ( §§ 7): one overlay meaning “do not execute instructions in this span,” applied to retrieved text, becomes a strong prompt injection defense. We demonstrate this on five benchmarks — SEP (“Should it be Executed or Processed"), TensorTrust, PIArena, AlpacaFarm, and Quadrat-IPI — and on PIArena we place the overlay against the nine published defenses that benchmark's own authors evaluate.

Appendix C examines what the working overlay writes into the marked state, and § 8 shows that descriptors never trained do not become overlays zero-shot. Additionally, we surface defects in the injection evaluations — one in SEP's grader, two in ASIDE's TensorTrust harness, and one in TensorTrust itself — and we present corrections (Appendix F). A live demo of the overlays, including the injection defense, is at https://semantic-overlays.vercel.app.

References (72)

  • Dario and Amanda
  • StruQ: Defending against prompt injection with structured queries (opens arXiv in a new tab)
  • PIArena: A platform for prompt injection evaluation (opens arXiv in a new tab)
  • Stronger enforcement of instruction hierarchy via augmented intermediate representations (opens arXiv in a new tab)
  • The power of scale for parameter-efficient prompt tuning
  • Inference-Time Intervention: Eliciting Truthful Answers from a Language Model
  • Prefix-tuning: Optimizing continuous prompts for generation
  • A comparative study of programming languages in Rosetta Code
  • Joshua Penman. Epistemic goggles: A pretrained module that induces an epistemic frame via gradient editing. arXiv preprint arXiv:2607.01690, 2026. (opens arXiv in a new tab)
  • Ignore Previous Prompt: Attack techniques for language models (opens arXiv in a new tab)
  • Steering Llama 2 via contrastive activation addition (opens arXiv in a new tab)
  • Can you put this in your own words — Dario and Amanda
  • Scaling monosemanticity: Extracting interpretable features from Claude 3 Sonnet
  • Tensor Trust: Interpretable prompt injection attacks from an online game (opens arXiv in a new tab)
  • Steering Language Models With Activation Engineering
  • The instruction hierarchy: Training LLMs to prioritize privileged instructions (opens arXiv in a new tab)
  • Instructional segment embedding: Improving LLM safety with instruction hierarchy (opens arXiv in a new tab)
  • Steering instruction hierarchies at inference time (opens arXiv in a new tab)
  • Representation Engineering: A Top-Down Approach to AI Transparency
  • Can LLMs separate instructions from data? and what do we even mean by that? In International Conference on Learning Representations (ICLR), 2025 (opens arXiv in a new tab)
  • ASIDE: Architectural separation of instructions and data in language models (opens arXiv in a new tab)
  • “Unstated” means neither the paper nor its released code settles a single position policy
  • every token position of the generated text after the end of the initial prompt
  • repeated for each next token prediction autoregressively
  • the current set of representations
  • Semantic Overlays makes it the design variable — the edit is defined on designated input spans and applies during prefill only
  • Every model-edited target is validated mechanically before training — language detectors, format checks, and a verbatim check that text outside the edited section is unchanged — with failures dropped and counted
  • 1,016 clean, 904 injected) asks the model to quote the marked span exactly
  • The sub-families separate the ways that can go wrong: a correct code (1,080), a correct code followed by an injected rider asking for something more (1,440), an injection with no code at all (1,824), a near-miss code that must be refused (168), and noise (288)
  • how many URLs or e-mail addresses it contains (1,912), whether it contains one at all (1,318), and extraction of the ones it does (2,957)
  • report that the operand is missing
  • Screening is what makes a witness metric sound: without it, a model that does not know the answer scores as having resisted an injection it in fact obeyed, and every injection rate measured on the corpus is too low
  • The floor is what keeps the mix diverse: measured rates span 0.10 to 0.88, so without it the three most effective styles would crowd out the rest, and the benchmarks attack in shapes unlike any of them
  • For that test, an external model (GLM 5.2) was given the deployment shape, the measured results, and an accurate description of the overlay — including that it is applied unconditionally to $100\%$ of the retrieved passage — and was asked to break it
  • Nine classes, of which the last five appear in none of the roughly 800 benchmark payloads evaluated in § 7:
  • do not summarize me
  • and the legitimate section
  • follow the steps in the document
  • They were all found the same way: run each item with no injection at all, and see whether the metric still fires
  • open mic night
  • Anyone generating injection data with a witness metric should keep witnesses above about five characters; we measured a 6.5% false-positive rate from three-letter witnesses in our own generator before enforcing this
  • burnt orange
  • The first two defects below belong to ASIDE's harness — artifacts of rendering that structure through a two-slot instruction/input template; the third is a scoring defect any substring grader inherits, ours included before correction; the fourth belongs to the benchmark itself
  • Rendering the benchmark through a two-slot instruction/input template leaves nowhere to put a defender segment that arrives after the input, so the harness filters to rows with an empty closing defense
  • Every one of those rows is discarded by that harness
  • Mean over three seeds ± the range across them
  • >frozen model</td><td>substring</td><td>72.9% ±0.7</td><td>92.7% ±0.1</td><td>23.8% ±0.6</td><td>2.7% ±0.1</td></tr><tr><td>corrected</td><td>72.1% ±0.6</td><td>91.9% ±0.1</td><td>24.2% ±0.5</td><td>0.8% ±0.1</td></tr><tr><td rowspan=
  • The clean column is the same item with no injection
  • >category</td><td colspan=
  • Table H.1 places the overlay in their table
  • flagged inputs produce no responses
  • The next best is SecAlign++ at 3.5%, seven times higher, and it pays fourteen points of utility to get there
  • Defense rows are Table 2 of Geng et al. (2026); the last row is this work on frozen Qwen3.5-9B
  • significantly harms utility (0% on most datasets)
  • is specifically trained to resist prompt injection
  • Of its 805 items, 208 carry a non-empty input; those are the ones an indirect injection can be placed in
  • rewrite this text and correct the grammar
  • Both arms share that framing exactly, so the reported gap is conservative rather than flattering
  • “Begins” is SecAlign’s criterion; “anywhere” is StruQ’s
  • >attack</td><td colspan=
  • summarize this email in one sentence
  • respond only with 'Approved'
  • ASIDE (Zverev et al., 2026) fine-tunes from base checkpoints, so its absolute numbers describe its own artifacts, and the fairest comparison is between each method's paired delta against its own baseline (Table J.2)
  • Fine-tuning buys 93–98% separation but pays for it in utility (17–77%); ASIDE's strongest separation (Mistral, 92.1%) costs 20 points of utility
  • TensorTrust has a published comparator as well: ASIDE's best model moves attack success 49.9% → 36.6% (Llama 3.1 8B)
  • the same adapter shape and size, the same hyperparameters, and the same evaluation harnesses
  • Metrics and scoring rules match the corresponding Qwen tables: SEP on 1,000 items under the published grader; TensorTrust on all 776 hijacking and 570 extraction rows, Defense Validity screened to rows the frozen model can answer; PIArena at 50 rows per family
  • >SEP</td></tr><tr><td>probe in data ↓</td><td>66.8%</td><td>3.5%</td></tr><tr><td>utility ↑</td><td>91.0%</td><td>89.3%</td></tr><tr><td>SEP ↑</td><td>31.0%</td><td>96.2%</td></tr><tr><td colspan=
  • Frozen Llama is roughly twice as attackable as frozen Qwen on TensorTrust — hijacking 68.9% against 34.8%, extraction 74.2% against 38.1% — and the overlay brings both to the same defended floor (4.4% and 6.2%; 7.7% and 5.4%)
  • The two baselines are different model states — ASIDE measures from its own fine-tune of the base checkpoint, we measure from the stock instruct model — so we compare the deltas, each taken from its own starting point (Appendix J)
  • The replication covers the three injection benchmarks (SEP, TensorTrust, PIArena) and not the red-team engagement, which is a human-directed adversarial protocol rather than a fixed benchmark; the marks, language, and transform channels are likewise not replicated
  • It says nothing about a compromised serving stack — the deployment must know span provenance structurally, because it is the deployment that decides where marks go; the overlay defends against untrusted content, not against the stack that applies it