Abstract
Ensuring the safety of Large Language Models (LLMs) against harmful content generation and adversarial "jailbreaking" is a critical challenge. Traditional model-based safeguarding approaches often struggle with the high dimensionality of LLM feature spaces. We present ReGA (Representation-Guided Abstraction), a scalable and interpretable framework that builds a lightweight safety monitor by focusing on low-dimensional safety representations. ReGA achieves high detection accuracy (up to 0.985 AUROC) while maintaining negligible computational overhead, offering a transparent alternative to black-box safety classifiers.
Introduction
As LLMs are increasingly integrated into complex software ecosystems, the risk of generating toxic, biased, or harmful content grows. While alignment techniques like Reinforcement Learning from Human Feedback (RLHF) provide a baseline of safety, they are often superficial and susceptible to sophisticated adversarial attacks.
Model-based analysis offers a formal path to safety by constructing simplified abstractions (e.g., state machines) of a neural network's internal behavior. However, the "scalability hurdle" has historically limited this approach; the vast internal feature spaces of LLMs typically require millions of states for an effective abstraction. ReGA addresses this by focusing on safety-critical representations rather than the entire feature space, enabling the construction of efficient, formal safety monitors.
The ReGA Framework
The core innovation of ReGA is the use of Representation-Guided Abstraction. By identifying specific directions in the model's hidden states that correspond to safety concepts, the framework can build a highly compressed yet accurate model of the LLM's safety logic.
The ReGA pipeline operates in three distinct phases:
- Safety Representation Extraction: Hidden states are extracted from the middle layers of the target LLM using a contrastive dataset of safe and harmful prompts. Principal Component Analysis (PCA) is then applied to isolate the primary "safety directions."
- Abstract Model Construction: These low-dimensional representations are clustered via K-Means into a small set of abstract states (typically 8 to 64). These states are linked into a Discrete Time Markov Chain (DTMC), which captures the transition probabilities between safety states during text processing.
- Runtime Safeguarding: During inference, ReGA monitors the internal states of the LLM. It computes a safety score based on the current abstract state and the transition probability from the previous state. If this score falls below a predefined threshold, the system triggers a refusal at either the prompt or conversation level.
Experimental Setup
ReGA was evaluated across six prominent open-source LLMs: Llama-2, Mistral, Qwen, Vicuna, Koala, and Baichuan. The framework was trained using a contrastive dataset derived from Alpaca (safe) and AdvBench (harmful). Evaluation benchmarks included:
- Safety Benchmarks: HarmBench, JailbreakBench, and RepE-Harmful/Safe.
- Real-world Scenarios: MT-Bench and Chat 1M.
- Adversarial Attacks: Specific tests against technical jargon, misspellings, authority endorsement, and the complex "WildJailbreak" dataset.
Results and Analysis
ReGA demonstrates exceptional performance in distinguishing between safe and harmful inputs across diverse model architectures.
Key Findings:
- High Detection Accuracy: ReGA achieved an average AUROC of 0.975 at the prompt level and 0.985 at the conversation level. As shown in the distribution plots, there is a clear separation between the safety scores of harmful and safe inputs.
- Layer Sensitivity: The authors identified that middle layers are the most effective for safety modeling. Early layers focus on low-level linguistic features, while later layers reflect the final output decision; the middle layers capture the internal conceptual conflict between safety and harm.
- Efficiency and Scalability: Unlike previous methods requiring millions of states, ReGA remains effective with as few as 8-64 abstract states. This drastic dimensionality reduction ensures negligible latency during runtime.
- Interpretability: The use of a DTMC allows developers to trace a refusal back to specific state transitions, providing a level of transparency missing from standard neural classifiers.
Discussion and Limitations
While ReGA is highly effective, its performance is inherently tied to the quality of the contrastive dataset used for PCA. Biases in the training data may lead to biased safety monitoring. Additionally, while ReGA handles many adversarial tactics well, it showed slightly lower performance on the "WildJailbreak" dataset, which features highly nuanced, multi-layered prompts.
Future work will explore dynamic updates to the DTMC to adapt to emerging threats in real-time and further refine the framework's ability to handle complex, multi-turn adversarial reasoning.
Summary updated