Safety Mid-Training: Internalizing LLM Safety as a Foundational Capability

Zhengyue Zhao1 Liwei Jiang2 Yejin Choi3 Chaowei Xiao1
1Johns Hopkins University 2University of Washington 3Stanford University
Safety and general tasks share a reasoning structure, learned through self-generated documents and reasoning traces during safety mid-training
Safety mid-training learns safety as a foundational capability through a reasoning structure shared with general tasks. The base model generates the documents and traces used for training.

The resulting models improve safety while preserving general capability and retain safety through general-only SFT and GRPO, including GRPO without safety rewards.

Abstract

Safety alignment for large language models (LLMs) is primarily performed during post-training, while recent work has also begun incorporating safety data into pre-training. Yet safety can degrade when later training no longer includes safety data, and gains in safety often come at the cost of general capability. This tension suggests that safety and general reasoning should not be treated as separate training goals. We instead view safety as an LLM capability that can be learned through a reasoning structure shared with general tasks. Both require the model to understand intent or task goals, apply relevant knowledge, and reason about potential consequences. We introduce safety mid-training, a stage between pre-training and post-training that jointly develops safety and general reasoning through this shared structure. Given safety and utility prompts, the base model generates structured documents and reasoning traces that are then used for mid-training. Safety mid-training reduces average attack success rate (ASR) by 72% to 81% relative to Qwen3-1.7B, 4B, and 8B base models, while also improving general capability. The benefits persist through subsequent post-training. After general-only SFT, mid-trained models largely retain their safety, achieving lower ASR than the baselines without sacrificing general capability. They also retain safety under general-only GRPO without safety rewards, while subsequent RL reaches a better safety-utility frontier when initialized from the mid-trained models. Together, these results suggest that learning safety and general reasoning within a shared mid-training stage can reduce the safety-utility trade-off and make safety more robust to subsequent training.

Safety Mid-Training

Safety and general tasks both require the model to understand intent or task goals, apply relevant knowledge, and reason about possible consequences. Safety mid-training learns these abilities together by organizing both types of examples into structured documents and reasoning traces.

For each prompt, the base model first generates a document that brings together the information needed for a response. It then uses the document and reference answer to generate a reasoning trace and a final answer. Qwen3-32B evaluates the candidates for faithfulness, coherence, and consistency with the reference answer and safety label. Accepted candidates pass the rubric checks and receive a quality score of at least 4; failed candidates can be resampled using the judge's feedback.

The accepted documents and reasoning records are shuffled together for continued training of the base model. By learning the knowledge and reasoning behind safe responses alongside general tasks, the model develops safety as part of its broader capabilities. The resulting model is then used as the starting point for SFT or GRPO.

Main Results

Before supervised fine-tuning, safety mid-training improves both safety and utility at every Qwen3 scale.

ModelBase ASROurs ASRBase UtilityOurs Utility
Qwen3-1.7B30.48.429.858.6
Qwen3-4B34.16.647.673.1
Qwen3-8B25.44.970.377.1

Lower ASR is better; higher utility is better. Scores are percentages.

We consider nine safety and nine utility benchmarks. Because WildJailbreak and BeaverTails share benchmark sources with the mid-training safety data, and GSM8K and MATH-500 share sources with the general data, they are excluded from the main comparison averages below. Complete per-benchmark results are available in the paper's appendix. The safety-utility, SFT-mixture, and schema plots show the paper's full-suite averages.

Safety and utility results across Qwen3 and Llama-3.2 models
All evaluated Qwen3 and Llama-3.2 models shift toward lower ASR and higher utility after mid-training.

Safety Retention after Supervised Fine-Tuning

After balanced SFT, our models achieve the lowest average ASR across the Qwen3 scales, with higher or comparable general capability. When SFT uses only general data, they retain substantially more safety than the baselines and achieve the highest utility at each scale.

The Qwen3-4B comparison below illustrates this pattern. Removing safety examples from SFT raises ASR substantially for Safety Pretraining (SP) and Alignment Pretraining (AP), while the change is much smaller for Ours and utility is maintained.

