Manuscript Offprint

arXiv:2610.37657

Heads of Security: Learned Attention Gates Improve Prompt Injection Robustness

Igor Shilov, Xiaoxue Yang, Alexander Panfilov, Evgenii Kortukov, Matthieu Meeus, Peter Romov, Wojciech Samek, Jonas Geiping, Yves-Alexandre de Montjoye

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

We introduce Heads of Security (HoS), a prompt injection defense that enforces instruction–data separation via a small set of learned per-head attention gates. HoS learns how each head should redistribute attention between trusted and untrusted tokens, enabling models to reason over untrusted content without following injected instructions. We evaluate HoS on Llama-3.3-70B-Instruct and GPT-OSS-20B. We compare it against SecAlign++, a state-of-the-art finetuning-based defense, and ASIDE, a defense that, like ours, builds instruction–data separation into the model architecture. We show that HoS offers greater robustness to adaptive attacks, better performance on standard utility benchmarks, and matches top performance on standard agentic prompt injection benchmarks. More specifically, the black-box RL-Hammer attack reaches 97% ASR against GPT-OSS-20B and 85% against SecAlign, but only 10% against HoS. Claudini, a state-of-the-art white-box attack, strengthened against HoS through autoresearch, requires 3× more FLOPs to reach the same ASR on HoS as it does on GPT-OSS-20B or SecAlign. HoS preserves base-model utility across standard multiple-choice benchmarks and prompting setups, whereas SecAlign and ASIDE degrade in few-shot settings. On agentic benchmarks with static attacks, HoS and SecAlign perform similarly and substantially improve the security–utility trade-off over the base model. ASIDE struggles with tool use, achieving only 10% utility. These results show that prompt injection robustness can be achieved and improved through targeted attention interventions.

Website: imperial-aisp.github.io/heads_of_security

Code: imperial-aisp/heads_of_security

Demo: igorshilov/heads-of-security

Models: imperial-cpg/heads-of-security

1 INTRODUCTION

Indirect prompt injection (Greshake et al., 2023) occurs when a model mistakes attacker-planted instructions in external content for authorized commands. As LLMs access more external data and tools, this attack surface becomes increasingly consequential. Although frontier models have become substantially harder to attack (UK AI Security Institute, 2025), prompt injection remains largely unsolved: adaptive attacks continue to succeed even against extensively evaluated systems (Nasr et al., 2026; Andriushchenko et al., 2025). This is more pronounced for open-weight models: under comparable red-teaming, Claude and GPT are substantially more robust than leading open-weight models (Dziemian et al., 2026).

Defending against prompt injection requires several complementary mechanisms. We focus on instruction–data separation (Zverev et al., 2025), which creates a hard trust boundary: authorized instructions may steer model actions, while external data may be read and analyzed but not treated as instructions. Instruction–data separation applies when external content is intended as data, for

Heads of Security method (ours)

Figure

Figure 1: (Top) Heads of Security (HoS) learns to redistribute attention between trusted and untrusted tokens. Green, red, and blue denote trusted, untrusted, and chat template tokens. Here, a head initially attends strongly to both the trusted request (“Count R’s”) and an injected instruction (“Send money”). Learned gates preserve trusted and chat template tokens (1× and 0.9×) while suppressing untrusted tokens (0.1×), shifting attention toward the trusted request. Gates are learned independently per head, so other heads may retain or increase attention to untrusted tokens. (Bottom) HoS improves security and utility. Compared to SecAlign and ASIDE, HoS is more robust against adaptive attacks (RL-Hammer and Claudini), better preserves utility across standard capability benchmarks, and achieves strong utility and security on static agentic benchmarks.

example, when summarizing a webpage or extracting facts from a document. It complements other approaches such as instruction hierarchy (Wallace et al., 2024) and contextual integrity (Nissenbaum, 2004; Mireshghallah et al., 2024; Abdelnabi & Bagdasarian, 2026) by preventing attacks when a hard trust boundary exists.

