Advancing LLM Safe Alignment with Safety Representation Ranking

Tianqi Du, Zeming Wei, Quan Chen, Chenheng Zhang, Yisen Wang · Submission to ICLR 2026 · Rejected

TL;DR

Rather than altering decoding dynamics or relying on heavy external LLM judges, Safety Representation Ranking (SRR) extracts internal hidden states from a frozen language model to rank candidate completions by safety. By pairing a tiny (<5M parameter) single-layer Transformer ranker with listwise contrastive learning, SRR filters out harmful outputs under jailbreak attacks while leaving the model’s natural reasoning capabilities untouched.

What Problem Does This Paper Address?

Current defenses against malicious prompts and jailbreak attacks generally rely on two paradigms, both of which introduce noticeable trade-offs:

  1. Decoding-time interventions: Methods that modify token logits or insert safe prompts often degrade output fluency and hurt performance on benign queries.
  2. Post-generation external judges (e.g., LLM-as-a-Judge): These add substantial computational latency and frequently suffer from high false-positive rates (over-refusal), rejecting harmless queries.

Traditional reward models evaluate only the final surface text, often missing nuanced safety indicators. The authors address this by asking: Can an LLM's own internal representations be used at inference time to select safe completions without modifying how the model generates tokens?

Methods

SRR uses a generate-and-rank approach powered by the base model's internal representations:

[Prompt + Candidates] 
       │
       ▼
 [Frozen Base LLM] ──(Extract hidden states from ~bottom 25% layers)
       │
       ▼
[Linear Projection] ──(Map d=4096 down to lightweight space)
       │
       ▼
[1-Layer Transformer Ranker] ──(Cross-attend prompt & candidates)
       │
       ▼
[Cosine Similarity + Listwise KL Loss] ──► Select top-ranked safe response
  • Candidate Generation: The frozen base LLM samples $m$ candidate responses via stochastic decoding (injecting adversarial prompts during training to generate hard negatives). Responses are labeled as safe ($y_i=1$) or unsafe ($y_i=0$) using rule/keyword filters.
  • Representation Extraction: The model extracts the last-token hidden state from intermediate layers (around the bottom 25% of layers) for both the prompt ($h_{\text{inst}}$) and each candidate ($h_{\text{resp}, i}$). Intermediate states provide richer semantic representations than final layers, which are heavily biased toward next-token emission.
  • Lightweight Transformer Scorer: Representations are projected into a lower-dimensional space and passed through a single-layer Transformer encoder (<5M parameters) allowing the prompt embedding to cross-attend to all candidates.
  • Listwise Optimization: The model computes cosine similarity between the contextualized prompt and candidate representations. Scores are normalized with a temperature-scaled softmax ($\hat{p}_i$) and optimized against a uniform target distribution over all safe candidates ($p^*_i = 1/k$) using Kullback–Leibler (KL) divergence.

Datasets

The authors evaluated SRR across three base models (Qwen2.5-7B-Instruct, Mistral-7B-v0.3, and Vicuna-7B-v1.5) across multiple tasks:

  • Safety & Jailbreaking: HarmBench (standard 200 harmful prompts), SorryBench, and JailbreakBench.
  • Privacy: Harmcopy (evaluating copyright/privacy violations).
  • Fairness: BBQ (Bias Benchmark for QA, a 3-choice ambiguity QA dataset).
  • Utility / Benign Tasks: MATH (12,500 competition math problems) and MBPP (500 Python coding problems).

Key Insights and Ideas

  • Latent space carries clearer safety signals than surface text: Surface-level safety filters can be fooled by jailbreak formatting, but the underlying transformer representations retain distinct signatures when handling harmful intent.
  • Separating generation from safety filtering prevents capability degradation: By letting the base model generate responses naturally and acting purely as a reranker, SRR avoids altering the token distribution on standard queries.
  • Extreme parameter efficiency: A single Transformer layer with fewer than 5M parameters substantially outperformed a pretrained GPT-2 reward model (which has ~20× more parameters).

Key Results

  • Safety Ranking Accuracy: Across HarmBench, SorryBench, and JailbreakBench, SRR achieved average ranking accuracies of 88.10%, 87.90%, and 90.30%, outperforming a GPT-2 reward baseline (44.66%, 54.93%, and 62.46%).
  • Cross-Dataset Generalization: A ranker trained on one benchmark maintained high accuracy on unseen benchmarks (e.g., HarmBench $\rightarrow$ JailbreakBench achieved 86.40% average accuracy), showing that it learns general safety features rather than dataset-specific artifacts.
  • Broader Alignment: SRR generalized to privacy violation detection on Harmcopy (94.28% average accuracy) and improved fairness ranking on BBQ to 52.52% (well above the random baseline of ~33%).
  • Real-World Attack Mitigation: When selecting among live generations under jailbreak attacks, SRR improved safe response rates over standard greedy decoding (First choice) across all benchmarks (e.g., on JailbreakBench, accuracy rose from 24.58% to 39.00%).
  • Zero Penalty on Benign Tasks: On MATH (68.7% baseline) and MBPP (60.6% baseline), applying SRR yielded virtually unchanged accuracies (68.5%–69.1% on MATH; 60.8%–61.6% on MBPP).

Limitations and Future Work

  • Heuristic Layer Selection: Hidden states were taken from roughly the bottom 25% of layers without systematic sensitivity analysis across different architectures.
  • Coarse Supervision: Training relied on binary safe/unsafe labels verified by keyword matching, limiting the ranker's ability to capture subtle, non-keyword-based toxicity.
  • Vulnerability to Adaptive Attacks: While robust against standard jailbreaks, SRR has not yet been stress-tested against white-box attacks designed to trick its latent cosine similarity space.

Summary updated

BibTeX
@inproceedings{du2025advancing,
  author = {Tianqi Du and Zeming Wei and Quan Chen and Chenheng Zhang and Yisen Wang},
  title = {{Advancing LLM Safe Alignment with Safety Representation Ranking}},
  booktitle = {R2-FM @ ICML},
  year = {2025},
  url = {https://openreview.net/forum?id=BfWptIx53G},
}
Figure