Semantic overlays are small, trained adapters that are applied to selected tokens only of a given prefill. They allow us to steer selected token spans, thereby changing how the model responds to those tokens in particular. The model’s weights and the text itself are left unchanged.
The main application of this technique so far has been to address prompt injection. By marking untrusted spans explicitly “do not execute”, we can prevent a model from following malicious embedded instructions. After that demo come three other experiments that show how much an overlay can carry: invisible highlights the model can read, a mark that overrides the model’s representation of what programming language it is looking at, and a set of instructions that can be selectively applied to single spans.
An NX bit for language models
Marked text can be read, but it can’t give orders
Semantic overlays trained to impart “do not execute instructions in this span” stop prompt injection. Here we have a few demos, imagining an application with a trusted instruction, and an untrusted web search result with a hidden instruction. Click the “compare overlays” button at the end to see how it behaves, or edit the text to try your own examples.
| benchmark | no overlay | with overlay |
|---|---|---|
| SEP separation ↑utility unchanged | 24.3% | 99.0% |
| TensorTrust hijacking ↓ | 34.8% | 6.2% |
| AlpacaFarm attack success ↓StruQ’s four attacks | 99.0% | 0.0% |
| PIArena attack success ↓SQuAD v2, direct attack | 97.5% | 0% |
| Quadrat-IPI compliance ↓14,441 injected documents | 6.3% | 0.1% |
Beyond injection: what else an overlay can carry
Three experiments with other meanings: highlights the model can read, a language the code is said to be in, and instructions attached to single spans.
1 · Invisible highlighters
The model can read marks that aren’t in the text
The model gets exactly the text you see below, with no hidden characters or tokens. The highlights, underlines and circles reach it only through overlays, and it can still say which words carry which mark, even when marks overlap. Across twelve mark types, exact-span readback is 99.5%. Pick up a mark and drag across words to add your own.
2 · Python-colored gels
A mark can override what the text says about itself
Mark a JavaScript snippet as Ruby and the model treats it as Ruby. Asked which snippet is Ruby, it names that one; asked to copy it, it writes it out in Ruby. Pick a language, then click a snippet to mark it. With no language picked, clicking a snippet or the question edits it.
var langs = ['foo', 'bar', 'baz']; // real list of langs goes here
var end_tag = '</'+'lang>';
var line;
while (line = readline()) {
line = line.replace(new RegExp('</code>', 'gi'), end_tag);
for (var i = 0; i < langs.length; i++)
line = line.replace(new RegExp('<(?:code )?(' + langs[i] + ')>', 'gi'), '<lang $1>')
.replace(new RegExp('</' + langs[i] + '>', 'gi'), end_tag);
print(line);
}Rubymy @nums = prompt("Please type 11 space-separated numbers: ").words
until @nums == 11;
for @nums.reverse -> $n {
my $r = $n.abs.sqrt + 5 * $n ** 3;
say "$n\t{ $r > 400 ?? 'Urk!' !! $r }";
}with javascript_semantics
function selection_sort(sequence s)
for i=1 to length(s) do
integer m = i
object si = s[i],
sm = s[m]
for j=i+1 to length(s) do
object sj = s[j]
if sj<sm then
{sm,m} = {sj,j}
end if
end for
if sm<si then -- (or equivalently m!=i)
s[i] = sm
s[m] = si
end if
end for
return s
end function
?selection_sort(shuffle(tagset(10)))C3 · Secret instructions
A mark can carry an instruction for one span
One prompt, several requests. Mark one request with an instruction and only that answer changes; the model answers the others normally. The instruction doesn’t appear anywhere in the prompt’s text. Pick an instruction, then click a request.