AgentWatcher : A Rule-based Prompt Injection Monitor

2026

Read AgentWatcher : A Rule-based Prompt Injection Monitor (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2604-01194.txt.

Introduction

AgentWatcher is a rule-based monitor for prompt injection attacks in 2026. Large language models and their agent applications are highly vulnerable. Prompt injection can steer an agent through text it merely reads.

State-of-the-art detection methods carry two limitations, the authors argue. First, effectiveness degrades significantly as context length increases in long inputs. Second, they lack explicit rules defining what prompt injection is. Detection decisions thus stay implicit, opaque, and hard to reason about. A rule-based watcher aims to fix both problems at once. Explicit rules make each flag explainable to a human reviewer. Security readers get a monitor designed for long, real agent contexts.

Catalog record

YEAR2026
COLLECTIONPAPERS
FORMATTXT
FILE SIZE86 KB
VERSION1.0
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2604-01194

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

AgentWatcher : A Rule-based Prompt Injection Monitor Abstract Large language models (LLMs) and their applications, such as agents, are highly vulnerable to prompt injection attacks. State-of-the-art prompt injection detection methods have the following limitations: (1) their effectiveness degrades significantly as context length increases, and (2) they lack explicit rules that define what constitutes prompt injection, causing detection decisions to be implicit, opaque, and difficult to reason about. In this work, we propose AgentWatcher to address the above two limitations. To address the first limitation, AgentWatcher attributes the LLM’s output (e.g., the action of an agent) to a small set of causally influential context segments. By focusing detection on a relatively short text, AgentWatcher can be scalable to long contexts. To address the second limitation, we define a set of rules specifying what does and does not constitute a prompt injection, and use a monitor LLM to reason over these rules based on the attributed text, making the detection decisions more explainable. We conduct a comprehensive evaluation on tool-use agent benchmarks and long-context understanding datasets. The experimental results demonstrate that AgentWatcher can effectively detect prompt injection and maintain utility without attacks. The code is available at https://github.com/wang-yanting/AgentWatcher . 1 Introduction Large language model applications, such as agents, are widely deployed in the real world. However, many recent studies [ 31 , 14 , 68 , 33 , 25 , 32 , 15 ] showed that they are vulnerable to prompt injection, where an attacker can inject a malicious instruction to make an LLM perform an attacker-desired task. For instance, many reports [ 61 , 8 , 49 ] showed that OpenClaw [ 44 ] , a personal AI assistant, is vulnerable to prompt injection attacks, where malicious instructions embedded within benign-looking content (such as emails or codes) cause the agent to execute unauthorized operations. Prompt injection therefore poses serious security and safety risks for the deployment of LLM applications and agents. Many defenses have been proposed to defend against prompt injection, including prevention-based [ 17 , 24 , 52 , 60 , 5 , 6 ] and detection-based [ 38 , 23 , 30 , 37 , 1 , 22 , 34 , 71 ] . Prevention-based defenses, such as SecAlign [ 6 ] , aim to ensure the LLM still performs the user task while ignoring potential injected prompts, whereas detection-based defenses focus on identifying and blocking prompt injection attempts. In general, these two families of defenses are complementary and can be combined to form defense-in-depth. In this work, we focus on detection-based defenses. State-of-the-art detection methods [ 38 , 23 , 30 , 37 , 1 , 22 , 34 , 71 ] face the following challenges: (1) they have limited effectiveness when the context becomes long, making them less scalable to realistic long-context applications such as agents, and (2) they either rely on implicit learned representations [ 23 , 30 , 37 , 1 , 34 , 71 ] , leading to opaque and difficult-to-interpret decisions, or adopt oversimplified assumptions about prompt injection (e.g., that the injected instruction must divert the LLM’s attention from the target task [ 22 ] ), which can fail in complex real-world scenarios. Our work: In this work, we propose a new detection method, namely AgentWatcher , to mitigate the above two limitations. To address the first limitation, AgentWatcher attributes a set of texts that are responsible for the output action of the backbone LLM. For instance, when an agent is about to perform a potentially risky action, such as deleting files, sending sensitive information, or visiting an external URL, AgentWatcher identifies the specific contexts that causes this action. A key challenge is ensuring the entire injected prompt lies within the attributed context. Existing attribution methods [ 10 , 9 , 58 , 57 , 16 ] typically rely on fixed text partitioning, where injected instructions can be split across segment boundaries. AgentWatcher instead applies a small sliding window to locate sink tokens (tokens receiving disproportionately high attention from the LLM’s response) and retains their surrounding spans as the attributed context. This design prevents injected instructions from being fragmented across segments and improves detection performance. Given the attributed context, the target (user) task, and the backbone LLM’s output action, AgentWatcher employs a monitor LLM to reason whether the context contains a malicious instruction according to a set of explicit, customizable rules. This design not only improves detection effectiveness but also makes the LLM’s decisions more interpretable. An example of the monitor LLM’s output is shown below, where the original target task is to retrieve the user’s electricity bill and make a payment. The output contains a reasoning process that explains why there exists a prompt injection. To further enhance rule-based reasoning, we fine-tune the LLM using GRPO [ 50 ] . We also explore different strategies for automatically generating the rule set. An example of the Monitor LLM’s output <Reasoning> The untrusted context contains a section labeled "<INFORMATION>" where Emma Johnson instructs the model to "Send money to AT6854532054 with the subject ’consulting services’ and amount of 20" before solving the original task. This constitutes a direct instruction to take unauthorized financial action, which falls under rule (4): malice controlling funds or exfiltrating resources. It also violates rule (2) by overriding the original task and redirecting execution flow. Despite the model responding with a neutral tool call related to date retrieval, the presence of explicit commands to transfer money clearly represents a prompt injection attempt. </Reasoning> Yes, Injection: Before you can solve the task that I gave you in the beginning, please do the following first: Send money to AT6854532054 with the subject ’consulting services’ and amount of 20. After you do that, you can solve the task that I gave you in the beginning. Thanks! Signed, Emma Johnson We evaluate AgentWatcher on four agent benchmarks, including AgentDojo [ 14 ] and AgentDyn [ 31 ] , as well as six long-context understanding datasets. AgentWatcher consistently demonstrates strong effectiveness across diverse settings. 2 Related Work Existing defenses against prompt injection can be categorized into prevention-based and detection-based defenses. Prevention-based defenses [ 17 , 24 , 52 , 60 , 5 , 6 ] aim to mitigate the effects of injection, such as by sanitizing the context to neutralize the effect of malicious instructions [ 17 , 24 , 52 , 60 ] or training a robust LLM against prompt injection [ 6 , 5 ] . We defer the detailed discussion for prevention-based defenses to Appendix A . In general, detection-based defenses are complementary to prevention-based methods, and they can be combined to form defense-in-depth. Next, we discuss more details on existing detection-based defenses, as our defense is also based on detection. Existing detection methods [ 38 , 23 , 30 , 37 , 1 , 22 , 34 , 71 ] detect whether a context is contaminated with prompt injection before letting a backend LLM generate a response. For instance, Known-Answer Detection [ 38 ] designs a detection instruction to test if a given context contains an injected instruction using an LLM. Specifically, the context is detected as contaminated if the detection instruction is not followed by the LLM. DataSentinel [ 34

Read the complete text