PISanitizer: Preventing Prompt Injection to Long-Context LLMs via Prompt Sanitization
On the map: LLM safety and security → Prompt injection and agent security
Abstract (arXiv)
Long context LLMs are vulnerable to prompt injection, where an attacker can inject an instruction in a long context to induce an LLM to generate an attacker-desired output. Existing prompt injection defenses are designed for short contexts. When extended to long-context scenarios, they have limited effectiveness. The reason is that an injected instruction constitutes only a very small portion of a long context, making the defense very challenging. In this work, we propose PISanitizer, which first pinpoints and sanitizes potential injected tokens (if any) in a context before letting a backend LLM generate a response, thereby eliminating the influence of the injected instruction. To sanitize injected tokens, PISanitizer builds on two observations: (1) prompt injection attacks essentially craft an instruction that compels an LLM to follow it, and (2) LLMs intrinsically leverage the attention mechanism to focus on crucial input tokens for output generation. Guided by these two observations, we first intentionally let an LLM follow arbitrary instructions in a context and then sanitize tokens receiving high attention that drive the instruction-following behavior of the LLM. By design, PISanitizer presents a dilemma for an attacker: the more effectively an injected instruction compels an LLM to follow it, the more likely it is to be sanitized by PISanitizer. Our extensive evaluation shows that PISanitizer can successfully prevent prompt injection, maintain utility, outperform existing defenses, is efficient, and is robust to optimization-based and strong adaptive attacks. The code is available at https://github.com/sleeepeer/PISanitizer.
Key facts. Cited by 13 papers in the map (data through 14 Oct 2026). Placed in Prompt injection and agent security, one of 12 directions in LLM safety and security. First posted on arXiv 13 Nov 2025.
Builds on
0 of 0 references.
No references here yet.
Built on by
Citing papers per year: 2026: 13.
13 papers.
Sort:
By area:
- 2026Taming OpenClaw: Security Analysis and Mitigation of Autonomous LLM Agent Threatscited by 29
- 2026PISmith: Reinforcement Learning-based Red Teaming for Prompt Injection Defensescited by 16
- 2026CausalArmor: Efficient Indirect Prompt Injection Guardrails via Causal Attributioncited by 14
- 2026PIArena: A Platform for Prompt Injection Evaluationcited by 11
- 2026SafeAgent: A Runtime Protection Architecture for Agentic Systemscited by 7
- 2026AgentWatcher: A Rule-based Prompt Injection Monitorcited by 6
- 2026VeriCache: Turning Lossy KV Cache into Lossless LLM Inferencecited by 5
- 2026Agent Against Agent: An Agentic System for Automatic Prompt Injection Red Teamingcited by 1
- 2026Beyond Over-Refusal: Defending Indirect Prompt Injection via Latent Instruction Manifoldscited by 1
- 2026CLASP: Defending Hybrid Large Language Models Against Hidden State Poisoning Attackscited by 0
- 2026ALIBI: Adaptive Agentic Attacks on LLM-Based Vulnerability Detectors via Adversarial Code Commentscited by 0
- 2026ToolFence: Fine-Grained Authorization for Secure Tool-Using LLM Agentscited by 0
1 more
- 2026Jailbreaking Open-Weight LLMs via Random Embedding Perturbations5 Oct 2026
- 2026ToolFence: Fine-Grained Authorization for Secure Tool-Using LLM Agents29 Sep 2026
- 2026Beyond Over-Refusal: Defending Indirect Prompt Injection via Latent Instruction Manifolds23 Aug 2026
- 2026Agent Against Agent: An Agentic System for Automatic Prompt Injection Red Teaming5 Aug 2026
- 2026ALIBI: Adaptive Agentic Attacks on LLM-Based Vulnerability Detectors via Adversarial Code Comments27 Jul 2026
- 2026VeriCache: Turning Lossy KV Cache into Lossless LLM Inference17 May 2026
- 2026SafeAgent: A Runtime Protection Architecture for Agentic Systems19 Apr 2026
- 2026PIArena: A Platform for Prompt Injection Evaluation9 Apr 2026
- 2026AgentWatcher: A Rule-based Prompt Injection Monitor1 Apr 2026
- 2026PISmith: Reinforcement Learning-based Red Teaming for Prompt Injection Defenses13 Mar 2026
- 2026CLASP: Defending Hybrid Large Language Models Against Hidden State Poisoning Attacks12 Mar 2026
- 2026Taming OpenClaw: Security Analysis and Mitigation of Autonomous LLM Agent Threats12 Mar 2026
- 2026Taming OpenClaw: Security Analysis and Mitigation of Autonomous LLM Agent Threatscited by 29
- 2026CausalArmor: Efficient Indirect Prompt Injection Guardrails via Causal Attributioncited by 14
- 2026SafeAgent: A Runtime Protection Architecture for Agentic Systemscited by 7
- 2026Agent Against Agent: An Agentic System for Automatic Prompt Injection Red Teamingcited by 1
- 2026ALIBI: Adaptive Agentic Attacks on LLM-Based Vulnerability Detectors via Adversarial Code Commentscited by 0
- 2026ToolFence: Fine-Grained Authorization for Secure Tool-Using LLM Agentscited by 0
- 2026ToolFence: Fine-Grained Authorization for Secure Tool-Using LLM Agents29 Sep 2026
- 2026Agent Against Agent: An Agentic System for Automatic Prompt Injection Red Teaming5 Aug 2026
- 2026ALIBI: Adaptive Agentic Attacks on LLM-Based Vulnerability Detectors via Adversarial Code Comments27 Jul 2026
- 2026SafeAgent: A Runtime Protection Architecture for Agentic Systems19 Apr 2026
- 2026Taming OpenClaw: Security Analysis and Mitigation of Autonomous LLM Agent Threats12 Mar 2026
- 2026CausalArmor: Efficient Indirect Prompt Injection Guardrails via Causal Attribution8 Feb 2026
- 2026PISmith: Reinforcement Learning-based Red Teaming for Prompt Injection Defensescited by 16
- 2026PIArena: A Platform for Prompt Injection Evaluationcited by 11
- 2026AgentWatcher: A Rule-based Prompt Injection Monitorcited by 6
- 2026Beyond Over-Refusal: Defending Indirect Prompt Injection via Latent Instruction Manifoldscited by 1
- 2026Jailbreaking Open-Weight LLMs via Random Embedding Perturbationscited by 0
- 2026Jailbreaking Open-Weight LLMs via Random Embedding Perturbations5 Oct 2026
- 2026Beyond Over-Refusal: Defending Indirect Prompt Injection via Latent Instruction Manifolds23 Aug 2026
- 2026PIArena: A Platform for Prompt Injection Evaluation9 Apr 2026
- 2026AgentWatcher: A Rule-based Prompt Injection Monitor1 Apr 2026
- 2026PISmith: Reinforcement Learning-based Red Teaming for Prompt Injection Defenses13 Mar 2026
Similar, not cited
Close in wording, no citation either way
- 2025Robustness via Referencing: Defending against Prompt Injection Attacks by Referencing the Executed Instruction
- 2025Defending Against Prompt Injection With a Few DefensiveTokens
- 2025LLMail-Inject: A Dataset from a Realistic Adaptive Prompt Injection Challenge
- 2026Know Thy Enemy: Securing LLMs Against Prompt Injection via Diverse Data Synthesis and Instruction-Level Chain-of-Thought Learning
- 2026LongPIBench: A Long-Context Benchmark for Prompt Injection
- 2023Evaluating the Instruction-Following Robustness of Large Language Models to Prompt Injection
- 2024Defense Against Prompt Injection Attack by Leveraging Attack Techniques
- 2023Benchmarking and Defending Against Indirect Prompt Injection Attacks on Large Language Models