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

Yongjian Guo, Wanlun Ma, Lingyu Shen, Xi Xiao, Sheng WenarXiv 2026

TL;DR

ROPD (Routing-based On-Policy Distillation) is a new framework designed to "realign" Large Language Models (LLMs) that have been compromised by malicious fine-tuning. By routing distillation between a frozen safety teacher and a task teacher, ROPD restores safety without destroying specialized skills, even when the attacker uses secret prompt templates that the defender hasn't seen.

What Problem Does This Paper Address?

LLMs are typically aligned using techniques like RLHF to ensure they are helpful and harmless. However, this alignment is surprisingly fragile. A malicious actor can provide a fine-tuning corpus that teaches a model a useful skill (like SQL generation) while "quietly" embedding harmful behaviors.

Existing defenses that try to "realign" these compromised models suffer from three major vulnerabilities:

  1. Skill Retention Degradation: The process of making the model safe often "breaks" the specialized skill it was fine-tuned for.
  2. Template Dependence: Defenses usually assume the defender knows the exact prompt template (e.g., [INST] ... [/INST]) the attacker used. If there is a mismatch, the defense effectiveness collapses.
  3. Fragile Robustness Boundaries: Even a "fixed" model can often be re-jailbroken simply by changing the system prompt.

The authors identify this as the "template-consistency trap," illustrated in Figure 1.

Figure 1: The template-consistency trap in safety realignment.

Methods

The authors propose ROPD (Routing-based On-Policy Distillation). Instead of fine-tuning the model on specific "refusal" text, ROPD focuses on matching the output probability distributions of two specialized, frozen teachers:

  • The Safety Teacher: The original, pre-attack aligned model. It provides a "refusal prior" that is largely independent of the specific prompt template.
  • The Task Teacher: The misaligned, fine-tuned model itself. It holds the specialized downstream skill.

The Routing Mechanism: During realignment, every training token is routed. Harmful probes are distilled from the Safety Teacher, while task-related examples are distilled from the Task Teacher. This decouples the two objectives, allowing the model to stay "smart" while becoming "safe" again.

Top-K KL Distillation: To make training efficient and robust, ROPD uses a top-$K$ KL divergence objective. It matches the student model to the teacher's distribution only on the most likely tokens, rather than the entire vocabulary, which helps the model ignore surface-level template noise. The full pipeline is shown in Figure 2.

Figure 2: Overview of the ROPD pipeline: two frozen teachers—the aligned original (refusal prior) and the fine-tuned model (task skill)—supply source-routed top-𝐾KL distillation to a single realigned student.

Datasets

The researchers evaluated ROPD across three base models (Llama-2-7B, Qwen2.5-7B, and Gemma-2-9B) and three specialized downstream tasks:

  • SQL: Text-to-SQL generation.
  • SAMSum: Dialogue summarization.
  • NL2Bash: Natural language to Linux shell commands.

For safety data, they used BeaverTails, a dataset of harmful prompts and human-preference labels. They tested three template types: raw (minimal), self (native chat format), and attack (a bespoke adversarial template).

Key Insights and Ideas

  • Distribution over Text: The core "aha" moment is that safety is a property of the model's probability distribution, not just the words it says. By distilling the distribution, the defense becomes much more robust to template shifts.
  • Specialization through Routing: By using two teachers, ROPD avoids the "tug-of-war" between safety and utility. The task teacher anchors the model's skills, while the safety teacher pulls it back toward ethical boundaries.
  • Template Mismatch is the Real Threat: The paper quantifies how badly standard defenses fail when they don't know the attacker's template. ROPD is the first method to show consistent performance even when the defense template is chosen blindly.

Key Results

ROPD significantly outperformed state-of-the-art (SOTA) baselines like SSRD, RESTA, and soft-SFT:

  • Robustness: On Llama-2, when the attack and defense templates were mismatched, baselines saw their Attack Success Rate (ASR) jump to over 40%. ROPD maintained a low ASR of ~2.1-2.4%.
  • Skill Preservation: While baselines often crashed task performance to near zero to achieve safety, ROPD maintained task scores at or near pre-attack levels (e.g., maintaining ~60% exact match on SQL while baselines dropped to <10%).
  • Efficiency: ROPD is highly data-efficient, requiring only about 1,500 examples to reach peak effectiveness.

Figure 3 highlights these trade-offs across different tasks and models.

Figure 3: Defense comparison on SAMSum and NL2Bash.

Limitations and Future Work

The authors acknowledge that ROPD is not a "silver bullet":

  • Residual Risk: While it drastically reduces template sensitivity, it is not entirely immune. ASR still rises slightly under extreme template mismatch.
  • Weight-Level vs. Prompt-Level: The paper notes that current realignment is often a "prompt-conditional fix." A determined adversary who can freely rewrite system prompts can still find ways to elicit harmful behavior.
  • Future Direction: The authors suggest that future work should focus on making realignment truly durable at the weight level, ensuring safety persists regardless of the input context.

Summary updated

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