PromptLocate: Localizing Prompt Injection Attacks

Yuqi Jia, Yupei Liu, Zedian Shao, Jinyuan Jia, Neil Zhenqiang Gong · DOI

TL;DR

Prompt injection attacks are a growing threat to LLM-powered applications, where attackers subtly embed malicious instructions within user data. This paper introduces PromptLocate, the first method to accurately pinpoint these injected prompts within contaminated data. PromptLocate's ability to localize these attacks is crucial for forensic analysis and recovering the original, intended functionality of LLM applications.

What Problem Does This Paper Address?

Large Language Models (LLMs) are increasingly integrated into real-world applications, from search engines to AI assistants. A significant vulnerability is "prompt injection," where attackers craft malicious inputs that trick the LLM into executing unintended tasks. This is achieved by embedding "injected prompts" (containing instructions and data) into the LLM's input. While detecting these attacks is a challenge, localizing the exact injected prompt within the contaminated data is even more critical. Without precise localization, it's difficult to perform post-attack forensic analysis to understand how the attack happened or to recover the original, clean data to restore the LLM's intended function. Existing defenses primarily focus on prevention or detection, leaving localization largely unexplored.

Methods

PromptLocate tackles the localization problem with a three-step approach:

  1. Semantic Segmentation (Step I): The contaminated data is first broken down into semantically coherent segments. This is done by analyzing the cosine similarity between word embeddings. The goal is to separate injected prompt content from clean data and ensure segments are informative enough for subsequent steps.
  2. Instruction-Contaminated Segment Identification (Step II): This step identifies segments containing injected instructions. It uses a "tailored detector" (an oracle) trained to classify segments, rather than entire data samples. A novel "segment-group-based search strategy" is employed to overcome challenges where instructions might be split across multiple segments.
  3. Data-Contaminated Segment Pinpointing (Step III): This step focuses on identifying segments containing injected data. It leverages the observation that injected data often follows injected instructions and exhibits contextual inconsistency with the original data. It identifies these segments by looking for contextual inconsistencies using a small LLM to estimate probabilities.

Datasets

The paper evaluates PromptLocate on two benchmarks:

  • OpenPromptInjection: This benchmark includes seven natural language tasks (e.g., sentiment analysis, summarization) and is used with eight existing and eight adaptive prompt injection attacks.
  • AgentDojo: This benchmark evaluates prompt injection in LLM agents that interact with environments. It uses GPT-40 as the backend LLM.

A validation dataset, distinct from the evaluation sets, was used to select the optimal segmentation threshold for Step I.

Key Insights and Ideas

  • Segmentation is Key: Breaking down contaminated data into semantically coherent segments is crucial for effective localization, allowing for more granular analysis than treating the entire input as a single unit.
  • Tailored Detectors are Necessary: Standard detectors designed for entire data samples are suboptimal for segment-level classification. PromptLocate's use of a "tailored oracle" significantly improves accuracy.
  • Group-Based Search Outperforms Individual Analysis: For identifying instruction-contaminated segments, evaluating groups of segments is more robust than analyzing each segment in isolation, especially when instructions are fragmented.
  • Contextual Inconsistency is a Strong Signal for Injected Data: Injected data often disrupts the natural flow and meaning of the original content, providing a valuable signal for its identification.
  • Localization Enables Recovery: Successfully localizing and removing injected prompts allows for the recovery of clean data, which can then be used to restore the LLM's intended functionality with high accuracy.

Key Results

PromptLocate demonstrates strong performance across various attacks and benchmarks:

  • OpenPromptInjection: Achieved 0.93-0.99 RL and ES scores, and 0.95-1.00 Precision and Recall across attack settings.
  • AgentDojo: Achieved RL, ES, Precision, and Recall scores above 0.95 for some environments and above 0.85 for others.
  • Attack Effectiveness: After localization and removal by PromptLocate, the Attack Success Value (ASV) dropped significantly, indicating that the attacks were rendered ineffective.
  • Adaptive Attacks: PromptLocate remained effective even against eight adaptive attacks specifically designed to evade its three steps, showing high RL and ES scores.
  • Data Recovery: Recovered data retained 85%-100% of the original performance (PNA-T), demonstrating the effectiveness of PromptLocate in restoring LLM functionality.
  • Runtime: PromptLocate is efficient, taking approximately 11 seconds on average to localize injected prompts on a single GPU.

Limitations and Future Work

The authors acknowledge several limitations and suggest future directions:

  • Natural Segmentation: In scenarios where data already has natural segments (e.g., reviews), PromptLocate can leverage this, but the core Steps II and III remain essential.
  • Adaptive Attacks and Misinformation: PromptLocate's effectiveness can be challenged by adaptive attacks that exploit the LLM's inherent vulnerabilities, especially in cases of misinformation where injected content mimics legitimate data without explicit instructions.
  • Detector Evolution: The performance of PromptLocate relies on the underlying detector used as an oracle. As stronger detectors emerge, they can be tailored to further improve PromptLocate's capabilities.
  • Future Work: The authors suggest developing stronger adaptive prompt injection attacks and designing localization methods with provable security guarantees. They also highlight the need for balancing the risk of imperfect recovery against denial-of-service from discarding all contaminated data.

Summary updated

BibTeX
@inproceedings{jia2026promptlocate,
  author = {Yuqi Jia and Yupei Liu and Zedian Shao and Jinyuan Jia and Neil Zhenqiang Gong},
  title = {{PromptLocate: Localizing Prompt Injection Attacks}},
  booktitle = {SP},
  year = {2026},
  doi = {10.1109/sp63933.2026.00105},
}
Figure