TLDR: PromptLocate is the first method to localize prompt injection attacks in Large Language Models (LLMs). It uses a three-step process: semantically segmenting contaminated data, identifying instruction-contaminated segments with a tailored detector and group-based search, and pinpointing data-contaminated segments based on contextual inconsistency. This approach accurately localizes injected prompts across various attacks, enabling post-attack forensic analysis and data recovery, significantly improving LLM security.
Large Language Models (LLMs) are now integral to many applications, from AI-powered search to summarizing product reviews. These powerful AI systems operate by taking a “prompt” as input, which typically consists of an instruction and data, to complete a specific task. However, when the data comes from untrusted sources, LLMs become vulnerable to a significant threat known as prompt injection attacks.
In a prompt injection attack, an attacker embeds a hidden, malicious prompt—containing both injected instructions and data—within the legitimate input data. This tricks the LLM into performing an attacker-specified task instead of its intended one. Imagine an LLM summarizing web pages, and a malicious comment on a page directs the LLM to promote a harmful website. Or a product review subtly injects an instruction to declare a product “useless,” regardless of other reviews. These scenarios highlight the critical need to identify and isolate these injected prompts.
While defenses against prompt injection have focused on prevention and detection, the crucial step of “localization”—pinpointing exactly where the injected prompt lies within the contaminated data—has remained largely unexplored. Localizing these malicious prompts is vital for post-attack analysis, identifying the source of the attack, and recovering clean data to ensure the LLM can perform its legitimate tasks accurately.
Introducing PromptLocate: The First Localization Method
Bridging this critical gap, researchers Yuqi Jia, Yupei Liu, Zedian Shao, Jinyuan Jia, and Neil Zhenqiang Gong have proposed PromptLocate, the first method specifically designed for localizing injected prompts within contaminated data. PromptLocate employs a sophisticated three-step approach to accurately identify these hidden threats.
Step 1: Smart Data Segmentation
The first challenge in localization is breaking down the contaminated data into meaningful units. Simple methods, like splitting by individual words or sentences, often fall short. If an injected prompt is part of a sentence, sentence-based splitting won’t isolate it. If it’s too fragmented by word-based splitting, it loses context. PromptLocate addresses this by using a “semantically driven segmentation strategy.” It processes the data word by word, calculating the similarity between consecutive words’ meanings (using their embeddings). When this similarity drops below a certain threshold, it indicates a semantic shift, and a segment boundary is created. This ensures that injected prompts and clean data are separated into distinct, coherent segments, making subsequent identification more effective.
Step 2: Identifying Injected Instructions
Once the data is segmented, PromptLocate moves to identify segments containing injected instructions. This step faces challenges because injected instructions might be split across multiple segments, or standard detectors aren’t designed for small segments. To overcome this, PromptLocate uses a specially “tailored detector,” referred to as an “oracle,” which is trained to classify individual segments rather than entire data samples. Furthermore, it employs a “group-based search strategy.” Instead of evaluating segments in isolation, it examines groups of segments, efficiently identifying the earliest segment where the concatenation with preceding segments is classified as contaminated. This multi-round process helps pinpoint all instruction-contaminated segments, even if they are non-consecutive.
Step 3: Pinpointing Injected Data
Also Read:
- LatentBreak: A Stealthy New Method for Bypassing LLM Safety Measures
- Uncovering Hidden Dangers: A New Approach to Red-Teaming LLMs with Web Search
Proven Effectiveness and Real-World Applications
PromptLocate has been rigorously evaluated against a wide array of prompt injection attacks, including eight existing attacks and eight adaptive attacks specifically designed to evade localization. The results are impressive: PromptLocate consistently achieves high accuracy in localizing injected prompts, significantly outperforming traditional attribution methods used in interpretable machine learning. It maintains its effectiveness even when the underlying tailored detector is not perfectly accurate, thanks to its robust multi-step design.
The utility of PromptLocate extends to crucial real-world applications. For instance, in “post-attack forensic analysis,” it can identify malicious reviews or comments, helping trace the responsible users. In “data recovery,” PromptLocate can remove injected prompts from contaminated data, allowing the LLM to process the cleaned data and accurately complete its intended task, thereby preventing denial-of-service by simply discarding all contaminated inputs. This effectively acts as a form of input sanitization for LLMs, a challenging task given the fluid nature of “instruction” and “data” in these models.
This groundbreaking work marks a significant step forward in securing LLM-integrated applications. For more technical details, you can read the full research paper here.


