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

Backtracking Improves Generation Safety

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

In the world of Large Language Models (LLMs), text generation is usually a one-way street. Once a token is sampled and added to the context, the model is stuck with it. If a model accidentally starts generating a harmful response—perhaps due to a clever jailbreak or an "edge case" encoding—it tends to double down, following the statistical gravity of its own unsafe prefix.

A new paper from researchers at Meta and CMU, titled "Backtracking Improves Generation Safety," proposes a deceptively simple fix: give the model an "undo" button.

The Auto-Regressive Trap

Current safety alignment relies almost entirely on prevention—trying to make the probability of a harmful token zero. However, the "attack surface" of a text interface is effectively infinite. Attackers use base64 encoding, low-resource languages, or complex roleplay to bypass these filters.

The core issue is the auto-regressive nature of LLMs: once a model starts an unsafe sentence, the most likely next tokens are also unsafe. The authors hypothesize that it is often easier for a model to verify safety after a few tokens have been generated than to prevent the first "bad" token from ever appearing.

How Backtracking Works

To solve this, the researchers introduce a mechanism where a model can "take back" its words by emitting a special [RESET] token.

Overview of the Backtracking method

The training and inference pipeline consists of three main steps:

  1. Backtracking SFT (Supervised Fine-Tuning): The model is trained on contrastive demonstrations. Given an unsafe prompt and a partial unsafe response, the model is taught to generate [RESET] followed by a safe refusal or alternative.
  2. Backtracking DPO (Direct Preference Optimization): SFT alone isn't enough to make the model reliably use the token. The authors use DPO to rank [unsafe prefix + RESET + safe response] higher than a purely [unsafe response]. They also include negative examples to ensure the model doesn't become "trigger happy" and backtrack on perfectly safe text.
  3. Inference Tuning: At test time, if the model generates [RESET], the generation API wipes all tokens generated before it and returns only what follows. Developers can also apply a logit bias to the [RESET] token, acting as a "safety-efficiency knob."

Key Results and Trade-offs

The results on models like Llama-3-8B and Gemma-2-2B demonstrate a massive safety boost without degrading general utility (measured via MT-Bench).

  • Massive Safety Boost: Backtracking Llama-3-8B was roughly four times safer than the baseline, dropping the overall violation rate from 6.1% to 1.5%.
  • Robustness to Jailbreaks: Against the potent GCG (Gradient-based Coordinate Greedy) attack, the success rate dropped from 62.5% to 16.5% for Llama. The models even resisted adaptive attacks designed specifically to suppress the [RESET] token.

However, backtracking isn't entirely free. If a model generates 20 tokens and then hits [RESET], those 20 tokens represent wasted compute and increased latency.

Safety and efficiency trade-offs across logit biases

As shown above, adjusting the logit bias allows developers to manage this trade-off. A higher logit bias increases safety (lower Unsafe %) but slightly increases the time to the first non-reset token and lowers overall tokens per second. Fortunately, for standard, non-malicious prompts, the model almost never backtracks, meaning this "efficiency tax" is primarily paid only when the model is actually in a high-risk state.

Limitations and Future Work

  • One-Shot Limitation: In this study, the authors restricted the model to backtracking only once per generation to keep training stable. Future work could explore multi-turn backtracking.
  • False Positives: The model occasionally backtracks on safe content. Tuning the logit bias can reduce this, but it remains a balancing act.
  • Beyond Safety: The authors suggest that backtracking could be applied to other LLM challenges, such as hallucinations or logical errors in math and coding, allowing a model to realize mid-sentence that its reasoning has gone off the rails.

By moving from a paradigm of "perfect prevention" to "active recovery," backtracking provides a pragmatic and highly effective new layer for the AI safety stack.

Summary updated

BibTeX
@inproceedings{zhang2025backtracking,
  author = {Yiming Zhang and Jianfeng Chi and Hailey Nguyen and Kartikeya Upasani and Daniel M. Bikel and Jason E 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