Robust Context-Aware Detection of Malicious Instructions in Text
On the map: LLM safety and security → Prompt injection and agent security
Abstract (arXiv)
The remarkable instruction-following ability of modern LLMs has enabled their practical use as the minds of agents that can autonomously complete increasingly complex tasks. Therein, however, also lies their vulnerability to attacks which embed malicious instructions in text, common variants of which are known as indirect prompt injection (IPI). A fundamental task in addressing this vulnerability is successful segmentation of a given text into benign and malicious sentences (if any). While a number of approaches for this task have been proposed, no detector combines query-relative detection at the segment level, and none are hardened against adaptive evasion attacks realizable in agentic executions. We address the former limitation by developing an approach for malicious sentence classification that is both context- and query-aware. Next, to harden the resulting classifier against evasion, we present two adversarial training methods. The first is directly adapted feature-space adversarial training (AT) in which evasions are approximated using projected-gradient-based optimization in the embedding space. The second simulates realizable evasion attacks in the AT loop through LLM-based paraphrasing. Crucially, we parametrize both AT variants to facilitate a smooth tradeoff between utility and attack robustness. In extensive experiments using indirect prompt injection benchmarks we show that the proposed approach outperforms state-of-the-art IPI defense baselines under static attacks, while in the case of adaptive attacks, our AT variants provide significantly higher utility, lower attack success rate, and often both. Finally, we show that the best AT parameters can depend intimately on the particular application domain. Consequently, domain-dependent tuning of malicious text detectors is likely necessary in practice. Our code is publicly available at https://github.com/tavia-liu/CAD.
Key facts. No citing papers in the map yet (data through 7 Oct 2026). Placed in Prompt injection and agent security, one of 12 directions in LLM safety and security. Builds on 28 of its 38 references that are in the map. First posted on arXiv 5 Aug 2026.
Builds on
28 of 38 references.
Closest ancestors · 12
Same direction, newest first
- 2026AutoDojo: Adaptive Black-Box Attacks Reveal the Limits of IPI Defenses and Task-Specification Effects in LLM Agents13 Jun
- 2025DRIFT: Dynamic Rule-Based Defense with Injection Isolation for Securing LLM Agents13 Jun
- 2025Defending against Indirect Prompt Injection by Instruction Detection8 May
- 2025Progent: Securing AI Agents with Privilege Control16 Apr
- 2025Adaptive Attacks Break Defenses Against Indirect Prompt Injection Attacks on LLM Agents27 Feb
- 2025MELON: Provable Defense Against Indirect Prompt Injection Attacks in AI Agents7 Feb
- 2024The Task Shield: Enforcing Task Alignment to Defend Against Indirect Prompt Injection in LLM Agents21 Dec
- 2024Attention Tracker: Detecting Prompt Injection Attacks in LLMs1 Nov
- 2024Agent Security Bench (ASB): Formalizing and Benchmarking Attacks and Defenses in LLM-based Agents3 Oct
- 2024System-Level Defense against Indirect Prompt Injection Attacks: An Information Flow Control Perspective27 Sep
- 2024Defending Against Indirect Prompt Injection Attacks With Spotlighting20 Mar
- 2023Not what you've signed up for: Compromising Real-World LLM-Integrated Applications with Indirect Prompt Injection23 Feb
Other references · 16
- 2014Explaining and Harnessing Adversarial Examplescited by 7,287
- 2023Universal and Transferable Adversarial Attacks on Aligned Language Modelscited by 2,914
- 2019Theoretically Principled Trade-off between Robustness and Accuracycited by 1,510
- 2026DeepSeek-V4: Towards Highly Efficient Million-Token Context Intelligencecited by 877
- 2018Robustness May Be at Odds with Accuracycited by 873
- 2020Fast is better than free: Revisiting adversarial trainingcited by 723
- 2017Provable defenses against adversarial examples via the convex outer adversarial polytopecited by 564
- 2017Wild Patterns: Ten Years After the Rise of Adversarial Machine Learningcited by 411
- 2023Detecting Language Model Attacks with Perplexitycited by 411
- 2016Adversarial Training Methods for Semi-Supervised Text Classificationcited by 280
- 2019FreeLB: Enhanced Adversarial Training for Natural Language Understandingcited by 261
- 2024IsolateGPT: An Execution Isolation Architecture for LLM-Based Agentic Systemscited by 118
4 more
- 2025The Attacker Moves Second: Stronger Adaptive Attacks Bypass Defenses Against Llm Jailbreaks and Prompt Injectionscited by 108
- 2019Defending Against Physically Realizable Attacks on Image Classificationcited by 66
- 2026AgentDyn: Are Your Agent Security Defenses Deployable in Real-World Dynamic Environments?cited by 45
- 2017Improving Robustness of ML Classifiers against Realizable Evasion Attacks Using Conserved Featurescited by 18
Built on by
Not cited yet.
Similar, not cited
Close in wording, no citation either way
- 2026Detecting and Localizing Segment-Level Poisoning in Multi-Source LLM-Agent Inputs
- 2025Mitigating Indirect Prompt Injection via Instruction-Following Intent Analysis
- 2026Defense Against Indirect Prompt Injection via Tool Result Parsing
- 2026Overcoming the Retrieval Barrier: Indirect Prompt Injection in the Wild for LLM Systems
- 2024Human-Interpretable Adversarial Prompt Attack on Large Language Models with Situational Context
- 2026Bypassing Prompt Injection Detectors through Evasive Injections
- 2026ICON: Indirect Prompt Injection Defense for Agents based on Inference-Time Correction
- 2026Know Thy Enemy: Securing LLMs Against Prompt Injection via Diverse Data Synthesis and Instruction-Level Chain-of-Thought Learning