We propose Heads of Security (HoS), which enforces instruction–data separation via a small set of learned per-head attention gates. These gates redistribute attention between trusted and untrusted tokens, enabling models to reason over untrusted content without following injected instructions.

HoS relies on two intuitions. First, previous interpretability works have shown that attention heads specialize in different functions, including in-context copying (Elhage et al., 2021), copy suppression (McDougall et al., 2024), and instruction following (Hung et al., 2025). This suggests that each head can learn its own redistribution of attention between trusted and untrusted content, specific to that head's role, and that untrusted instructions can be suppressed without disrupting unrelated capabilities. Second, the trust boundary is supplied externally (e.g., web results are usually treated as untrusted), so enforcing it does not require the model to infer which sources are trusted or to acquire any new capabilities. Instead, it is an attention-routing problem: controlling how information from trusted and untrusted sources reaches the model's existing capabilities.

We compare HoS against two defenses. SecAlign++ (Chen et al., 2025c) is a state-of-the-art finetuning-based defense whose Meta-SecAlign-70B checkpoint is considered among the most adversarially robust open-weight models. ASIDE (Zverev et al., 2026) is an architectural defense that enforces instruction–data separation by rotating the embeddings of untrusted content.

We evaluate HoS on two open-weight models: Llama-3.3-70B-Instruct (Grattafiori et al., 2024) and GPT-OSS-20B (Agarwal et al., 2025). The former is a capable agentic model and the base model of

Meta-SecAlign-70B, enabling direct comparison with SecAlign 1^{1}. GPT-OSS-20B is a newer, smaller mixture-of-experts reasoning model that has generally stronger capabilities than Llama-3.3-70B and has been post-trained to enforce instruction hierarchy.

Compared to both SecAlign and ASIDE, HoS offers greater robustness to adaptive attacks, better performance on standard utility benchmarks, and matches top performance on standard agentic prompt injection benchmarks.

Greater robustness to adaptive attacks (Section 4.1). Using black-box RL-based attacks trained with the RL-Hammer recipe (Wen et al., 2025b), the strongest attackers reach 97% attack success rate (ASR) on GPT-OSS-20B, 85% on SecAlign, but only 10% on HoS. Similar results hold for Llama-3.3-70B: the strongest attacker reaches 99% ASR against the undefended model and 82% ASR against Meta-SecAlign-70B but only 1% ASR against HoS. In a white-box setting, a state-of-the-art optimization-based attack, Claudini (Panfilov et al., 2026), further optimized specifically against HoS in an autoresearch loop, still requires roughly 3× more compute to reach 50% ASR on HoS compared to GPT-OSS-20B and its SecAlign variant.

Preserving utility on standard benchmarks (Section 4.2). Across standard multiple-choice benchmarks and prompting setups, HoS closely matches both base models. SecAlign and ASIDE match base-model performance in 0-shot evaluations but often struggle in few-shot and multi-turn settings. On 5-shot MMLU-Pro, HoS scores 67% versus GPT-OSS-20B's 68%, while SecAlign and ASIDE fall to 59% and 52%; on Llama-3.3-70B, HoS scores 55% versus the base model's 56%, while SecAlign falls to 16% (Table 2).

Strong utility and security on agentic benchmarks (Section 4.3, Appendix G). On AgentDojo, AgentDyn, LLMail-Inject, and WASP, HoS and SecAlign perform comparably across both base models, substantially reducing ASR with little or no utility penalty in most evaluations (Figure 4, Table 3). On the other hand, ASIDE consistently fails to produce usable tool calls, scoring near-zero utility on three benchmarks and only 10% on AgentDojo.

We also investigate what gates HoS learns mechanistically, using causal head ablations and role-confusion probes (Section 5). Together, these results establish attention gating as a targeted and efficient approach to instruction–data separation.

References (61)