RAG Makes Guardrails Brittle? Investigating Robustness of Guardrails under RAG-style Contexts
Organizations: Carnegie Mellon University · Oracle Cloud Infrastructure · University of Pennsylvania
Abstract
With the increasing adoption of large language models (LLMs), ensuring the safety of LLM systems has become a pressing concern. External LLM-based guardrail models have emerged as a popular solution to screen unsafe inputs and outputs, but they are themselves fine-tuned or prompt-engineered LLMs vulnerable to data distribution shifts. In this paper, taking Retrieval Augmentation Generation (RAG) as a case study, we investigate how robust LLM-based guardrails are against additional information embedded in the context. Through a systematic evaluation of 3 Llama Guards and 2 GPT-oss models, we find that inserting benign retrieved documents flips the judgments of input and output guardrails in around 11% and 8% of cases respectively, with the majority of these flips (72% and 64%) reversing previously correct decisions. We further analyze the effect of each component in the augmented context: retrieved documents, user query, and LLM response. Two tested mitigations reveal that the robustness gap is not easily closed. These results expose a context-robustness gap in current guardrails.
Figures & tables
Appendix figures & tables10 assets
Supplementary material from the paper’s appendix.
Appendix
| Responses to | llamaguard2 | llamaguard3 | llamaguard4 | gpt-oss-20b | gpt-oss-120b |
|---|---|---|---|---|---|
| Unsafe queries | 56.66 | 33.33 | 80.00 | 73.33 | 76.66 |
| Safe queries | 90.00 | 80.00 | 70.00 | 40.00 | 30.00 |
| Dataset | Total Number of Data | Reference |
|---|---|---|
| Harmbench | 400 | Mazeika et al. (2024) |
| AdvBench | 520 | Zou et al. (2023) |
| AART | 3,269 | Radharapu et al. (2023) |
| HarmfulQA | 1,960 | Bhardwaj and Poria (2023) |
| DangerousQA | 200 | Shaikh et al. (2023) |
| CategoricalHarmfulQA | 550 | Bhardwaj et al. (2024) |
| Dataset | Total Number of Data | Reference |
|---|---|---|
| XStest | 250 | Röttger et al. (2024) |
| OR-Bench-Hard-1K | 1,319 | Cui et al. (2025) |
LLM Guardrails
Large language model guardrails detect or constrain harmful outputs, prompt attacks, and unsafe agent actions before they cause harm.
See all 218 papers