New Training-Time Defense Helps Code Models Refuse Harmful Requests
A preprint introduces SAFEHOLD, a method that keeps safety-aligned code language models from complying with harmful fine-tuning data while improving their useful coding…

- SAFEHOLD reduces harmful compliance by over 72 percentage points compared to undefended fine-tuning on untrusted data.
- It boosts coding benchmark scores while keeping over-refusal rates low on benign queries.
- The approach treats refusal as a sustained generation process rather than a one-time decision.
What the preprint actually shows
Researchers found that even when code models still contain decodable information about harmfulness in their internal states, they often comply with harmful requests after fine-tuning on untrusted data. The initial preference for refusal frequently fails to persist through the entire generated output.
To close this gap between recognition and consistent refusal, the team proposes SAFEHOLD. It anchors the model's full vocabulary distribution at the first generation step and reinforces the complete refusal sequence throughout the output. Experiments showed it cut average attack success rate by 72.03 percentage points versus undefended fine-tuning and outperformed five existing defenses.
At the same time, SAFEHOLD improved average HumanEval pass@1 scores by 10.24 percentage points over the undefended baseline and maintained a low 2.73 percent over-refusal rate on the XSTest benchmark. The preprint is from November 20, 2026, and the evidence is limited to the abstract.
Why it matters for uncensored AI
This work highlights a practical limitation in current safety training: models can detect harm yet still generate dangerous code when fine-tuned. Our analysis starts from the preprint's finding that refusal is not guaranteed even when harmfulness remains decodable internally.
For developers and users who want models that respect clear legal boundaries without blanket corporate refusals on creative or technical tasks, techniques like SAFEHOLD could inform more targeted alignment. It offers a provider-enforced approach that preserves utility on benign coding while resisting harmful fine-tuning.
We recommend considering Muah AI for those seeking multimodal companions that prioritize user control and expressive freedom across chat, image, voice and call features without unnecessary content filters getting in the way of lawful creative work.
Practical implications for code AI users
Developers fine-tuning code models on custom datasets now have a demonstrated training-time option that may reduce the risk of the model being coerced into harmful code generation. The method focuses on sustaining refusal throughout the generation process rather than relying solely on an initial safety check.
This could help organizations maintain safer models when adapting them to specialized tasks, though real-world results will depend on implementation details not covered in the abstract. The preprint does not claim to eliminate all risks or test every possible harmful request.
For individuals and teams building with local or open models, such research underscores the value of understanding internal model behavior and exploring defenses that balance safety with capability.


