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

Backtracking Improves Generation Safety

Yiming Zhang, Jianfeng Chi, Hailey Nguyen, Kartikeya Upasani, Daniel M. Bikel, Jason Weston, Eric Michael Smith · OpenReview

Abstract

Text generation has a fundamental limitation almost by definition: there is no taking back tokens that have been generated, even when they are clearly problematic. In the context of language model safety, when a partial unsafe generation is produced, language models by their nature tend to happily keep on generating similarly unsafe additional text. This is in fact how safety alignment of frontier models gets circumvented in the wild, despite great efforts in improving their safety. Deviating from the paradigm of approaching safety alignment as prevention (decreasing the probability of harmful responses), we propose backtracking, a technique that allows language models to "undo" and recover from their own unsafe generation through the introduction of a special [RESET] token. Our method can be incorporated into either SFT or DPO training to optimize helpfulness and harmlessness. We show that models trained to backtrack are consistently safer than baseline models: backtracking Llama-3-8B is four times more safe than the baseline model (5.3% → 1.5%) in our evaluations without regression in helpfulness. Our method additionally provides protection against four adversarial attacks including an adaptive attack, despite not being trained to do so.

Introduction

The current "gold standard" for AI safety is prevention—training models to never initiate a harmful response. However, the potential "attack surface" for text is virtually infinite. Even state-of-the-art models like GPT-4 can be jailbroken using simple techniques like encoding malicious prompts in Base64 or low-resource languages. The core issue lies in the autoregressive nature of LLMs: once a model starts down an unsafe path, it is forced to continue that trajectory. We argue that it is often easier for a model to verify safety after a few tokens have been generated than it is to prevent an unsafe start entirely. We propose shifting the safety paradigm from prevention to recovery through a mechanism called backtracking.

Methodology: The Backtracking Framework

Backtracking introduces a new capability: the model can recognize its own mistake, stop, and start over. This is achieved through three main components:

  1. The [RESET] Token: A special control token is introduced. When the model emits [RESET], the generation API discards all preceding tokens and returns only the text generated afterward.
  2. Supervised Fine-Tuning (SFT): Models are trained on contrastive demonstrations where an unsafe prefix is followed by [RESET] and then a safe, helpful response. This teaches the mechanics of backtracking.
  3. Direct Preference Optimization (DPO): To teach the model when to backtrack, we use preference pairs. The model learns to prefer a "backtracked" safe response over a continued unsafe one, while also learning to avoid "over-backtracking" on safe initial text.
Overview of the backtracking training process (SFT and DPO) and inference mechanism.

Experimental Results

We evaluated our approach using Llama-3-8B and Gemma-2-2B across several safety benchmarks, including AdvBench (AB), MaliciousInstructions (MI), SimpleSafetyTests (SST), and StrongREJECT (SR). Helpfulness was measured using MT-Bench.

Safety and Helpfulness

Backtracking models demonstrated significant safety improvements. For Llama-3-8B, the overall safety violation rate dropped from 5.3% to 1.5%, a 72% relative reduction. Gemma-2-2B saw a reduction from 10.6% to 6.1%. Crucially, this "safety gain" did not come at the cost of helpfulness; backtracking models maintained or slightly improved their scores on MT-Bench compared to baselines.

Safety violation rates across benchmarks and MT-Bench helpfulness scores for baseline and backtracking models.

Adversarial Robustness

Backtracking proved remarkably resilient to adversarial attacks. In white-box attacks like GCG (Gradient-based Control Generation), the backtracking Llama model reduced attack success rates from 62.5% to 16.5%. It also naturally defended against "prefilling" attacks, where an attacker starts the model's response, by simply resetting the forced start.

Discussion

While backtracking adds a small latency cost (approximately 1 second for the reset process), this can be managed using a tunable logit bias on the [RESET] token. This allows developers to trade off a small amount of safety for higher efficiency. Beyond safety, the backtracking mechanism offers a promising path for correcting other autoregressive errors, such as logical fallacies or hallucinations, by providing a one-shot escape hatch from a problematic context.

Summary updated

BibTeX
@inproceedings{zhang2025backtracking,
  author = {Yiming Zhang and Jianfeng Chi and Hailey Nguyen and Kartikeya Upasani and Daniel M. Bikel and Jason Weston and Eric Michael Smith},
  title = {{Backtracking Improves Generation Safety}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=Bo62NeU6VF},
}
Figure