Manuscript Offprint

arXiv:2610.26013

SpanGuard: Decoupling Instruction Localization from Authorization for Lightweight IPI Defense

Yinxiang Wang, Zehua Ma, Kejiang Chen, Weiming Zhang, Han Fang

ABSTRACT

LLM-based guardrails have shown strong effectiveness against indirect prompt injection (IPI), especially when powered by highly capable language models. However, their effectiveness depends heavily on model capability: once the guardrail model becomes smaller or weaker, detection performance can degrade substantially. This raises a natural question: can we retain strong IPI defense while relying only on a small LLM? To understand why strong models are needed, we revisit what an LLM guardrail actually does. Detecting an IPI requires it to simultaneously locate potentially injected instructions within heterogeneous tool outputs and determine whether those instructions are authorized by the user's request. We find that the challenge for small models arises largely from having to satisfy both requirements jointly, rather than from either subproblem alone. This observation suggests a different path toward lightweight defense: explicitly decouple localization from decision-making. In particular, we find that localization can be handled without strong language-model reasoning, as injected instructions are often semantically discontinuous with their surrounding content and can therefore be partitioned into local regions through lightweight, unsupervised segmentation. Once the observation is partitioned into local regions, the remaining authorization check becomes a localized judgment that can be handled by a small LLM. Building on this insight, we design a lightweight IPI guardrail that performs attack-agnostic localization followed by block-level authorization judgment with a small language model. By separating where to look from what to decide, our approach substantially reduces the capability required of the guardrail model while preserving strong defense performance. Empirically, our guardrail achieves a 0.32% attack success rate with negligible loss in benign utility, while remaining effective with substantially smaller models. These results show that strong IPI defense need not rely on strong LLMs when localization and decision-making are explicitly decoupled.

1 INTRODUCTION

Large language models (LLMs) are increasingly deployed as autonomous agents that reason over tasks, invoke tools, and interact with external environments (Yao et al., 2022; Schick et al., 2023; Wang et al., 2024). To complete real-world tasks, these agents must continuously consume tool outputs such as web pages, messages, documents, and API responses, and use them to guide subsequent actions. This reliance on external content makes LLM agents particularly vulnerable to indirect prompt injection (IPI) (Greshake et al., 2023; Liu et al., 2024), where adversaries embed malicious instructions into otherwise legitimate data encountered by the agent. Because instructions and external data are presented within the same context, the agent must determine not only what the content says, but also whether an instruction is actually authorized by the user's request. Failures in this distinction can redirect the agent toward unintended actions, including unauthorized tool use, sensitive-data disclosure, and other harmful behavior.

Figure

Figure 1: Comparison between existing LLM-based IPI sanitizers and SpanGuard.

Existing defenses against IPI broadly attempt to prevent untrusted external content from overriding the user's intent. Some approaches strengthen the victim model through security-oriented fine-tuning or alignment (Chen et al., 2025a;b), while others train dedicated detectors to identify injected instructions before they influence the agent (ProtectAI.com, 2023; Li et al., 2025; Liu et al., 2025; Chennabasappa et al., 2025). Prompting-based defenses instead introduce additional instructions or structural cues to help the model distinguish trusted instructions from external data (Hines et al., 2024). More recently, a growing line of work directly employs LLMs as guardrails, either by inspecting untrusted content for injected instructions (Shi et al., 2025) or by monitoring the agent's downstream behavior to determine whether it is being driven by untrusted information (Zhu et al., 2025; He et al., 2026; Kim et al., 2026). By leveraging the general semantic reasoning ability of LLMs, these approaches can provide strong protection across diverse attack forms without relying on narrowly defined attack patterns.

Despite their strong performance, LLM-based guardrails introduce a new dependence: their effectiveness is closely tied to the capability of the underlying guardrail model. A sufficiently capable LLM can jointly interpret heterogeneous external content, identify suspicious instructions, and reason about whether those instructions are consistent with the user's intent. However, when the same guardrail is instantiated with a smaller model, detection performance can deteriorate substantially. In other words, existing LLM-based defenses often obtain strong security by relying on strong models, making effective IPI protection costly to deploy. This raises a natural question: can we retain strong IPI defense while relying only on a small LLM?

To answer this question, we revisit what an LLM guardrail is actually required to do. Detecting an IPI involves two distinct requirements: locating potentially injected instructions within heterogeneous tool outputs, and determining whether those instructions are authorized by the user's request. Existing LLM-based guardrails largely ask a single model to satisfy both requirements jointly over the full observation. We find that this coupling, rather than either requirement alone, is a major source of difficulty for small models: they must simultaneously search for the relevant region and reason about its authorization. This suggests a different route to lightweight defense. Instead of asking a small LLM to perform both tasks at once, we explicitly separate where to look from what to decide, decoupling localization from authorization, as illustrated in Figure 1.

Building on this decoupling, we develop SpanGuard, a lightweight IPI guardrail with two stages. First, SpanGuard performs attack-agnostic localization by partitioning heterogeneous tool outputs into semantically coherent regions through lightweight, unsupervised segmentation. This stage does not attempt to recognize specific attacks, but instead uses semantic discontinuities to expose local regions that can be examined independently. Second, SpanGuard applies a small LLM to each region and determines whether the contained instruction is authorized by the user's request. By removing the need for the LLM to jointly search for suspicious content and reason about its authorization, SpanGuard reduces the guardrail model to a localized decision-maker, substantially lowering the capability required for effective IPI defense.

We evaluate SpanGuard on AgentDojo, where a 7B guardrail model achieves a 0.32% attack success rate with negligible loss in benign utility. More importantly, SpanGuard remains effective across substantially smaller and diverse models, showing much lower dependence on guardrail capability than existing LLM-based defenses.

Our contributions are threefold:

(1) We identify the coupling between instruction localization and authorization as a key source of the capability bottleneck in LLM-based IPI guardrails.

(2) We develop a lightweight IPI guardrail that decouples localization from authorization through unsupervised semantic-discontinuity-based segmentation and block-level authorization reasoning.

(3) We demonstrate that our approach achieves a 0.32% attack success rate on AgentDojo with negligible utility loss, while remaining effective across substantially smaller and diverse guardrail models than existing approaches.

References (27)