[Paper Review] AgentSentry: Mitigating Indirect Prompt Injection in LLM Agents via Temporal Causal Diagnostics and Context Purification
AgentSentry introduces an inference-time defense that treats multi-turn indirect prompt injection as a temporal causal takeover, using boundary-aware diagnostics and context purification to enable safe continuation of tool-augmented LLM agents under attack.
Large language model (LLM) agents increasingly rely on external tools and retrieval systems to autonomously complete complex tasks. However, this design exposes agents to indirect prompt injection (IPI), where attacker-controlled context embedded in tool outputs or retrieved content silently steers agent actions away from user intent. Unlike prompt-based attacks, IPI unfolds over multi-turn trajectories, making malicious control difficult to disentangle from legitimate task execution. Existing inference-time defenses primarily rely on heuristic detection and conservative blocking of high-risk actions, which can prematurely terminate workflows or broadly suppress tool usage under ambiguous multi-turn scenarios. We propose AgentSentry, a novel inference-time detection and mitigation framework for tool-augmented LLM agents. To the best of our knowledge, AgentSentry is the first inference-time defense to model multi-turn IPI as a temporal causal takeover. It localizes takeover points via controlled counterfactual re-executions at tool-return boundaries and enables safe continuation through causally guided context purification that removes attack-induced deviations while preserving task-relevant evidence. We evaluate AgentSentry on the extsc{AgentDojo} benchmark across four task suites, three IPI attack families, and multiple black-box LLMs. AgentSentry eliminates successful attacks and maintains strong utility under attack, achieving an average Utility Under Attack (UA) of 74.55 %, improving UA by 20.8 to 33.6 percentage points over the strongest baselines without degrading benign performance.
Motivation & Objective
- Motivate and formalize the IPI threat in tool-augmented LLM agents and its multi-turn, delayed takeover patterns.
- Develop an inference-time defense that localizes takeover points and enables safe continuation without premature termination.
- Propose boundary-anchored counterfactual diagnostics to detect causal dominance by untrusted mediator content.
- Implement causally gated context purification to suppress attack signals while preserving task-relevant evidence.
- Demonstrate effectiveness on AgentDojo across diverse tasks and attack families with black-box LLMs.
Proposed method
- Model multi-turn IPI as a temporal causal takeover and localize takeover points via controlled counterfactual re-executions at tool-return boundaries.
- Compute boundary-level causal quantities using four diagnostic regimes (orig, mask, mask_sanitized, orig_sanitized) and an ordinal takeover outcome Y_b.
- Estimate average causal effects (ACE) and direct/indirect effects (DE/IE) through Monte Carlo re-executions and a mediation decomposition.
- Apply boundary-local context purification only when diagnostics indicate context-mediated dominance, enabling safe continuation.
- Use dry-run re-executions to avoid irreversible actions and implement a selective, per-boundary mitigation.

Experimental results
Research questions
- RQ1Can multi-turn indirect prompt injection be reliably detected and localized at tool-return boundaries using controlled counterfactual re-executions?
- RQ2Does causally gated context purification restore safe continuation without unduly sacrificing task utility under attack?
- RQ3How effective is AgentSentry across multiple IPI attack families and black-box LLM backends on AgentDojo?
- RQ4What is the trade-off between detection-based safeguards and maintaining benign task performance in long-horizon workflows?
Key findings
- AgentSentry achieves a perfect defense on AgentDojo with Attack Success Rate (ASR) = 0%.
- Under attack, AgentSentry attains an average Utility Under Attack (UA) of 74.55%.
- AgentSentry improves UA by 20.8 to 33.6 percentage points over the strongest baselines without degrading benign performance.
- Diagnostics localize the earliest boundary where attacker-controlled context dominates and enable targeted purification rather than global blocking.
- Mitigation activates only when diagnostics indicate context-mediated causal dominance, preventing unnecessary disruption of legitimate tasks.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.