Feiyue Xu
Author directory2026
Staying on Task: Defending Against Prompt Injection via Task Consistency Checking
Feiyue Xu | Jiaming Mu | Fengting Li | Bin Benjamin Zhu | Hongsheng Hu | Qiankun Liu | Shuo Wang | Chaoxiang He | Chao Feng
Proceedings of the 2026 Conference on Empirical Methods in Natural Language Processing
Feiyue Xu | Jiaming Mu | Fengting Li | Bin Benjamin Zhu | Hongsheng Hu | Qiankun Liu | Shuo Wang | Chaoxiang He | Chao Feng
Proceedings of the 2026 Conference on Empirical Methods in Natural Language Processing
Large language models (LLMs) deployed in real-world applications process heterogeneous inputs, including system prompts, user requests, and external content, exposing them to prompt injection attacks. Existing defenses, including prompt-level safeguards, external filters, and source-aware instruction handling, remain brittle against diverse direct and indirect prompt injection attacks. We propose **CBC** (*Consistency Before Complying*), a task-consistency alignment framework to defend against task-redirection prompt-injection attacks. **CBC** characterizes task consistency through semantic conflicts along action, constraint, and domain dimensions, then uses structured reasoning to determine whether newly introduced instructions are consistent with the original task before acting on them. Using targeted synthetic supervision, we train **CBC** to reason about task consistency and further strengthen this capability through dual-objective online alignment while preserving task utility. Across three model families and a diverse set of direct and indirect prompt-injection benchmarks, **CBC** improves defense success rates by up to 13.2 percentage points over the strongest baseline while better preserving task utility under attack. Our code and models can be found at: https://github.com/XOTaichi/CBC-PI.git