Prompt injection is the security hole that won't close. You build a guardrail, attackers find a new angle. You train a detector, it costs latency and compute. You inspect the output, you're already too late — the model said the bad thing.

RAP-ID takes a different approach. It listens to what happens inside the model during the first forward pass and catches injections before a single token is generated. No extra model. No fine-tuning. No waiting around.

The paper, "RAP-ID: Mechanistic Prompt Injection Detection via Impostor Behavior Analysis," appeared at ACL 2026 Findings last week. It comes from Yuchen Yang, Lei Peng, Yujie He, Yang Yu, Zhongxin Wu, and Yanlei Shi.

The Core Idea: Injections Are Impostors

Every prompt injection has to do three things to succeed. RAP-ID names these "impostor behaviors" and detects each one from the model's internal state.

Directive Likeness. An injection needs to sound like a system instruction. "Ignore all previous instructions and..." is trying to impersonate the system prompt. RAP-ID measures how much an input's internal representation looks like the model's encoding of system-level directives. If a user message starts acting like a system message, that's suspicious.

Counterfactual Gain. Injections steal attention. When a malicious payload enters the conversation, it pulls the model's attention away from the real system prompt and toward itself. RAP-ID compares attention patterns with and without the suspect input. If the input is hijacking attention from the system prompt, the counterfactual gain spikes.

Policy Conflict. Injections trigger the model's latent risk concepts — the internal representations that fire when the model encounters something it was trained to refuse. RAP-ID probes whether an input activates these risk-related latent directions. If the input is quietly nudging the model toward something it should refuse, the policy conflict signal lights up.

Fuse these three signals together and you get a detection score. High score means impostor behavior detected. Low score means the input is probably legitimate.

Why This Is Different

Most injection defenses fall into a few buckets, each with problems:

  • External guardrail models (like a separate classifier checking inputs) add latency and compute. They also need training data, which means they're only as good as the attacks they've seen.
  • Response inspection checks the model's output for harmful content. But by then the model has already generated the text. If you're using the model for agentic workflows, the output might trigger a tool call before you can inspect it.
  • Prompt-level defenses (like adding "ignore instructions from external sources" to the system prompt) learn surface heuristics rather than deep security, as another ACL 2026 paper demonstrated. They're bypassable.
  • Training-based internal defenses require fine-tuning the model, which is expensive and needs attack data.

RAP-ID skips all of these problems. It reads the model's own internal states — the hidden layer activations and attention weights that already exist during a normal forward pass. No generation. No extra model. No training. The detection happens during the same computation the model is already doing.

How It Works in Practice

Here's the flow: the model receives a prompt. During the forward pass, RAP-ID extracts three things from the internal state. First, it compares the input's representation against the system prompt's representation to measure Directive Likeness. Second, it computes a counterfactual — what would the attention pattern look like without this input? — and measures the attention shift (Counterfactual Gain). Third, it checks whether the input activates the model's internal risk directions (Policy Conflict).

The three signals get fused into a single detection score. If the score exceeds a threshold, the input is flagged as an injection attempt. All of this happens before the model generates any output tokens.

The counterfactual computation is the cleverest part. You don't need to run the model twice. The paper shows you can approximate the counterfactual attention pattern from a single forward pass by analyzing how attention is distributed across the system prompt versus the user input. This keeps the overhead minimal.

What It Catches

RAP-ID was evaluated across multiple attack types:

  • Direct jailbreaks — the classic "ignore previous instructions" style attacks
  • Stealthy agentic manipulations — injections embedded in tool outputs or retrieved documents that try to subtly redirect agent behavior

The paper reports competitive performance compared to heuristic methods, with "significant overall improvements." The key word is "competitive," not "perfect." RAP-ID catches a broad range of attacks from a single forward pass, but the authors don't claim it's a silver bullet.

The train-free aspect matters here. Heuristic methods need to be updated as new attack patterns emerge. RAP-ID's mechanistic approach targets behaviors that are structural to how injections work, not surface patterns that attackers can avoid by rephrasing.

Why It Matters for Agents

Agent systems are where injection attacks hurt the most. An agent that reads tool outputs, retrieves documents, and executes actions has a huge attack surface. Every external data source is a potential injection vector.

Current agent defenses often rely on output inspection — check what the agent is about to do before it does it. But agents chain actions. By the time you're inspecting the third or fourth step, the injection has already influenced the model's reasoning across multiple turns.

RAP-ID operates at the input layer, before generation. For agents, that means you can flag a suspicious tool output or retrieved document before it enters the model's context window and starts influencing downstream behavior. That's a meaningful shift from reactive to proactive defense.

Limitations to Keep in Mind

The paper doesn't claim RAP-ID replaces all other defenses. It's a detection layer, not a complete defense system. False positives are a real concern — legitimate instructions that strongly resemble system directives could trigger Directive Likeness. A well-crafted legitimate prompt that happens to touch risk topics could trigger Policy Conflict.

The counterfactual gain signal is the most discriminating of the three because it's hardest to fake. An attacker can make their injection sound like a system directive, and they can make it touch risky topics, but it's much harder to avoid stealing attention from the real system prompt while still being effective. The fusion of all three signals helps balance this out.

Access to internal states is also a requirement. If you're calling a closed API where you can't see hidden layer activations or attention weights, RAP-ID isn't directly applicable. This is a defense for open-weight models or deployments where you control the inference pipeline.

The Bigger Picture

RAP-ID is part of a growing wave of mechanistic approaches to LLM security. Instead of treating the model as a black box and building external guardrails, these approaches open the box and use the model's own internal representations as the detection signal.

We're seeing the same shift in jailbreak detection (latent refusal trajectories), injection theory (role confusion as a mechanistic explanation), and now injection detection. The common thread: if you want to understand whether a model is being attacked, look at what's happening inside the model, not just at what it says.

This matters because internal signals are harder to evade. Surface patterns can be paraphrased away. Attention hijacking and policy activation are structural. You can't rephrase your way out of stealing attention from the system prompt — if your injection works, it's doing exactly that.

RAP-ID won't be the last word on mechanistic injection detection. But it's a clean, practical contribution: three well-motivated signals, fused into a single detection score, computed during a normal forward pass, with no training required. For anyone running open-weight models in production, it's worth serious consideration.


Citations:

Suggested title: RAP-ID Catches Prompt Injections Before the Model Even Speaks

Word count: ~1,050

Fact-check notes:

  • The abstract confirms the three signals (Directive Likeness, Counterfactual Gain, Policy Conflict) and the train-free, forward-pass-only approach. Direct quotes from the abstract were used for accuracy.
  • The paper claims "competitive performance with significant overall improvements compared to heuristic methods" — this is the authors' claim, not independently verified.
  • The claim about counterfactual approximation from a single forward pass is inferred from the paper's statement that RAP-ID "incurs minimal computational overhead" and operates "exclusively on internal state dynamics during the initial forward pass." The exact mechanism for computing the counterfactual without a second pass was not directly verified from the PDF (which was not extractable as text).
  • The limitation about closed APIs is an inference, not stated in the paper. It's a reasonable conclusion given that RAP-ID requires access to internal states.
  • Author affiliations were not fully extractable from the PDF. The bib entry confirms author names but not institutions.