Manuscript Offprint

arXiv:2608.22248

Beyond Over-Refusal: Defending Indirect Prompt Injection via Latent Instruction Manifolds

Jiahao Chen, Rui Yin, Xinfeng Li, Qianli Ma, Tianyu Du, Zhihui Fu, Jun Wang, Zhaoxiang Wang, Shouling Ji

Abstract

Large Language Models (LLMs) have been integrated into complex ecosystems (e.g., Code Agents), while the Indirect Prompt Injection (IPI) attacks have emerged as critical barriers to their safe deployment. Attackers exploit LLMs' indistinguishability between "instructions" and "data" to manipulate LLMs via maliciously injected instructions. Existing defenses, however, face an intractable safety-utility trade-off: most guardrails either incur high latency or suffer from severe over-refusal. In this paper, we first demonstrate that LLMs can separate instruction from data intrinsically with both theoretical and empirical evidence. Inspired by this insight, we propose AEGIS (Adaptive Ensemble Guard for Injection Shielding). AEGIS extracts instruction-sensitive projectors to identify malicious instructions and leverages a Unified Multi-Layer Consensus mechanism that aggregates topologically distinct signals across the network depth. Empirical evaluations show that AEGIS achieves remarkable detection performance against both heuristic and optimization-based attacks compared to baselines, highlighting its potential to mitigate IPI. Code is available at Github

1 Introduction

The development of Large Language Models (LLMs) from passive text generators to active agents has demonstrated remarkable performance across a wide range of Natural Language Processing (NLP) tasks (Taori et al., 2023; Ouyang et al., 2022). By integrating with Retrieval-Augmented Generation (RAG) and external tool APIs (e.g., search engines), LLMs now function as core components within complex application ecosystems, capable of executing code and managing user data (Shi et al., 2025; Zhang et al., 2025). However, this integration exposes a severe vulnerability within LLMs (Willison, 2022): the lack of explicit distinction between instructions (control flow) and knowledge (external inputs) within the context.

This ambiguity enables Indirect Prompt Injection (IPI) attacks, where adversaries embed malicious commands into retrieved data streams, such as web pages or emails, to hijack the model's behavior (Willison, 2022; Zhang et al., 2025). Such attacks can lead to severe consequences, including data exfiltration (Lin et al., 2026), unauthorized actions, and the propagation of harmful content (Hui et al., 2024; Collu et al., 2025). The demand for robust defense mechanisms has become paramount.

Existing countermeasures, however, struggle to reconcile the Safety-Utility trade-off. IPI Sanitization approaches, such as structured queries (Chen et al., 2025a) and token-wise filtering (Geng et al., 2025; Liu et al., 2025a), attempt to neutralize threats by restructuring or scrubbing the input stream. Since these methods necessitate the rigorous filtering of every input, they impose large utility penalties, incurring high computational overheads and often degrading the semantic integrity of complex user queries. Conversely, IPI Detection guardrails aim to identify and block malicious inputs. However, whether relying on external classifiers (Alon and Kamfonas, 2023; BlueteamAI, 2024) or internal steering mechanisms (Hung et al., 2025), these methods suffer from severe over-refusal (Li et al., 2025a) and compromise the model's general availability and helpfulness.

In this work, we challenge the previous assumption that the conflation of instruction and data is indistinguishable for LLM (Zverev et al.). We argue that the key to resolving this trade-off lies in the intrinsic geometry of the LLM's latent space (Jin et al., 2026), shaped by its two-stage training paradigm. We posit that: Pre-training forces knowledge representations to occupy a high-dimensional, high-entropy manifold to maximize information capacity, whereas Instruction Tuning collapses instruction representations into a separated, compact operator subspace (Park et al., 2024; Zou et al.,

2023a). Consequently, detection should not rely on black-box classification, but on identifying signatures within this compact instruction manifold.

Inspired by these insights, here we introduce AEGIS (Adaptive Ensemble Guard for Injection Shielding), a lightweight detection framework that secures LLMs without training. AEGIS distinguishes malicious instructions from benign data by filtering out superficial phrasing differences to isolate the core “imperative intent.” To further ensure robustness without over-refusal, we introduce a Unified Multi-Layer Consensus mechanism. Instead of relying on a single layer, which can be noisy, AEGIS aggregates evidence across multiple network depths. This ensures that an input is flagged as an attack only if it exhibits a persistent malicious signal throughout the model’s processing, eliminating false positives caused by transient noise. Our contributions are summarized as:

• We characterize the geometric relationship between instruction and knowledge representations, effectively distinguishing instructions from the high-entropy manifold of the untrusted external knowledge.

• We propose AEGIS that combines distribution-aware threshold calibration with a multi-layer voting mechanism. Beyond empirical efficacy, we derive a theoretical error bound for the False Positive Rate (FPR) and provide a geometric analysis for the ensemble’s robustness radius against latent perturbations.

• Extensive evaluations on eight IPI attacks with ten baselines demonstrate that AEGIS achieves remarkable detection performance. Crucially, it improves the safety-utility balance under standard benign workloads, reducing the FPR on benign tasks to negligible levels (< 1%).

References (19)