Abstract
Safety alignment in large language models (LLMs) induces over-refusals—where LLMs decline benign requests due to aggressive safety filters. We analyze this phenomenon in retrieval-augmented generation (RAG), where both the query intent and retrieved context properties influence refusal behavior. We construct RagRefuse, a domain-stratified benchmark spanning medical, chemical, and open domains, pairing benign and harmful queries with controlled context contamination patterns and sizes. Our analysis shows that context arrangement, domain, and harmful-text density trigger refusals even on benign queries, with effects depending on model-specific alignment choices. To mitigate over-refusals, we introduce SafeRAG-Steering, a model-centric embedding intervention that steers the embedding regions towards the confirmed safe, non-refusing output regions at inference time. This reduces over-refusals in contaminated RAG pipelines while preserving legitimate refusals.
Introduction: The Over-Refusal Problem in RAG
Safety alignment is a critical component of modern LLM deployment, yet it often results in "over-refusal"—the rejection of perfectly safe user queries. In Retrieval-Augmented Generation (RAG) systems, this problem is significantly amplified. Even when a user's intent is benign (e.g., asking about chemical properties), the retriever may pull in "contaminated" documents containing harmful snippets (e.g., instructions for illicit substances). These snippets can inadvertently trigger the model's safety guardrails, leading to a refusal of a legitimate request.
The RAGRefuse Benchmark
To systematically study this phenomenon, the authors introduced RAGRefuse, a domain-stratified benchmark designed to evaluate RAG over-refusal. The dataset consists of 2,970 samples across six high-risk domains: Medical, Chemical, Cybersecurity, Legal, Financial, and General. It pairs benign and harmful queries with controlled "contamination patterns," such as mixtures of benign (B) and harmful (H) contexts (e.g., BBB, BHH, or HHH). This structure allows researchers to isolate how specific context properties, rather than just query intent, drive model behavior.
SafeRAG-Steering: Inference-Time Intervention
The proposed solution, SafeRAG-Steering, is a lightweight, model-centric approach that intervenes in the model's latent space during inference. The authors discovered that "safe" (answering) states and "refusal" states are linearly separable within the model's middle hidden layers (typically layers 8-23).
By calculating a "steering vector"—the difference between the average embedding of successful safe responses and the average embedding of over-refusals—the method can "nudge" the model's internal representation toward the safe region. This zero-shot method requires no fine-tuning; it simply adds the steering vector (scaled by a coefficient $\alpha$) to the model's residual stream during generation.
Key Insights and Results
Analysis using RAGRefuse revealed several critical triggers for over-refusal:
- Context Density: Refusal frequency grows monotonically with the number of harmful snippets in the retrieved context. Increasing context length from 3 to 7 snippets can increase refusals by up to 25%.
- Domain Sensitivity: Models exhibit varying levels of caution across domains. For example, Llama-3.1-8B is significantly more prone to over-refusal in the Chemical and Medical domains than in Cybersecurity.
- Linear Separability: The effectiveness of a simple vector addition confirms that the model's decision to refuse is often encoded linearly in its hidden states.
In empirical tests, SafeRAG-Steering proved highly effective. For Llama-3.1-8B, the baseline over-refusal rate of 53.4% was slashed to just 4.3%. For Qwen-1.5-7B, over-refusals were eliminated entirely. Crucially, the steering is tuned to preserve legitimate refusals for genuinely harmful queries.
Conclusion
SafeRAG-Steering offers a promising, computationally efficient path toward making RAG systems more reliable. By addressing the model's internal representations rather than just filtering inputs, it mitigates the "trigger-happy" nature of safety alignment in contaminated environments while maintaining essential safety guardrails.
Summary updated