[Paper Review] ReasAlign: Reasoning Enhanced Safety Alignment against Prompt Injection Attack
ReasAlign uses structured reasoning and a test-time judge to detect and mitigate indirect prompt-injection attacks, improving security while maintaining utility close to undefended models. It outperforms Meta SecAlign across multiple benchmarks, including CyberSecEval2.
Large Language Models (LLMs) have enabled the development of powerful agentic systems capable of automating complex workflows across various fields. However, these systems are highly vulnerable to indirect prompt injection attacks, where malicious instructions embedded in external data can hijack agent behavior. In this work, we present ReasAlign, a model-level solution to improve safety alignment against indirect prompt injection attacks. The core idea of ReasAlign is to incorporate structured reasoning steps to analyze user queries, detect conflicting instructions, and preserve the continuity of the user's intended tasks to defend against indirect injection attacks. To further ensure reasoning logic and accuracy, we introduce a test-time scaling mechanism with a preference-optimized judge model that scores reasoning steps and selects the best trajectory. Comprehensive evaluations across various benchmarks show that ReasAlign maintains utility comparable to an undefended model while consistently outperforming Meta SecAlign, the strongest prior guardrail. On the representative open-ended CyberSecEval2 benchmark, which includes multiple prompt-injected tasks, ReasAlign achieves 94.6% utility and only 3.6% ASR, far surpassing the state-of-the-art defensive model of Meta SecAlign (56.4% utility and 74.4% ASR). These results demonstrate that ReasAlign achieves the best trade-off between security and utility, establishing a robust and practical defense against prompt injection attacks in real-world agentic systems. Our code and experimental results could be found at https://github.com/leolee99/ReasAlign.
Motivation & Objective
- Motivate safe operation of LLM-based agents by defending against indirect prompt injection attacks.
- Develop a reasoning-based internal guardrail that analyzes user intent and external data separately from injected content.
- Leverage structured reasoning and a judge-based test-time scaling to select the best reasoning trajectory.
- Maintain high task utility while significantly reducing attack success rate (ASR) compared to prior guardrails.
- Demonstrate robustness across general knowledge, instruction-following, and agentic workflow benchmarks.
Proposed method
- Construct a structured reasoning dataset for injection defense by synthesizing injection samples from SQuADv2, TaskTracker, and BeaverTails.
- Use a three-stage reasoning process (Problem Analysis, Reasoning, Final Answer Generation) with explicit highlighting of injected instructions.
- Apply Low-Rank Adaptation (LoRA) instruction tuning for safety alignment on the reasoning dataset.
- Introduce a test-time scaling (beam search with a logic judge) to score and select the best reasoning trajectory using Direct Preference Optimization (DPO) to train the judge.
- Evaluate on general knowledge, instruction-following, and agentic workflow benchmarks to compare utility and ASR against undefended baselines and prior guardrails.
- Implement experiments on Llama-3.1-8B-Instruct and, for some comparisons, Qwen2.5-14B-Instruct to test generalization.
Experimental results
Research questions
- RQ1RQ1: How does ReasAlign perform in terms of utility and security across general knowledge, instruction-following, and agentic tasks?
- RQ2RQ2: Does incorporating reasoning improve defense against prompt injection attacks compared to prior guardrails?
- RQ3RQ3: How effective is the test-time scaling (node-based reasoning selection) for reliability and defense?
- RQ4RQ4: What is the computational overhead introduced by the reasoning process and scaling mechanism?
Key findings
- ReasAlign maintains strong general knowledge performance with only slight degradation relative to the undefended model and outperforms SecAlign and Meta SecAlign on most benchmarks.
- Under prompt injection attacks, ReasAlign achieves higher utility and substantially lower ASR than competing guardrails (e.g., CyberSecEval2 ASR reduced to 3.6% from 21.8% in ablation vs. 74.4% for Meta SecAlign).
- In instruction-following benchmarks, ReasAlign reduces ASR to 3.6% on CyberSecEval2 and 1.1% on SEP, with notable utility advantages over Meta SecAlign under attack.
- In agentic workflows, ReasAlign achieves best utility on AgentDojo and can reduce ASR to zero on certain setups, with cross-model generalization showing strong defense on Qwen2.5-14B-Instruct.
- Ablation shows reasoning contributes significantly to security gains, with direct-answer training yielding higher ASR than reasoning-enabled training (ASR drop from 21.8% to 3.6% on CySE and substantial reductions on SEP).
- Node-scale ablations indicate increasing N from 1 to 3 improves utility and reduces ASR under attack, with diminishing returns beyond N=3.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.