arXiv:2610.22874cs.CLOct 2026

Manuscript Offprint

arXiv:2610.22874

Identify, Classify, Act: Per-Instruction Controlled Compliance for LLMs over External Data

Zesheng Shi, Xue Li, Chenrui Dai, Jing Li

Abstract

LLMs over external data face a per-instruction tension: a single document or tool return often interleaves legitimate directives with adversarial prompt injections, and the model must follow the former while rejecting the latter. Existing defenses suppress or trust all external instructions, collapsing the safety-utility frontier and forcing a choice between over-refusal and over-compliance. We argue the missing capability is per-instruction credit attribution and formalize it as External-Data Instruction Classification, an identify-classify-act decision over each embedded directive. We propose EDIC, a decomposed reward framework for per-instruction compliance. A scene-grounded pipeline injects mixed beneficial and harmful instructions with counterfactual filtering, while a generative judge is initialized by SFT and refined with GRPO to attribute compliance at the instruction level. The judge then produces a reward that separately encourages beneficial compliance and penalizes harmful compliance for RL training. Across two backbones and five benchmarks, EDIC improves both safety and utility over the strongest prior defense, lifting harmful-rejection by up to 7.7% and Arena-Hard-Auto utility by 12.5% on Qwen3-4B. The code repository is hosted at https://github.com/yingyingxia666/EDIC.

WARNING: The paper contains content that may be offensive and disturbing in nature.

1 Introduction

Large language models (LLMs) have rapidly evolved beyond conversational systems and are now being deployed across a wide range of real-world applications (Kang et al., 2026b; He et al., 2026; Gao et al., 2026; Shi et al., 2026; Zeng et al., 2024b,a, 2026). They serve as the reasoning core of retrieval-augmented generation pipelines, browser assistants, tool-using agents, and multi-step workflow systems (Lewis et al., 2020; Nakano et al., 2021; Schick et al., 2023; Yao et al., 2023b; Kang et al., 2026a). In these settings, LLM must interpret and act on externally provided data beyond its control.

However, external data often mixes factual content with instruction-like text. Some embedded instructions are useful, such as formatting rules in API docs or workflow guidelines in medical protocols that help the model complete tasks correctly (Li et al., 2023; Chen et al., 2023; Zhou et al., 2025b; Chou et al., 2026; Shi et al., 2025). Others are harmful, such as indirect prompt injections that try to override the user's goal, extract private data, or divert the model to unrelated objectives (Greshake et al., 2023; Yi et al., 2025; Debenedetti et al., 2024; Zhan et al., 2024; Zhou et al., 2025a). Existing defenses largely treat this as a binary problem, either rejecting all embedded instructions or fully trusting them (Greshake et al., 2023; Yi et al., 2025; Debenedetti et al., 2024). Methods such as instruction hierarchy (Wallace et al., 2024), structured query isolation (Chen et al., 2025a), and external prompt-injection classifiers (Meta AI, 2024) improve robustness against malicious instructions, but they indiscriminately suppress external directives, leading to over-refusal and degraded performance on legitimate tasks. The core challenge isn't uniform rejection but fine-grained classification that distinguishes safe, task-relevant embedded instructions from adversarial ones and translates that judgment into appropriate actions.

We address this gap by formalizing the problem as External-Data Instruction Classification (EDIC). We construct a stage-wise data synthesis pipeline that embeds both beneficial and harmful instructions into realistic external contexts. Then we train a two-stage system, which consists of a generative judge model that assigns per-instruction compliance in outputs and a CoT response model. Re-

☑ Corresponding author.

Figure

Figure 1: External data contains both beneficial instructions and harmful prompt injections. Always rejecting external instructions leads to over-refusal, while always trusting them allows attacks to succeed. EDIC classifies each embedded instruction and responds accordingly.

response model is optimized via supervised fine-tuning followed by judge-guided reinforcement learning. Judge assigns separate score for following beneficial instructions and penalties for following harmful instructions, enabling LLM to learn controlled compliance instead of uniform obedience or rejection. On our evaluation suite spanning utility and prompt-injection security benchmarks, EDIC achieves 91.2% harmful-rejection and 89.5% benign-follow on Qwen3-4B, outperforming the strongest reasoning-based baseline ReasAlign by 7.7pp on safety and 12.5pp on Arena-Hard-Auto utility. The same trend holds on Llama-3.1-8B (92.8% harmful-rejection, 91.7% benign-follow), confirming that fine-grained instruction classification resolves the safety-utility trade-offs that blanket-defense approaches can't avoid.

Our contributions are as follows:

• We define external-data instruction classification as a unified task bridging prompt-injection defense and task-grounded reasoning, formalizing identify-classify-act framework for mixed-instruction external data.

• We present a data synthesis and validation pipeline that builds realistic mixed-instruction contexts with counterfactual quality checks.

• We propose a judge-guided training recipe in which a generative judge provides decomposed per-instruction rewards, enabling LLM to learn controlled compliance by SFT followed by reinforcement learning. The full system named EDIC achieves the best utility-safety trade-offs on several benchmarks.