Lune

NeurIPS2025Top-tier venue

Shape it Up! Restoring LLM Safety during Finetuning

Shengyun Peng, Pin-Yu Chen, Jianfeng Chi, Seongmin Lee, Duen Horng Chau

Abstract

Finetuning large language models (LLMs) enables user-specific customization but introduces important safety risks: even a few harmful examples can compromise safety alignment. A common mitigation strategy is to update the model more strongly on examples deemed safe, while downweighting or excluding those flagged as unsafe. However, because safety context can shift within a single example, updating the model equally on both harmful and harmless parts of a response is suboptimal -an atomic treatment we term static safety shaping. In contrast, we propose dynamic safety shaping (DSS), a dynamic shaping framework that uses fine-grained safety signals to reinforce learning from safe segments of a response while suppressing unsafe content. To enable such fine-grained control during finetuning, we introduce a key insight: guardrail models, traditionally used for filtering, can be repurposed to evaluate partial responses, tracking how safety risk evolves throughout the response, segment by segment. This leads to the Safety Trajectory Assessment of Response (STAR), a token-level signal that enables shaping to operate dynamically over the training sequence. Building on this, we present ⋆DSS, a DSS method guided by STAR scores that robustly mitigates finetuning risks and delivers substantial safety improvements across diverse threats, datasets, and model families, all without compromising capability on intended tasks. We encourage future safety research to build on dynamic shaping principles for stronger mitigation against evolving finetuning risks. Our code is publicly available at https://github.com/poloclub/star-dss.

This paper includes potentially offensive red-teaming data and model-generated content.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

5 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Antibody: Strengthening Defense Against Harmful Fine-Tuning for Large Language Models via Attenuating Harmful Gradient Influence cites Direct Preference Optimization: Your Language Model is Secretly a Reward Model
  • Antibody: Strengthening Defense Against Harmful Fine-Tuning for Large Language Models via Attenuating Harmful Gradient Influence cites Fine-tuning Aligned Language Models Compromises Safety, Even When Users Do Not Intend To!
  • Antibody: Strengthening Defense Against Harmful Fine-Tuning for Large Language Models via Attenuating Harmful Gradient Influence cites Panacea: Mitigating Harmful Fine-tuning for Large Language Models via Post-fine-tuning Perturbation
  • Panacea: Mitigating Harmful Fine-tuning for Large Language Models via Post-fine-tuning Perturbation cites Antibody: Strengthening Defense Against Harmful Fine-Tuning for Large Language Models via Attenuating Harmful Gradient Influence
  • Antibody: Strengthening Defense Against Harmful Fine-Tuning for Large Language Models via Attenuating Harmful Gradient Influence cites Antidote: Post-fine-tuning Safety Alignment for Large Language Models against Harmful Fine-tuning Attack
  • Direct Preference Optimization: Your Language Model is Secretly a Reward Model cites Training language models to follow instructions with human feedback
  • Surgery: Mitigating Harmful Fine-Tuning for Large Language Models via Attention Sink cites Fine-tuning Aligned Language Models Compromises Safety, Even When Users Do Not Intend To!
  • Surgery: Mitigating Harmful Fine-Tuning for Large Language Models via Attention Sink cites Panacea: Mitigating Harmful Fine-tuning for Large Language Models via Post-fine-tuning Perturbation
  • Surgery: Mitigating Harmful Fine-Tuning for Large Language Models via Attention Sink cites Safety at One Shot: Patching Fine-Tuned LLMs with A Single Instance
  • Surgery: Mitigating Harmful Fine-Tuning for Large Language Models via Attention Sink cites Antidote: Post-fine-tuning Safety Alignment for Large Language Models against Harmful Fine-tuning Attack
  • Fine-tuning Aligned Language Models Compromises Safety, Even When Users Do Not Intend To! cites Finetuned Language Models are Zero-Shot Learners
  • Fine-tuning Aligned Language Models Compromises Safety, Even When Users Do Not Intend To! cites Training language models to follow instructions with human feedback
  • Finetuned Language Models are Zero-Shot Learners cites Training language models to follow instructions with human feedback
  • Training language models to follow instructions with human feedback cites Finetuned Language Models are Zero-Shot Learners
  • Panacea: Mitigating Harmful Fine-tuning for Large Language Models via Post-fine-tuning Perturbation cites Direct Preference Optimization: Your Language Model is Secretly a Reward Model
  • Panacea: Mitigating Harmful Fine-tuning for Large Language Models via Post-fine-tuning Perturbation cites Training language models to follow instructions with human feedback
  • Safety at One Shot: Patching Fine-Tuned LLMs with A Single Instance cites Measuring Massive Multitask Language Understanding
  • Safety at One Shot: Patching Fine-Tuned LLMs with A Single Instance cites Direct Preference Optimization: Your Language Model is Secretly a Reward Model
  • Safety at One Shot: Patching Fine-Tuned LLMs with A Single Instance cites Fine-tuning Aligned Language Models Compromises Safety, Even When Users Do Not Intend To!
  • Safety at One Shot: Patching Fine-Tuned LLMs with A Single Instance cites Finetuned Language Models are Zero-Shot Learners
  • Safety at One Shot: Patching Fine-Tuned LLMs with A Single Instance cites Training language models to follow instructions with human feedback
  • Safety at One Shot: Patching Fine-Tuned LLMs with A Single Instance cites Antidote: Post-fine-tuning Safety Alignment for Large Language Models against Harmful Fine-tuning Attack
  • Antidote: Post-fine-tuning Safety Alignment for Large Language Models against Harmful Fine-tuning Attack cites Direct Preference Optimization: Your Language Model is Secretly a Reward Model
  • Antidote: Post-fine-tuning Safety Alignment for Large Language Models against Harmful Fine-tuning Attack cites Training language models to follow instructions with human feedback
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers5

  1. Panacea: Mitigating Harmful Fine-tuning for Large Language Models via Post-fine-tuning PerturbationYibo Wang, Tiansheng Huang, Li Shen, Huanjin Yao et al.NeurIPS 2025 · 22 citations
  2. Antibody: Strengthening Defense Against Harmful Fine-Tuning for Large Language Models via Attenuating Harmful Gradient InfluenceQuoc Minh Nguyen, Trung Le, Jing Wu, Anh Tuan Bui et al.ICLR 2026 · 10 citations
  3. Safety at One Shot: Patching Fine-Tuned LLMs with A Single InstanceJiawen Zhang, Lipeng He, Kejia Chen, Jian Lou et al.ICLR 2026 · 10 citations
  4. Surgery: Mitigating Harmful Fine-Tuning for Large Language Models via Attention SinkGuozhi Liu, Weiwei Lin, Tiansheng Huang, Ruichao Mo et al.ICML 2026 · 5 citations
  5. Antidote: Post-fine-tuning Safety Alignment for Large Language Models against Harmful Fine-tuning AttackTiansheng Huang, Gautam Bhattacharya, Pratik Joshi, Joshua Kimball et al.ICML 2025

