Understanding and Mitigating Role Spoofing in LLMs

Ezra Edelman, Benjamin Edelman, Surbhi Goel, Eran MalacharXiv 2026

TL;DR

LLMs are surprisingly bad at tracking "who said what" in a conversation, making them vulnerable to role spoofing—an attack where malicious tool outputs (like a webpage or email) impersonate a user. This paper demonstrates that even frontier models like GPT-5 and Claude 3 Opus are highly susceptible to these attacks and proposes a robust defense using linear probes to detect internal "role confusion" within the model's activations.

What Problem Does This Paper Address?

As LLMs transition into autonomous agents that read external data and call tools, they face a critical security threat: prompt injection. A specific, dangerous variant is role spoofing, where an adversary tricks the model into believing a malicious instruction came from the authorized user rather than an untrusted tool output.

While modern LLMs use "special tokens" (e.g., <|im_start|>user) to define message boundaries, they often rely on unreliable cues like writing style or semantics to identify the speaker. If an attacker mimics the user's style or injects "fake" structural markers, the model may suffer from role confusion and execute unauthorized actions, such as wiring money or deleting data. The authors investigate why this happens and how to stop it.

Methods

The authors employ a multi-pronged approach to dissect role tracking:

  1. "Who Said What" Setting: A simplified diagnostic task where models are pre-filled with a conversation and then asked to identify the sender of a specific text snippet. This isolates role attribution from other agentic capabilities.
  2. Toy Model Analysis: They train a two-layer transformer on synthetic data to simulate the training pipeline (pretraining $\rightarrow$ instruction tuning $\rightarrow$ adversarial training). This allows them to visualize attention patterns and see exactly how models switch between "content-based" and "structure-based" role tracking.
  3. Linear Probing: They develop a defense by training simple linear classifiers on the internal activations of the LLM. These probes are trained to predict the model's "internal belief" about the role of a token (e.g., "is this a tool output?").
  4. Adversarial Evaluation: They test models against "fake structure" (forged special tokens) and "misleading content" (style mimicry) to see which cues different models prioritize.

Datasets

  • AgentDojo (Workspace Family): A benchmark for evaluating prompt injections in agentic workflows.
  • Simple Tool-Use Testbed: A new, controlled environment created by the authors featuring five domains (banking, email, etc.) designed to isolate role spoofing by sampling user and adversarial tasks from the same pool.
  • Nemotron-SFT-Agentic-v2 & Nemotron-CC: Used for realistic agentic conversation data and "style-free" random internet data, respectively.

Key Insights and Ideas

  • The Mixture of Cues: Models don't just use one method to track roles. They use a "mixture" of content and structure. Interestingly, different models have different biases: Gemini 3.6 Flash is rarely fooled by content but fails on fake structure, while GPT-5.4 is more frequently swayed by misleading content.
  • The Robustness Trap: Training a model to ignore content-based injections (like "ignore previous instructions") often forces it to rely more heavily on structural cues. This makes the model more vulnerable to sophisticated attacks that use forged special tokens.
  • Internal "Belief" vs. Output: Even when a model is fooled and follows a malicious instruction, its internal activations often still distinguish the roles correctly. The "belief" is there; it's just not being used correctly for the final prediction.
  • Defense via Randomness: One of the most surprising findings is that linear probes trained on conversations filled with completely random tokens are incredibly effective at detecting role spoofing in real, coherent conversations.

Key Results

The paper reveals a sobering reality: role spoofing is highly effective against every model tested.

Figure 1: (Left) A simplified example of role spoofing via a fake special token injection. The injection is shown in orange, with the real special tokens wrapping it, and forged special tokens within. (Right) LLM role spoofing results in the AgentDojo ‘workspace family’. The first two columns show the rate at which the model follows the malicious instructions, when sent by the user (control) or when injected in a tool call (injection). The third column shows the ratio of injection to control. Our setup, being focused on role spoofing in particular, differs from the AgentDojo benchmark defaults, see Section B for the full details.
  • Attack Success: In the AgentDojo benchmark, role spoofing attacks achieved injection-to-control ratios near 100% for models like GPT-5.4 and Claude Opus 5, meaning the models followed malicious instructions almost as often as legitimate user requests.
  • Testbed Performance: In the authors' "Simple Tool-Use Testbed," the attack success rate exceeded 95% for nearly all models.
  • Defense Efficacy: The proposed linear probe defense achieved near-perfect separation between clean and injected messages. As shown in the ROC curves, the probes can achieve a >99% true positive rate with zero false positives in the tested regimes.
Figure 2: Injection success rates on “Who Said What”, where models need to output the role assigned to a given message segment in the presence of either misleading content or fake structure.

Limitations and Future Work

  • Scope of Defense: The linear probe method is specifically designed for role spoofing. It does not detect other types of prompt injections, such as jailbreaks that don't involve impersonation.
  • Brittle Training: While the authors suggest that adding more "edge cases" to training data might help, they warn this is a brittle solution that doesn't guarantee the model will learn a truly robust structural mechanism.
  • Future Integration: The authors hope frontier model providers will incorporate these simple linear probe monitors into their inference engines to provide a more robust layer of security for autonomous agents.

Summary updated

Abstract

Despite growing capabilities, LLMs remain susceptible to prompt injections: malicious inputs that can manipulate or hijack models. In particular, it has recently been observed that LLMs can exhibit role confusion (Ye et al., 2026), where models attribute the source of text based on its style instead of its labeled role. Malicious text in tool outputs (for instance, a malicious webpage accessed by an agent) can leverage role confusion to impersonate the user, an attack we call role spoofing}. In this work, we seek to understand and mitigate role spoofing. We study how models track "who said what" in a conversation, showing that they use cues from both content (e.g., semantics and writing style) and structure (e.g., control tokens and formatting). We show that LLMs are highly susceptible to role spoofing attacks that combine both fake structure and content. Additionally, in a toy setting, we show that adversarial training which teaches the model to ignore content-based injections does mitigate content-based attacks but leaves the model susceptible to structure-based attacks. This can explain why frontier models, with increased resistance to many injection attacks, can still be susceptible to role spoofing. Finally, we propose a new method for detecting role spoofing using linear probes trained to predict roles in a conversation, and show that it is effective across different settings.
BibTeX
@misc{edelman2026understanding,
  author = {Ezra Edelman and Benjamin Edelman and Surbhi Goel and Eran Malach},
  title = {{Understanding and Mitigating Role Spoofing in LLMs}},
  year = {2026},
  eprint = {2610.40396},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.40396},
}
Figure