Manuscript Offprint

arXiv:2610.28988

Attention-based Classification for Indirect Prompt Injection

Amelia Kawasaki, Stefan Lee

Abstract

Indirect prompt injection (IPI) attacks, in which adversarial instructions are embedded in external data processed by a language model, pose a significant threat to the integrity of deployed LLM agents. Attention Tracker (Hung et al., 2025) is a recently proposed white-box detection method that identifies prompt injection attacks by monitoring how a model's attention is distributed between user task tokens and data tokens, claiming dataset-agnostic detection via a scalar focus score threshold. In this paper, we provide the first evaluation of Attention Tracker in a realistic agentic IPI setting using the AgentDojo benchmark, finding that the dataset agnosticism claim does not hold. We find that in agentic environments, long structured tool outputs subvert the fundamental assumptions Attention Tracker makes about attention that the method depends on and produces near-chance detection on AgentDojo across most model families. We propose AttnDA, an extension replacing the scalar threshold with a Fisher Linear Discriminant Analysis classifier over the per-head focus score vector, and evaluate both methods in a cross-dataset setting spanning four benchmarks. AttnDA improves detection performance across agentic and tool-integrated benchmarks, though transfer to AgentDojo remains challenging regardless of classifier choice. A covariance ablation further shows that removing inter-head correlation structure substantially contributes to performance, with complex covariance assumptions causing significant degradation on cross-domain data. These results indicate that the attentional distraction signal underlying focus-score-based detection does not transfer reliably to agentic environments, and that learned linear classifiers over head-level attention features offer improved detection performance, provided training data from the target deployment domain is available.

Keywords: indirect prompt injection, attention analysis, LLM agents, white-box detection

1. Introduction

Large Language Models (LLMs) have rapidly become capable and widely deployed systems, enabling a broad range of applications from automated writing assistants to complex question answering pipelines. As these models grow in capability, they are increasingly deployed not as static responders but as autonomous agents: systems that iteratively plan, call external tools, retrieve data from the environment, and take actions on behalf of users. This shift toward agentic deployment fundamentally changes the security landscape for LLMs.

In agentic settings, a model does not only process instructions from a trusted user. It also ingests content from the external environment, such as emails, documents, web pages, and database records, as part of completing its task. An adversary who controls any piece of content the agent reads can embed malicious instructions within it, delivering an indirect prompt injection (IPI) attack that may be entirely invisible to the user (Greshake

© 2026 A. Kawasaki & S. Lee.

et al., 2023). Unlike direct prompt injection, where a malicious user submits adversarial instructions themselves, IPI attacks are delivered through the environment, making them particularly difficult to defend against in deployed systems.

The threat is not merely theoretical. Debenedetti et al. (2024) demonstrate through the AgentDojo benchmark that current LLM agents are highly susceptible to IPI attacks embedded in realistic environment data across a range of task domains including banking, email, and travel. Defending against these attacks in a way that is both effective and practical for deployment remains an open problem. Existing defenses either require multiple forward passes per agent step (Zhu et al., 2025; Robey et al., 2025) or rely on text-level classifiers that are brittle to semantically subtle attacks (Chen et al., 2025).

A promising alternative is to detect IPIs by inspecting the model's internal state at inference time. Recent work has shown that the distinction between benign and adversarial inputs is consistently recoverable from model internals, and that lightweight classifiers over internal representations can be highly effective (Kawasaki et al., 2024; Abdelnabi et al., 2025a; Zou et al., 2025). Among these, Hung et al. (2025) propose Attention Tracker, a single-pass detection method that monitors how the model's attention is distributed between system instruction tokens and data tokens. Their key observation is that when a prompt injection attack is present, the model's attention shifts away from the legitimate instruction and toward the injected content. By identifying a small set of attention heads that are sensitive to this shift and computing a scalar focus score at inference time, Attention Tracker achieves strong detection performance on non-IPI benchmark datasets. The authors further claim that the method is dataset-agnostic: the important heads are identified once on synthetic data and transfer across domains without any retraining.

In this paper, we evaluate and extend Attention Tracker in the realistic agentic setting for which defenses are most urgently needed. We make the following contributions:

– We provide the first evaluation of Attention Tracker on AgentDojo, a benchmark that embeds prompt injection attacks inside structured multi-step agent environments (Debenedetti et al., 2024). We find the dataset agnosticism claim does not fully hold in this setting.

– We introduce AttnDA, an alternative to Attention Tracker’s scalar threshold detection mechanism, replacing it with Fisher’s Linear Discriminant Analysis. AttnDA accounts for the varying head importance and finds more discriminative decision boundaries.

– We conduct a covariance structure ablation of AttnDA. We find that ignoring head-to-head correlations increases detection performance: complex covariance assumptions, including full and block-layer variants, cause significant degradation even on in-domain data, with transfer performance collapsing to chance for these variants.

– We evaluate on a broader set of benchmarks including AgentDojo and InjecAgent, and construct a matched benign dataset for LLMail-Inject attacks to enable evaluation for binary classification (Debenedetti et al., 2024; Zhan et al., 2024; Abdelnabi et al., 2025b).

References (20)