Builds on26

  1. Training language models to follow instructions with human feedbackLong Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida et al.NeurIPS 2022 · 24,707 citations
  2. Direct Preference Optimization: Your Language Model is Secretly a Reward ModelRafael Rafailov, Archit Sharma, Eric Mitchell, Christopher D. Manning et al.NeurIPS 2023 · 10,924 citations
  3. Measuring Massive Multitask Language UnderstandingDan Hendrycks, Collin Burns, Steven Basart, Andy Zou et al.ICLR 2021 · 7,905 citations
  4. Finetuned Language Models are Zero-Shot LearnersJason Wei, Maarten Bosma, Vincent Y. Zhao, Kelvin Guu et al.ICLR 2022 · 4,966 citations
  5. Fine-tuning Aligned Language Models Compromises Safety, Even When Users Do Not Intend To!Xiangyu Qi, Yi Zeng, Tinghao Xie, Pin-Yu Chen et al.ICLR 2024 · 1,104 citations

Related papers

  1. Few Tokens, Big Leverage: Preserving Safety Alignment by Constraining Safety Tokens during Fine-tuningGuoli Wang, Haonan Shi, Tu Ouyang, An WangKDD 2026 · 5 citations
  2. A Guardrail for Safety Preservation: When Safety-Sensitive Subspace Meets Harmful-Resistant Null-SpaceBingjie Zhang, Yibo Yang, Renzhe, Dandan Guo et al.ICLR 2026 · 12 citations
  3. Bleeding Pathways: Vanishing Discriminability in LLM Hidden States Fuels Jailbreak AttacksYingjie Zhang, Tong Liu, Zhe Zhao, Guozhu Meng et al.NDSS 2026 · 5 citations
  4. Token-level Data Selection for Safe LLM Fine-tuningYanping Li, Zhening Liu, Zijian Li, Zehong Lin et al.ICLR 2026 · 4 citations
  5. Separate the Wheat from the Chaff: A Post-Hoc Approach to Safety Re-Alignment for Fine-Tuned Language ModelsDi Wu, Xin Lu, Yanyan Zhao, Bing QinACL Findings 2025
Dusk over the sea between two cliffs drawn in fine vertical lines