NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Safety Pretraining: Toward the Next Generation of Safe AI

Pratyush Maini, Sachin Goyal, Dylan Sam, Alexander Robey, Yash Savani, Yiding Jiang, Andy Zou, Matt Fredrikson, Zachary Chase Lipton, J Zico Kolter

Abstract

Current AI safety methodologies largely rely on post-hoc alignment techniques like Reinforcement Learning from Human Feedback (RLHF), which often act as superficial patches over a model's underlying training. This paper argues that safety should be a foundational component of the pretraining phase. We introduce a four-pillar data-centric framework—including safety filtering, synthetic recontextualization, native refusal training, and harmfulness tagging—to develop SafeLM. Our results demonstrate that SafeLM is significantly more robust to attacks and downstream fine-tuning than standard models, reducing attack success rates from 38.8% to 8.4% without compromising general intelligence.

Introduction

The prevailing industry standard for AI safety is "alignment"—applying safety constraints after a model has been trained on vast, often toxic, web data. However, alignment is not unlearning. Once a model internalizes harmful patterns during pretraining, these patterns remain embedded in its core, leading to "brittleness." Highly aligned models can often be "jailbroken" through prompt engineering or lose their safety guardrails when fine-tuned on benign datasets. This research seeks to move safety from an afterthought to a core element of the pretraining process, baking ethics into the model's "DNA."

Methodology: A Four-Pillar Framework

To build safety into the pretraining phase, we propose a comprehensive data-centric framework consisting of four key interventions:

  1. Safety Filtering & Scoring: We utilized a high-quality safety classifier to score web data on a scale from 0 (safe) to 5 (highly unsafe), allowing for granular control over training data quality.
  2. Synthetic Recontextualization (SafeWeb): Rather than simply deleting unsafe data and losing factual context, we used LLMs to rewrite toxic content into safe, educational narratives. For instance, a toxic historical post is transformed into a classroom-style discussion on the ethical implications of the event.
  3. Native Refusal Training (RefuseWeb & Moral Education): We integrated datasets that teach the model how and why to refuse harmful requests. "Moral Education" data provides the ethical reasoning behind safety boundaries, moving beyond rote memorization of refusal templates.
  4. Harmfulness-Tagging & Safe Beam Search: During pretraining, potentially unsafe content is flagged with a special token (<potentially_unsafe_content>). At inference, a novel Safe Beam Search algorithm monitors the probability of this token and steers the model toward safer generation paths.
The SafeLM framework combines data-centric safety pillars with architectural interventions to significantly reduce harmfulness scores compared to standard models.

Experimental Results

We evaluated our approach using a 1.7B parameter model (SafeLM) across several benchmarks, including a new evaluation set, jb-completions, designed specifically for base models.

Robustness to Attacks

SafeLM showed a dramatic reduction in Attack Success Rate (ASR). On standard safety benchmarks, the ASR dropped from 38.8% in standard models to 8.3% in SafeLM. Even as a base model (prior to any instruction tuning), SafeLM maintained an ASR of only 11%, compared to 44% for standard base models.

Resilience to Fine-Tuning

A common failure mode for aligned models is the degradation of safety guardrails when fine-tuned on benign data (e.g., mathematics). SafeLM demonstrated superior robustness, maintaining low harmfulness scores even after extensive fine-tuning on the GSM8k dataset.

Intelligence Preservation

Crucially, these safety interventions did not incur an "intelligence tax." SafeLM performed competitively with standard models on general benchmarks such as MMLU and GSM8K, proving that safety and capability are not mutually exclusive.

Discussion and Key Insights

Our findings support the "Outer Onion" Hypothesis: safety risks are absorbed deep into a model's core during pretraining, and post-training alignment only peels the outer layer. Furthermore, we found that total censorship is counterproductive; models trained only on the "safest" data (Score 0) were more vulnerable to attacks because they lacked an understanding of what "unsafe" content looks like. Teaching the logic behind refusals through Moral Education proved to be the most effective single intervention.

Limitations and Future Work

While promising, SafeLM exhibits a slight increase in "over-refusal," where benign requests near safety boundaries are occasionally declined. Additionally, while Safe Beam Search is effective, future research must address potential "inference-aware" attacks. Scaling this framework to frontier-class models (70B+ parameters) remains a critical next step to ensure these safety benefits persist as model capabilities grow.

Summary updated

BibTeX
@inproceedings{maini2025safety,
  author = {Pratyush Maini and Sachin Goyal and Dylan Sam and Alexander Robey and Yash Savani and Yiding Jiang and Andy Zou and Matt Fredrikson and Zachary Chase Lipton and J Zico Kolter},
  title = {{Safety Pretraining: Toward the Next Generation of Safe AI}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=91H9CSvdwl},
}
Figure