Skip to content

Study: chat templates in knowledge distillation weaken student model safety alignmentUnderstanding the Role of Prompt Template in Knowledge Distillation for Safety Alignment

Paper Tracker· arXiv:2609.30802· Anjila Budathoki, Manish Dhakal, Benjamin M. Ampel, Yi Ding·Indexed by this site · 2026-10-03· Originally publishedAlignment

Quick read

Analysis and theory

Based on the paper PDF (AI-generated); refer to the original

When distilling on benign data, the student-side chat template weakens existing refusals more than non-chat: LLaMA's HarmBench ASR rises from 12.18% to 39.75%.

Questions
When an aligned student undergoes knowledge distillation on benign instruction data, can the prompt template used in training change its original refusals. The authors argue this factor has not been systematically examined in KD, while deployment scenarios require preserving safety behavior.
Methods
On three pairs of LLaMA, Gemma, and Qwen Instruct teacher-student models, LoRA distillation is performed with Dolly-15k, using a loss of equally weighted cross-entropy and forward KL. The comparison is between the model family's native chat template and a non-chat version without control tokens; inference uniformly uses the chat template, and teacher-student templates, mixing ratios, and refusal direction are decoupled.
Experiments and results
The authors state that benign KD raises ASR on most benchmarks, with chat more severe than non-chat, and that this is driven mainly by the student-side template. Chat KD also shifts the refusal direction away from baseline and narrows the harmful/harmless projection gap; as the chat sample proportion increases, ASR generally rises while utility improves only slightly.
Limitations and future work
The authors note that distillation uses only benign instruction data; whether code, math, and reasoning degrade similarly remains to be verified; non-native templates and LoRA ranks are also not covered. Experiments cover three families of open-source Instruct teacher-student models, four safety benchmarks, and multiple inference-format ablations; the appendix reports reverse KL and causal interventions.
Experimental setupLLaMA-3.1-8B-Instruct、LLaMA-3.2-3B-Instruct et al. · databricks-dolly-15k、AdvBench et al. · ASR、ROUGE-L et al.
Evaluated models
LLaMA-3.1-8B-InstructLLaMA-3.2-3B-InstructGemma-2-9B-ITGemma-2-2B-ITQwen2.5-7B-InstructQwen2.5-3B-Instruct
Benchmarks
databricks-dolly-15kAdvBenchJailbreakBenchHarmBenchSORRY-BenchDollySelfInstS-NIVicuna
Metrics
ASRROUGE-Lcosine similarityprojection gap
AI summaryA study analyzed the impact of prompt template choice in knowledge distillation on the existing safety alignment of student models, finding that after distillation with a chat template, models show higher compliance with harmful queries than with a non-chat template. This conclusion holds consistently across three model families, LLaMA, Gemma, and Qwen, and is validated on multiple safety benchmarks. The study also shows that non-chat template distillation better preserves the internal representations of the base student model, while chat template distillation leads to greater representation shift. The paper's code has been released.

