arXiv(opens in a new tab)cs.CRSep 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2609.10892

DriftNet: A Dual-Head Trajectory Transformer for Detecting and Localizing Prompt Injection in LLM Agents

Asif Pinjari, Mithun Paul Saint-Germain

Asif Pinjari

School of Informatics, Computing,

and Cyber Systems

Northern Arizona University

Flagstaff, AZ, USA

ap3929@nau.edu

Mithun Paul Saint-Germain

School of Informatics, Computing,

and Cyber Systems

Northern Arizona University

Flagstaff, AZ, USA

mithun.paul@nau.edu

Abstract—When an indirect prompt injection succeeds against an LLM agent, the compromise is visible in the agent's own behavior: a benign prefix of tool calls, a poisoned observation, and a suffix of actions that serve the attacker. An operator needs three facts: where the attack entered, which steps it corrupted, and whether apparent poison was resisted. Existing systems return either a whole-trace verdict or a single unsafe index. We present DriftNet, a dual-head trajectory Transformer that reads a logged tool-call trajectory and answers all three questions in one forward pass: one head classifies the trajectory as compromised or not, and a second assigns every step one of four labels (benign, injection point, hijacked, failed injection). To our knowledge it is the first supervised detector to produce this joint output. A frozen sentence encoder and four identity-free world features embed each step; the trained trunk, under two million parameters and optimized with a class-weighted joint objective over both heads, needs no access to the agent's model. On the task-disjoint split of the AgentDrift benchmark (12,536 trajectories, 71,024 labeled steps), with a 20-configuration sweep bounding hyperparameter sensitivity to 0.011 F1 and the test part evaluated exactly once, DriftNet reaches trajectory-level F1 of 0.983, exact injection-point recovery on 98.7% of attacked trajectories, hijacked-span IoU of 0.979, zero flags on 218 resisted attacks, and 2.9% flags on hard negatives. A surface baseline retrained on the identical split recovers 11.1% of partial hijacks and 17.1% of delayed executions; DriftNet reaches 98.6% and 93.2% while lowering every false-alarm rate. Reading all 26 residual errors shows that most misses trace to trajectories whose labeled injection observation carries no legible instruction, and we report the benchmark's measured world-identity regularity alongside the results.

Index Terms—LLM agents, prompt injection, trajectory analysis, sequence labeling, anomaly detection, agent security

I. INTRODUCTION

LLM agents act on the world by interleaving reasoning with tool calls. Following the pattern popularized by ReAct [1], every step couples a reasoning thought with a tool invocation, its arguments, and the returned observation, and such agents already read inboxes, move money, browse the web, edit code, and retrieve patient records. Every observation the agent reads is also an attack surface. Indirect prompt injection [2] hides instructions in content the agent will later retrieve; since a language model draws no hard line between data and instructions, the agent can adopt the planted goal as its own. The threat is measured, not hypothetical: a ReAct-prompted GPT-4 follows injected instructions in roughly a quarter of InjecAgent's test cases [3], Agent Security Bench reports attack success above 80% for some backbones [4], and stage-level tracking shows injected payloads surviving across surfaces and agent boundaries in multi-agent pipelines [5].

When an injection succeeds, the compromise has a shape. Execution begins benignly, a poisoned observation arrives mid-task, and the steps that follow drift away from the user's goal toward the attacker's. Detecting this is a sequence problem: each step must be judged against the task, the world the agent operates in, and everything that came before. Localizing it is what makes detection actionable. An operator confronted with a flagged trajectory needs to know the step where the attack entered, the span of actions it corrupted, and whether apparent poison was actually resisted, because those three facts decide what to roll back, what to audit, and which content source to distrust.

Existing systems do not produce this output. Live-loop defenses veto or re-derive single actions and assume control of the running agent [6]–[9]; internal-state probes and attention localizers require white-box access to the agent's model [10]–[12]. Detectors that do read completed trajectories emit either a single verdict on the whole trace, with resisted injections folded into the safe class [13]–[15], or a single index: the first unsafe action [16], the one mutated step [17], the divergence onset [18], the error step [19], or the root-cause component [20]. A single index cannot represent an agent that complied for two steps and recovered, an execution delayed past benign steps, or an injection that was seen and refused. What has been missing is a detector whose output is the full picture: a trajectory verdict together with an injection-specific label on every step.

This paper presents DriftNet, a detector with exactly that output, trained and evaluated on the AgentDrift benchmark [21], whose 71,024 step labels make dense, injection-specific supervision of this task available for the first time. DriftNet is deliberately small. Each step is serialized to text and embedded by a frozen sentence encoder; four world-grounded, identity-free features recover what semantics cannot see, namely whether the step's action targets a recipient outside the user's known world; and a Transformer encoder of at most three layers reads the sequence with two heads, one pooling into a trajectory verdict, one labeling every step as benign, injection_point, hijacked, or failed_injection. The trained trunk is under two million parameters, three orders of magnitude below contemporary LLM-scale guards [16], and it consumes only the logged trajectory: no agent internals, no re-execution, no live loop.

The evaluation is designed to be hard to fool and easy to trust. All experiments use the corpus's task-disjoint split, in which no task template is shared between training and test, so template memorization cannot inflate the numbers. A 20-configuration random sweep establishes that the result does not depend on a lucky configuration (every draw lands within a 0.011 band of validation F1). The held-out test part is evaluated exactly once. And the surface baseline we compare against is retrained on the identical split, making the comparison like for like. Under this protocol DriftNet reaches trajectory-level F1 of 0.983; it recovers the exact injection-point set in 98.7% of attacked trajectories and the hijacked span at mean IoU 0.979; it flags zero of 218 resisted attacks and 2.9% of hard negatives. Where the surface baseline collapses on the benchmark's two stealthy compliance patterns (11.1% recall on partial hijacks, 17.1% on delayed executions), DriftNet reaches 98.6% and 93.2%. Reading all 26 residual errors individually shows that they are confident rather than marginal, that the misses concentrate on delayed executions, and that in nine of twelve misses the labeled injection observation contains no legible instruction at all, pointing to residual generation noise in the corpus rather than to evidence the detector failed to read.

We also state plainly what these numbers do not establish. The corpus is synthetic and single-generator, and the dataset paper measures a world-identity regularity in it that a lookup exploits to 86% binary accuracy; our world features are immune by construction, but the text embeddings are not, and Section X discusses what that does and does not explain. The claim of this paper is scoped accordingly: on the first benchmark dense enough to supervise the task, joint trajectory classification and four-way step labeling is learnable to high fidelity by a small, cheap, model-agnostic detector.

Our contributions are as follows.

• DriftNet. A dual-head trajectory Transformer that, to our knowledge, is the first supervised detector to jointly classify a tool-call trajectory and label every step four ways, locating the injection point, the hijacked span, and resisted injections in one forward pass from the log alone (Section V).

• Strict localization metrics. Injection-point exact-set match and hijacked-span IoU, which expose localization failures that per-class F1 hides (Section III-D).

• A trust-preserving protocol. Task-disjoint training, a robustness sweep, a single test evaluation, and a like-for-like retrained baseline (Section VI).

• Results and analysis. High-fidelity detection and localization on AgentDrift with pattern, domain, and family breakdowns; an exhaustive error analysis with a calibration caution; and an honest account of the benchmark’s measured artifacts (Sections VII to X).

The remainder of the paper proceeds from related work (Section II) through formulation (Section III), the benchmark and split (Section IV), the architecture (Section V), and the protocol (Section VI), to results (Section VII), error analysis (Section VIII), discussion (Section IX), limitations (Section X), and future work (Section XI).

References (46)