Defending against Indirect Prompt Injection by Instruction Detection

Wen, Tongyu, Wang, Chenglong, Yang, Xiyuan, Tang, Haoyu, Xie, Yueqi, Lyu, Lingjuan, Dou, Zhicheng, Wu, Fangzhao

–arXiv.org Artificial Intelligence 

The integration of Large Language Models (LLMs) with external sources is becoming increasingly common, with Retrieval-Augmented Generation (RAG) being a prominent example. However, this integration introduces vulnerabilities of Indirect Prompt Injection (IPI) attacks, where hidden instructions embedded in external data can manipulate LLMs into executing unintended or harmful actions. We recognize that IPI attacks fundamentally rely on the presence of instructions embedded within external content, which can alter the behavioral states of LLMs. Can the effective detection of such state changes help us defend against IPI attacks? In this paper, we propose InstructDetector, a novel detection-based approach that leverages the behavioral states of Figure 1: In a medical use case of the RAG system, the LLMs to identify potential IPI attacks. Specifi-LLM is misled by the external instruction embedded in cally, we demonstrate the hidden states and gra-a retrieved document to recommend company A's meddients from intermediate layers provide highlyication. Our method performs instruction detection to discriminative features for instruction detection. By effectively combining these features, defend against such attacks, removing such documents InstructDetector achieves a detection accuracy before they are passed to the LLM. of 99.60% in the in-domain setting and 96.90% in the out-of-domain setting, and reducesstruggle with domain-specific or up-to-date knowlthe attack success rate to just 0.03% on theedge, which limits their reliability in critical appliBIPIA benchmark. The code is publicly avail-cations.