A study analyzed the impact of prompt template choice in knowledge distillation on the existing safety alignment of student models, finding that after distillation with a chat template, models show higher compliance with harmful queries than with a non-chat template. This conclusion holds consistently across three model families, LLaMA, Gemma, and Qwen, and is validated on multiple safety benchmarks. The study also shows that non-chat template distillation better preserves the internal representations of the base student model, while chat template distillation leads to greater representation shift. The paper's code has been released.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    Whether knowledge distillation on benign tasks can weaken a student's existing safety refusals due to the prompt template.

    How do chat and non-chat prompt templates affect the retention of an already aligned student model's original refusal behavior when performing knowledge distillation on benign instruction data.

    • Scenario and importance: The authors note that KD is commonly used to compress large models into more deployable student models, while applications such as healthcare and autonomous systems require that the distilled model still refuse harmful, malicious, or policy-violating requests. Alignment typically embeds refusal capabilities before downstream adaptation, but how this alignment changes during continued KD and which training factors determine it is, according to the authors, an open question.
    • Gaps in existing work: Lyu et al. (2024), Jiang et al. (2025), and Wang et al. (2025b) have discussed the impact of prompt format on safety behavior in SFT. The authors argue that KD differs from SFT: students also see teacher-generated soft targets, a signal that may interact with the template format; the role of templates in KD remains empirically underexplored.
    • Core observation: The authors compare two types of templates. The chat template wraps inputs with dialogue control tokens; the non-chat template is a task-style format without those tokens. The question they test is: when distilling on benign downstream tasks, how do these two templates affect the refusal behavior of safety alignment.
    • What this paper does: Across the LLaMA, Gemma, and Qwen families, students are distilled on benign instruction data under both chat and non-chat training formats, with inference always using the standard chat template, thereby attributing safety differences to the training-time template. In addition to output-layer ASR and utility, the authors perform mechanistic analysis in the refusal direction and vary the proportion of chat samples in training to observe how safety and utility change with chat exposure.
  2. What related research exists?

    Related work is grouped into KD, safety alignment, and prompt templates; the authors state that the role of templates in KD still lacks systematic comparison.

    In the introduction and Section 2, the authors divide related work into three groups and position this paper accordingly.

    Knowledge distillation

    • Hinton et al. (2015): Using soft targets (full probability distributions) conveys richer information than hard labels, allowing knowledge from a large network to transfer to a smaller one.
    • LLM distillation: Gu et al. (2024), Ko et al. (2024), and Wang et al. (2025a) distill LLM knowledge into more compact students. Gu et al. (2024) propose a distillation objective for generative models and introduce reverse KL, which subsequent methods adopt. The authors state that how task-utility-focused KD affects safety alignment remains under-studied.

    Safety alignment

    • SFT and preference alignment: Ouyang et al. (2022), Bai et al. (2022), and Rafailov et al. (2023) use SFT plus RLHF or DPO to embed the ability to refuse harmful instructions (which the authors call safety guardrails) into models.
    • Alignment via KD and known vulnerabilities: Yang et al. (2024) use KD to implement safety alignment in students. Yi et al. (2024) discuss vulnerabilities and jailbreaks in open-source LLM safety guardrails. The authors state that it remains unclear whether distilling on benign downstream tasks further weakens the guardrails of aligned models.

    Prompt templates

    • Impact of format on behavior and safety: Wang et al. (2025b) discuss that chat templates in instruction fine-tuning reduce context awareness and change how models attend to inputs. Lyu et al. (2024) state that task-style fine-tuning and safety-oriented testing better preserve safety behavior; Jiang et al. (2025) state that certain chat template designs trigger unexpected behavioral failures.
    • Role in multimodal settings: Shayegani et al. (2026)'s Role-Modality Attacks exploit dialogue roles and modality positions to attack VLMs. The authors state that despite these findings, the role of prompt templates in KD remains underexplored.

    Baseline methods include the untrained student MS, SFT on the same data, and both chat and non-chat KD. Benchmarks use databricks-dolly-15k for training; safety evaluation uses AdvBench, JailbreakBench, HarmBench, and SORRY-Bench; utility is average ROUGE-L on Dolly, SelfInst, S-NI, and Vicuna. The definition of refusal direction comes from Arditi et al. (2024).

    The authors position this paper as: a systematic comparison of chat and non-chat templates in benign KD, simultaneously measuring effects on utility and safety.

  3. How does the paper address this problem?

    Distill with equal-weight CE and forward KL on two templates, inference uniformly uses chat, then compare internal representations using the refusal direction.

    The authors use the same benign instruction data to distill knowledge into students under chat and non-chat training formats, then switch back to the standard chat template for inference, comparing safety, utility, and internal refusal representations. The pipeline is shown in Figure 1.

    Problem Setup and Templates

    • Model pairs: Teachers are larger Instruct models, students are smaller Instruct models. Specifically, LLaMA-3.1-8B-Instruct → LLaMA-3.2-3B-Instruct, Gemma-2-9B-IT → Gemma-2-2B-IT, Qwen2.5-7B-Instruct → Qwen2.5-3B-Instruct. The authors state these models have undergone rigorous pretraining filtering and post-training safety alignment, making them suitable as baselines for measuring safety degradation.
    • Chat template: Uses each model family's native chat template with all special control tokens, as the chat-format baseline for instruction following.
    • Non-chat template: Removes all model-specific control tokens, keeping only raw text, thereby separating the semantic content of instructions from the structural prior imposed by the template. Appendix Table 9 gives examples.
    • Training data: Only databricks-dolly-15k is used for distillation; the four safety benchmarks are used only for evaluation.

    Distillation Objective and Training

    • Loss: For formatted data D = {(x, y)}, total loss is L = (1 − α) LCE + α LKD. L_CE is the negative log-likelihood of the student on gold-standard tokens; L_KD is the forward KL between teacher and student on teacher-sampled sequences. α = 0.5, weighting task performance and knowledge transfer equally.
    • Main experiments use forward KL. Appendix C additionally evaluates reverse KL and FKL+RKL to see whether template effects hold across distillation objectives.
    • Parameters: All students use LoRA with rank r = 8, trained on a single node with 4 NVIDIA RTX 4090 GPUs. Learning rate, batch size, etc., are in Appendix A.1.

    Evaluation Protocol

    • Utility: Average ROUGE-L on four general instruction-following sets.
    • Safety: AdvBench and JailbreakBench use LLaMA-3-Guard-8B as judge in WalledEval (Gupta et al., 2024) to compute ASR; HarmBench and SORRY-Bench use their provided judges.
    • Inference format: Regardless of training template, evaluation strictly uses the standard chat template. The authors state this aligns with recommended usage for modern instruction models, so safety differences between conditions can be attributed to the training template, not evaluation format differences.

    Decoupling, Mixing, and Refusal Direction

    • Teacher–student decoupling: During training, the student template and the template used for teacher outputs can differ, to distinguish whether degradation comes from the student-side input format or the teacher's soft-target distribution.
    • Template mixing: On the same benign data, the proportion of chat samples varies from 0 (pure non-chat) to 1 (pure chat). 0.5 means half the samples use chat and half use the corresponding non-chat. The authors add no extra safety supervision.
    • Refusal direction: For each layer ℓ, using the residual stream resid_pre, the average activation difference between harmful prompts (SORRY-Bench) and harmless prompts (Dolly-15k) is L2-normalized to obtain r_ℓ. After distillation, compare the cosine similarity of this direction with the baseline student, and the harmful–harmless projection gap along this direction. Additionally, PCA is done on the last-token hidden states of the final layer. All models are compared under the same chat inference format. Appendix F also performs small-scale causal interventions on the learned refusal direction.

    Robustness Checks

    • Cross-template evaluation: On HarmBench and SORRY-Bench, both chat and non-chat inference formats are used.
    • Token ablations: On HarmBench, remove BOS/EOT, remove role markers, or give only the raw harmful instruction (Raw Query).
  4. What experiments did the paper conduct?

    Across the three student families, chat KD's ASR increase is generally larger than non-chat, and the refusal direction also deviates more from baseline.

    Experimental setup

    • Models under test: Students are LLaMA-3.2-3B-Instruct, Gemma-2-2B-IT, Qwen2.5-3B-Instruct; teachers are LLaMA-3.1-8B-Instruct, Gemma-2-9B-IT, Qwen2.5-7B-Instruct, respectively. One of the safety reviewers is LLaMA-3-Guard-8B.
    • Data: Distillation uses databricks-dolly-15k. Safety uses AdvBench, JailbreakBench (JBB in tables), SORRY-Bench, HarmBench. Utility is the average ROUGE-L (AVG) across Dolly, SelfInst, S-NI, Vicuna.
    • Conditions: Untrained student baseline MS; SFT and KD each split into Non-chat and Chat. Main experiments use the standard chat template for inference.
    • Metrics: Lower ASR is safer; subscripts are changes relative to that family's MS; utility is average ROUGE-L, higher is better.
    • Training: LoRA r = 8. The paper does not give the number of repetitions in the main text; hyperparameters are in Appendix A.1.
    • Review: AdvBench and JailbreakBench use WalledEval and LLaMA-3-Guard-8B; HarmBench and SORRY-Bench use their provided reviewers. The paper does not specify decision thresholds.

    Main results

    Table 1 reports student ASR (%) and average ROUGE-L under standard chat inference. The table below lists only KD and baseline; SFT rows appear later.

    Swipe horizontally to read the table

    ModelMethodAdvBenchJBBSORRYHarmBenchAVG
    LLaMA-3.2-3BMS2.987.2526.7212.1819.84
    LLaMA-3.2-3BKD Non-chat3.076.0027.3629.8124.75
    LLaMA-3.2-3BKD Chat4.998.7530.8639.7529.03
    Gemma-2-2BMS0.001.5016.0411.5622.35
    Gemma-2-2BKD Non-chat0.001.5019.1814.2523.63
    Gemma-2-2BKD Chat4.006.5051.3619.5630.18
    Qwen2.5-3BMS02.7536.2917.6922.46
    Qwen2.5-3BKD Non-chat1.063.2534.9317.8123.96

    Qwen KD Chat ASR is AdvBench 5.87, JBB 11, SORRY 40.99, HarmBench 30.81, AVG 28.95 (Table 1). The table also has several SFT rows below baseline, e.g., LLaMA SFT Non-chat AdvBench is 0.0096, JBB is 0.04.

    • The authors state that standard KD on benign data weakens students' existing safety alignment: the three distilled students have higher ASR than the corresponding MS on most safety benchmarks. The authors state that in some cases the vulnerability nearly triples, citing LLaMA's HarmBench and Gemma's SORRY-Bench as the largest degradations.
    • The authors state that chat KD increases ASR more than non-chat. Gemma on SORRY-Bench is +35.32% relative to baseline; LLaMA and Qwen on HarmBench are +27.57% and +13.12%, respectively. Under non-chat, Gemma's SORRY-Bench is only +3.14%, and Qwen's HarmBench is +0.12%. The authors also state that non-chat does not fully preserve the original alignment, e.g., LLaMA HarmBench is still +17.63%.
    • Utility and safety: Both templates improve instruction following, but larger utility gains co-occur with larger ASR increases. The authors use LLaMA to counter the claim that "non-chat's low ASR is just weaker instruction following": non-chat KD utility 24.75 is lower than SFT Chat's 29.10, yet HarmBench ASR is 29.81% vs. 22.50%.

    Teacher-student template decoupling

    Table 2 reports only SORRY-Bench and HarmBench. When the teacher uses non-chat and the student uses chat, LLaMA is 28.33 (+1.61) and 13.44 (+1.26), Gemma is 18.33 (+2.29) and 12.75 (+1.19). When the teacher uses chat and the student uses non-chat, LLaMA is 26.36 (−0.36) and 11.44 (−0.74), Gemma is 16.90 (+0.86) and 12.50 (+0.94). When both use chat, LLaMA HarmBench is +27.57%, Gemma SORRY-Bench is +35.32%.

    • The authors state that using chat only on the teacher side does not noticeably weaken safety, using chat only on the student side causes a small but consistent regression; using chat on both sides gives the largest degradation.
    • The authors attribute the asymmetry to: the student template directly determines the input distribution for gradient computation, while the teacher template only determines the soft targets the student sees. The authors state the degradation is not simply inherited from the teacher. Table 2 does not list Qwen.

    Internal representations

    Table 3 gives cosine similarity relative to the original Instruct student's refusal direction, and the harmful–harmless projection gap.

    Swipe horizontally to read the table

    ModelConditionCosine to BaseProjection Gap
    GemmaBase / Chat / Non-chat— / 0.53 / 0.99368.78 / 175.60 / 355.76
    LLaMABase / Chat / Non-chat— / 0.75 / 0.9720.38 / 18.48 / 20.87
    QwenBase / Chat / Non-chat— / 0.54 / 0.99118.45 / 83.21 / 110.69
    • The authors state that across all three families, chat KD changes the refusal geometry more: lower cosine similarity and smaller projection gap. Non-chat is closer to baseline; LLaMA non-chat's projection gap 20.87 is slightly above baseline 20.38.
    • Figure 2 is PCA of the last-layer hidden states for the three families. The layers marked in the figure are LLaMA layer 27, Gemma layer 25, Qwen layer 35; the legend is Harmless and Harmful. The authors state that non-chat KD is closer to the baseline student, chat KD produces a larger representation shift; the caption says PCA projection, not quantitative distance.
    • In the small-scale causal intervention in Appendix F, the authors specifically note: ablation on LLaMA may harm output coherence, so its lower ASR should not be interpreted as improved safety.

    Other ablations and analyses

    • Mix ratio (Table 4): LLaMA chat ratios 0 / 0.5 / 0.8 / 1.0, SORRY-Bench is 27.36 / 28.18 / 29.85 / 30.86, HarmBench is 29.81 / 23.06 / 24.50 / 39.75, AVG is 24.75 / 28.62 / 28.74 / 29.03. Gemma correspondingly SORRY is 19.18 / 38.94 / 44.39 / 51.36, HarmBench is 14.25 / 16.88 / 18.50 / 19.56, AVG is 23.63 / 29.60 / 30.24 / 30.18. The authors state that mixing cannot reduce ASR below pure non-chat, only mitigates relative to full chat; utility rises less with ratio than ASR. LLaMA HarmBench at 0.5 and 0.8 is below pure non-chat's 29.81.
    • Cross-template inference (Table 5): Under non-chat inference, LLaMA chat KD SORRY / HarmBench is 54.39 (+19.24) / 42.56 (+7.12), non-chat KD is 50.61 (+15.46) / 33.31 (−2.13). Gemma chat KD is 71.51 (+51.59) / 27.56 (+9.81). Under Qwen non-chat inference, non-chat KD SORRY 57.65 (+12.73) is higher than chat KD's 54.09 (+9.17). The authors state the degradation direction persists under non-chat evaluation, with magnitude varying by inference format.
    • Token ablation (Table 6, HarmBench): After removing BOS/EOT, KD-Chat relative to baseline is LLaMA +9.37, Gemma +7.69, Qwen +6.00. After removing role markers, Qwen KD-Chat is 45.75 (−3.00), KD-Non-chat is 44.50 (−4.25), below the baseline 48.75 in that setting. Under Raw Query, LLaMA KD-Non-chat is 28.19 (−7.50). The authors state that no single control token consistently explains the degradation across all three families.
    • Appendix C: The authors state that switching to reverse KL and FKL+RKL, the same template-driven safety degradation persists. The main text does not give specific ASR under these objectives.
    • Appendix E: The authors state that chat-template KD accelerates this vulnerability at earlier training stages. The main text does not give stepwise ASR.
    • Table 14: Combines HarmBench chat evaluation, BOS/EOT removal, role marker removal, non-chat evaluation, and Raw Query. The authors state that KD-Chat remains less safe than the corresponding baseline under several ablation settings, with role markers and Raw Query more model-dependent.
  5. What are some points that can be further explored?

    The authors note that results come from benign instruction data; whether code, math, reasoning, and non-native templates also degrade has not been verified.

    Limitations and future directions noted by the authors

    • Data scope: Limitations states that KD was only performed on benign instruction-following data; whether similar template-driven degradation occurs in specific domains such as code, math, or reasoning remains an open question. The authors specifically mention that these domains have different dependencies on structural tokens: formatting cues in code may interact with chat control tokens in different ways. (Limitations, Dataset)
    • Training–deployment asymmetry: Discussion states that when safety is a priority, non-chat training with standard chat interface deployment can be used, but this asymmetry is uncommon in practice, and its robustness beyond benign instruction data and this paper's benchmarks remains to be verified. (Section 6)
    • Future questions: Conclusion raises whether future fine-tuning and distillation can preserve refusal geometry without relying on explicit safety supervision, allowing students to improve utility while maintaining the baseline Instruct model's safety behavior. (Section 7)
    • Interpretation boundary of causal intervention: Section 5.2 states that LLaMA's refusal direction ablation may harm output coherence, so lower ASR should not be interpreted as improved safety. (Section 5.2, Appendix F)

    The paper's Limitations opening states three remaining limitations; the rest of the limitations after Dataset in stdin are not fully given in the original, so they are not supplemented here.

    Experimental coverage

    • Models: Experiments use three pairs of open-source Instruct teacher-student models: LLaMA-3.1-8B-Instruct to 3.2-3B-Instruct, Gemma-2-9B-IT to 2B-IT, Qwen2.5-7B-Instruct to 3B-Instruct, all students with LoRA r = 8 (Section 3.3).
    • Data and metrics: Distillation data is databricks-dolly-15k; safety ASR covers AdvBench, JailbreakBench, HarmBench, SORRY-Bench; utility is average ROUGE-L across four instruction sets (Table 1).
    • Factors: Main comparison is chat vs. non-chat; also teacher-student template decoupling (Table 2, reporting LLaMA and Gemma), chat ratios 0, 0.5, 0.8, 1.0 (Table 4), cross-inference formats (Table 5), and HarmBench token ablation (Table 6, Table 14).
    • Representation analysis: Refusal direction is estimated using resid_pre activations from SORRY-Bench and Dolly-15k, reporting cosine similarity and projection gap for the three families (Table 3), with PCA on the last layer (Figure 2). Appendix F reports small-scale causal intervention.
    • Distillation objective: Main experiments use forward KL with α = 0.5; Appendix C additionally evaluates reverse KL and FKL+RKL. The paper does not report specific ASR for these alternative objectives in the main text, nor the number of repetitions.
  6. Summarize the main content of the paper

    Benign KD increases student ASR, and the chat training template deviates more from the original refusal direction than non-chat.

    This work compares whether prompt templates during knowledge distillation change the refusal behavior of aligned students. The authors are concerned about whether the training format itself weakens safety alignment when only benign instruction data is needed and inference still uses the standard chat template.

    Students are LLaMA-3.2-3B-Instruct, Gemma-2-2B-IT, and Qwen2.5-3B-Instruct; teachers are larger Instruct models from the same families. Data is databricks-dolly-15k, loss is equal-weight cross-entropy and forward KL, LoRA rank is 8. Chat uses each model family's native control tokens; non-chat removes these tokens.

    • Behavior: In Table 1, chat KD HarmBench ASR is 39.75% on LLaMA (baseline 12.18%) and 30.81% on Qwen (baseline 17.69%); Gemma's SORRY-Bench goes from 16.04% to 51.36%. Non-chat increases are smaller, but LLaMA HarmBench still reaches 29.81%. Both templates raise average ROUGE-L, with chat having higher utility.
    • Source: In Table 2, changing only the teacher template yields smaller safety changes; when both teacher and student use chat, LLaMA HarmBench is +27.57% relative to baseline, and Gemma SORRY-Bench +35.32%. The authors argue the main driver is the student-side training template.
    • Representation and dose: In Table 3, cosine similarity of the refusal direction relative to baseline for chat KD is 0.53, 0.75, 0.54 on Gemma, LLaMA, Qwen, and for non-chat is 0.99, 0.97, 0.99. In Table 4, increasing the proportion of chat samples raises Gemma SORRY-Bench from 19.18% to 51.36%, and utility from 23.63 to about 30.
    • Robustness: Changing inference format, removing BOS/EOT, chat KD still often exceeds corresponding baselines across the three families; removing role markers or using only raw queries makes direction more model-dependent. In the appendix, the authors state that template effects persist under reverse KL and FKL+RKL.

    The authors conclude that optimizing benign instruction following conflicts with preserving existing refusals, and chat templates amplify this erosion. They suggest that when safety is a priority, training should use non-chat while deployment uses chat, and note that whether this asymmetry holds beyond this paper's data and benchmarks remains to be verified.

Read originalarxiv.org