TRANSMISSION // 2611.27495v1

Teaching code models to keep refusing

Source published

SAFEHOLD aims to preserve refusal behavior when code-capable language models are fine-tuned on harmful data. In tests on five models, it reduced harmful compliance while retaining performance on selected benign tasks.

AI-generated conceptual illustration for Teaching code models to keep refusing
AI-generated conceptual illustration; not documentary evidence.

A model can still distinguish harmful from harmless requests yet answer a harmful one. A new preprint explores that gap and tests SAFEHOLD, a training-time method designed to preserve both the start and continuation of a refusal during fine-tuning.

Fine-tuning can adapt a language model to new tasks, but it can also weaken safeguards. That creates a particular challenge for code-generating models: a user’s training data may teach a model to comply with requests that its original, safety-aligned version would have refused. In a new preprint, Miaoqing Tian and colleagues ask whether a provider can preserve refusal behavior while allowing this kind of adaptation—and whether refusal needs protection beyond the first word of an answer.

The researchers’ starting point is a distinction between recognizing a risky request and acting on that recognition. They fine-tuned three code-capable models on harmful instruction-and-response examples, then trained simple classifiers, called probes, to distinguish harmful from benign requests using the models’ internal representations. Harmful requests remained readily distinguishable after fine-tuning, even as the models often complied with them. The authors stress that this does not show the original safety mechanism remained intact: the probes were trained separately on each model version. It shows instead that detectable information about harmfulness can coexist with unsafe answers.

A second observation concerns how answers unfold. Language models produce text one token at a time. A model might begin with a refusal-like response, then continue with harmful content. In one analysis of a fine-tuned model, many prompts with high predicted probability of a refusal opening still led to harmful continuations. The practical implication is that checking or preserving only the first response decision may not be enough.

Protecting the opening and the continuation

The proposed method, SAFEHOLD, is designed for a provider that controls the fine-tuning process. It adds two safety objectives to the usual training on submitted examples. First, decision-boundary anchoring encourages the adapted model to preserve the original aligned model’s full distribution of possible first response tokens for a small set of provider-selected safety probes. Second, refusal-path reinforcement trains the model to produce a complete trusted refusal, token by token.

In effect, the first objective protects the model’s initial response preference; the second provides guidance for what follows. The provider combines both objectives with the fine-tuning loss in a single update. The authors say the approach uses eight fixed safety probes and a shared refusal text, needs no large trusted safety corpus, and makes no changes to the model’s ordinary inference process. It does, however, depend on provider control over training.

What the tests found

The experiments covered five open-weight, code-capable instruction models. The team fine-tuned them using low-rank adaptation and evaluated harmful compliance on three code-safety benchmarks. The main harmful training set contained 300 instruction-response pairs; additional harmful corpora were used for cross-domain analyses. The paper reports attack success rate (ASR), a measure of harmful compliance, alongside two checks of benign-task performance: refusal on safe prompts and functional code generation.

Across the five models and three harmful-code benchmarks, average ASR was 95.08% after fine-tuning without a defense and 23.05% with SAFEHOLD—a reported reduction of 72.03 percentage points. In comparisons with five other defenses, SAFEHOLD had the lowest or tied-lowest ASR in all 15 model-benchmark combinations. Its average ASR was lower than that of the strongest competing method by 24.32 percentage points, according to the authors.

The method also performed well on the study’s selected benign tests. Average over-refusal—the share of valid responses that fully refused safe prompts—was 2.73%. Average HumanEval pass@1, a measure of whether generated code passes tests on its first try, was 48.41%, compared with 38.17% after undefended fine-tuning. These results do not establish that the method improves every kind of coding or instruction-following task; they describe performance on the benchmarks used.

Ablation tests support the authors’ rationale: combining the two objectives performed better overall than using either alone, and supervising the complete refusal was more effective than training only the first refusal token. The paper also reports changes in internal activation patterns, but these analyses are evidence about model behavior and representations—not proof of a single underlying safety mechanism.

What remains uncertain

The results are promising but bounded. The study tests five models, a particular fine-tuning setup, a small fixed set of safety probes, and selected benchmarks. The authors identify broader model coverage and more diverse training data as future work. Harmful-response scoring relied on an automated judge, though responses were evaluated repeatedly and a sample of judgments was manually checked. Performance on other models, training conditions, harmful-request categories, or real-world deployments may differ.

This work is an arXiv preprint, not evidence by itself of independent replication or peer-reviewed validation. Its results suggest that refusal can be treated as a sequence to preserve, not merely a decision at the start of an answer. Whether SAFEHOLD generalizes beyond the tested setting remains an open question.

Source: Tian et al., “Trained on Harm, Still Refusing: A Training-Time Defense for Code Generation”.

Reviewed cross-references

These connections were reviewed by a model, not independently fact-checked by a human. Similarity does not imply agreement; consult the original papers and the evidence below.

  • Targeted weight edits help restore AI refusal behavior after fine-tuning

    Supporting evidence: Both studies report that fine-tuning can weaken refusal behavior and that a targeted intervention can improve safety measures: SAFEHOLD tests provider-controlled protection during harmful code fine-tuning, while SPECTRA applies a weight-level repair after domain-specific fine-tuning. Their model populations, adaptation settings and evaluation tasks differ, so the results support only this bounded connection, not comparative effectiveness or generalization across settings.

    Model review: · openai-codex/gpt-6-luna

    Evidence and provenance

    Selected excerpts, not complete papers. PDF extraction can omit figures or damage equations, tables and reading order; sources may be preprints.

    • 2611.27495v1 — Original paper

      Excerpt reference: static/papers/2611.27495v1.md:13-81
      Basis: Paper text
      Source SHA-256: f4a805cbf458b8bd548af2f8f6d20339a01668e31d00c971efd3d04f961f8d4b

    • 2611.27495v1 — Original paper

      Excerpt reference: static/papers/2611.27495v1.md:1651-1733
      Basis: Paper text
      Source SHA-256: f4a805cbf458b8bd548af2f8f6d20339a01668e31d00c971efd3d04f961f8d4b

    • 2611.10279v1 — Original paper

      Excerpt reference: static/papers/2611.10279v1.md:13-73
      Basis: Paper text
      Source SHA-256: 95cc2959b35b4b482b1c16c5fcee13b3caa192bf8055479e94e65ef00c6ffbe2

    • 2611.10279v1 — Original paper

      Excerpt reference: static/papers/2611.10279v1.md:804-913
      Basis: Paper text
      Source SHA-256: 95cc2959b35b4b482b1c16c5fcee13b3caa192bf8055479e94e65ef00c6ffbe2

Automatically matched by shared topic keywords. These links do not imply that the sources agree or establish a consensus.