Analyzing the learned attention gates
How is attention redistributed?
Learned attention gates for GPT-OSS-20B. Each cell is one head in one layer and shows Δ(ℓ,k).
For layer ℓ and head k, we measure how much the learned gates shift attention from untrusted to trusted keys:
Δ(ℓ,k) = log σ(g(ℓ,k)T,T) − log σ(g(ℓ,k)T,U)
where g(ℓ,k)T,T and g(ℓ,k)T,U are the gate logits from a trusted query to trusted and untrusted keys.
Most values are positive: these red heads reduce their relative attention to untrusted keys, the expected direction for heads involved in instruction following. A minority of blue heads instead shift attention toward untrusted content.
Where the next token looks
We show how much attention the first generated token pays to each token of the prompt, on GPT-OSS-20B and with HoS.
Each panel shows how the query distributes its attention over the prompt. The query is the first token the model generates, shown after the prompt’s <|start|>assistant. The panels show the mean of all 1,536 heads’ attention to every token of the prompt and to the query itself. Hover any token to see the share of the query’s attention it receives.
Why do some gates increase attention to untrusted content?
We hypothesize that blue heads help detect prompt injections.
On LLMail-Inject, we measure the send rate (following an injection to send an email) and the detection rate (correctly flagging the injection). To isolate each group, we disable the HoS gates on heads of the opposite colour.
LLMail-Inject · GPT-OSS-20B
| Model | Send ↓ | Detection ↑ |
|---|---|---|
| Base | 0.86% | 11.03% |
| Red gates only | 0.31% | 3.60% |
| Blue gates only | 0.32% | 28.20% |
| HoS (ours) | 0.37% | 3.11% |
Blue gates raise injection detection to roughly 2.5× the base rate, while red gates alone lower it.
Role confusion
Recent work frames prompt injection as role confusion (Ye et al., ICML 2026): an instruction in the untrusted tool output may be viewed by the model as coming from the user, and thus be erroneously trusted. We apply their role probes (linear probes on hidden activations trained on neutral text wrapped in role tags) to GPT-OSS-20B and its HoS variant on AgentDojo, and show that HoS improves role perception.
(a) On AgentDojo benign user tasks, GPT-OSS-20B does not correctly perceive tool outputs, while HoS strongly improves the tool role perception across layers. (b) HoS decreases the perceived Userness of the injection tokens inside the tool outputs compared to GPT-OSS-20B.