MethodBalanced ASR ↓Balanced Utility ↑General-only ASR ↓General-only Utility ↑
Base + SFT (Distill Sonnet-4.6)22.868.129.167.8
Base + SFT10.865.613.659.4
SP + SFT7.773.817.374.6
AP + SFT7.373.714.573.3
Ours + SFT5.574.97.674.9

SP uses Safety Pretraining data; AP uses the safety mid-training data from Alignment Pretraining. General-only SFT contains no safety examples.

Results for all model sizes and SFT mixtures
ModelMethodBalanced ASR ↓Balanced Utility ↑Safety-only ASR ↓Safety-only Utility ↑General-only ASR ↓General-only Utility ↑
Qwen3-1.7BBase + SFT (Distill Sonnet-4.6)17.260.08.062.037.359.1
Qwen3-1.7BBase + SFT17.252.018.751.926.351.1
Qwen3-1.7BSP + SFT12.461.79.260.537.159.8
Qwen3-1.7BAP + SFT12.361.19.558.828.060.7
Qwen3-1.7BOurs + SFT8.960.97.461.211.261.7
Qwen3-4BBase + SFT (Distill Sonnet-4.6)22.868.126.871.029.167.8
Qwen3-4BBase + SFT10.865.69.966.213.659.4
Qwen3-4BSP + SFT7.773.84.873.117.374.6
Qwen3-4BAP + SFT7.373.76.072.014.573.3
Qwen3-4BOurs + SFT5.574.94.575.37.674.9
Qwen3-8BBase + SFT (Distill Sonnet-4.6)10.578.37.077.620.477.6
Qwen3-8BBase + SFT12.673.69.272.711.670.7
Qwen3-8BSP + SFT5.075.04.074.815.976.3
Qwen3-8BAP + SFT4.676.04.575.718.076.8
Qwen3-8BOurs + SFT3.478.13.178.85.178.2
Safety robustness as safety data is removed from supervised fine-tuning
Mid-trained models maintain substantially lower ASR as safety examples are removed from SFT. Full-suite averages, as in the paper's introductory figure.

Safety Retention during GRPO

Safety mid-training gives GRPO a stronger starting point and leads to better final safety and utility. With balanced safety and general data, the advantage remains throughout training on both Qwen3-1.7B and Qwen3-4B.

General-only GRPO uses neither safety prompts nor safety rewards. In this setting, mid-trained models retain much more of their safety than base models. On Qwen3-4B, moving from balanced to general-only GRPO reduces safety by 13.2 points for the base model, compared with 1.4 points for Ours, with little change in utility. This shows that the safety capability learned during mid-training remains effective as RL focuses on general tasks.

Balanced and general-only GRPO trajectories for base and safety-mid-trained Qwen3-1.7B and Qwen3-4B
Mid-trained models reach stronger final safety and utility under balanced GRPO and retain safety under general-only GRPO without safety rewards.

Generalization across Model Families

The same pipeline improves safety and utility on Llama-3.2 models. Self-generated mid-training data gives the strongest overall results at both evaluated scales, supporting the use of shared reasoning across model families.

ModelBase ASROurs ASRBase UtilityOurs Utility
Llama-3.2-1B31.310.123.629.4
Llama-3.2-3B41.45.924.947.8

Ablations

Using the same reasoning data for mid-training yields stronger safety and utility than applying it directly as SFT. The schema and data-mixture ablations below further support learning safety and general reasoning together.

We also compare self-generated data with data generated by Sonnet 4.6. Self-generation is competitive before SFT and gives lower ASR at every scale after balanced SFT, making the base model itself an effective source of mid-training data.

Ablation of intent, knowledge, and consequence fields
Removing intent, knowledge, or consequence information degrades both safety and utility.
Safety and utility as the unsafe prompt ratio changes
A 25% unsafe-prompt ratio provides the best overall safety-utility balance.