On-Policy Distillation for LLM Safety: A Routing Approach to Template-Robust Realignment

Yongjian Guo, Wanlun Ma, Lingyu Shen, Xi Xiao, Sheng Wen
7/29/2026
cs.AIcs.CLcs.CR

No confident code implementation found for this paper.

Abstract

Fine-tuning is the dominant paradigm for specializing large language models (LLMs), yet it exposes a critical vulnerability: malicious data providers can embed harmful behaviors into downstream corpora, creating models that retain professional skills while violating human values on demand. Existing safety-realignment defenses often fail in practice due to three key limitations: they frequently cause catastrophic forgetting of specialized skills; their effectiveness collapses when the defender cannot observe the attacker's prompt template; and successfully realigned models remain susceptible to re-jailbreaking via simple system prompt switches. To address these challenges, we propose Routing-based On-Policy Distillation (ROPD), a novel realignment framework that models the divergence between aligned and compromised output probability distributions rather than fitting specific prompt templates. We conduct extensive experiments comparing ROPD against four state-of-the-art baselines across three datasets and three base models with varying alignment strengths. Our results demonstrate that when baseline defenses face template mismatches, often accompanied by severe degradation in downstream task performance. In contrast, ROPD substantially mitigates template-mismatch risks, maintaining superior robustness in both defense effectiveness and capability preservation. While our analysis indicates ROPD is not entirely immune to template shifts, its performance degradation is negligible compared to existing methods, establishing a new standard for robust LLM realignment.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{guo2026onpolicy,
  title  = {On-Policy Distillation for LLM Safety: A Routing Approach to Template-Robust Realignment},
  author = {Yongjian Guo and Wanlun Ma and Lingyu Shen and Xi Xiao and Sheng Wen},
  year   = {2026},
  eprint = {2607.27081},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2607.27081v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2607.27081.svg)](https://codeofpaper.com/paper/2607.27081)

Discussion