Trained on Harm, Still Refusing: A Training-Time Defense for Code Generation
On the map: LLM safety and security → Safety alignment, refusal and guardrails
Abstract (arXiv)
Fine-tuning enables safety-aligned code language models to adapt to diverse downstream tasks. However, training on untrusted data can severely undermine their ability to refuse harmful requests. Notably, we find that models comply with harmful requests even though harmfulness information remains highly decodable from their internal representations. Moreover, an initial preference for refusal does not necessarily translate into sustained refusal behavior throughout generation. Together, these findings reveal a critical gap between recognizing harmful requests and consistently refusing to fulfill them. To address this gap, we introduce SAFEHOLD, a novel provider-enforced defense framework that preserves safety alignment during harmful fine-tuning by treating refusal as a sustained generation process rather than a single response decision. Specifically, SAFEHOLD preserves the aligned model's full-vocabulary response distribution at the initial generation position through decision-boundary anchoring, while supervising the complete refusal sequence through refusal-path reinforcement. We conduct extensive experiments evaluating safety, utility, and internal mechanisms. SAFEHOLD reduces average ASR by 72.03 percentage points relative to undefended fine-tuning, outperforming five SOTA defenses by 24.32 to 70.87 percentage points. Meanwhile, it improves average HumanEval pass@1 by 10.24 percentage points over undefended fine-tuning, while maintaining an average XSTest over-refusal rate of only 2.73 percent. Overall, these results demonstrate that SAFEHOLD effectively mitigates safety degradation during harmful fine-tuning while preserving benign-task utility.
Key facts. No citing papers in the map yet (data through 24 Nov 2026). Placed in Safety alignment, refusal and guardrails, one of 12 directions in LLM safety and security. Builds on 9 of its 54 references that are in the map. Submitted 20 Nov 2026, announced 23 Nov 2026.
Builds on
9 of 54 references.
Closest ancestors · 1
Same direction, newest first
Other references · 8
- 2021Evaluating Large Language Models Trained on Codecited by 8,938
- 2022Training a Helpful and Harmless Assistant with Reinforcement Learning from Human Feedbackcited by 3,903
- 2023Universal and Transferable Adversarial Attacks on Aligned Language Modelscited by 3,374
- 2019Fine-Tuning Language Models from Human Preferencescited by 2,232
- 2026DeepSeek-V4: Towards Highly Efficient Million-Token Context Intelligencecited by 1,363
- 2023Shadow Alignment: The Ease of Subverting Safely-Aligned Language Modelscited by 319
- 2023BadLlama: cheaply removing safety fine-tuning from Llama 2-Chat 13Bcited by 45
- 2025CySecBench: Generative AI-based CyberSecurity-focused Prompt Dataset for Benchmarking Large Language Modelscited by 12
Built on by
Not cited yet.
Similar, not cited
Close in wording, no citation either way
- 2026SpecCloak: Probing Harmful Code Generation through Engineering Specifications
- 2026Beyond Shallow Alignment: How Post-Training Methods Determine Refusal Circuits And Steering Robustness
- 2026Deactivating Refusal Triggers: Understanding and Mitigating Overrefusal in Safety Alignment
- 2026When Safety Becomes An Outlier: Understanding the Retention of LLM Safety Behaviors
- 2026A Validated Prompt Bank for Malicious Code Generation: Separating Executable Weapons from Security Knowledge in 1,554 Consensus-Labeled Prompts
- 2026Refusal Is Not Robustness: Measuring Harmful Reachability in Autoregressive Language Models
- 2025An Embarrassingly Simple Defense Against LLM Abliteration Attacks
- 2026Beyond Refusal Patterns: Safe-Role Internalization for Robust and Generalizable LLM Safety Alignment