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

Backtracking for Safety

Bilgehan Sel, Dingcheng Li, Phillip Wallis, Vaishakh Keshava, Ming Jin, Siddhartha Reddy JonnalagaddaarXiv 2025 · DOI

Introduction

Large Language Models (LLMs) typically rely on Supervised Fine-Tuning (SFT) and Reinforcement Learning from Human Feedback (RLHF) for safety alignment. While effective at preventing models from initiating harmful responses, these methods often exhibit "shallow alignment." They struggle when safety violations occur deep within a long, otherwise helpful response. This vulnerability is particularly evident in prefilling attacks, where an adversary provides the initial tokens of a response (e.g., "Sure, I can help with that!"), tricking the model into a helpful state that bypasses initial safety filters.

The BSAFE Framework

To address these challenges, we introduce BSAFE (Backtracking for Safety). Unlike traditional methods that either refuse a prompt entirely or restart the generation process from scratch (the "Reset" method), BSAFE allows the model to surgically "undo" and correct safety violations mid-generation.

Comparison of Instruction Tuning (IT), Reset, and BSAFE methods in handling harmful queries and mid-response violations.

The framework treats safety as a dynamic, corrigible process through three primary mechanisms:

  1. Backtracking Mechanism: The model utilizes privileged tokens: [BACKTRACK] and [REPLACE]. Upon detecting a potential safety violation, the model emits [BACKTRACK], reverts to the state preceding the harmful segment, and uses [REPLACE] to provide a safe alternative.
  2. Modular Policy Tokens: Developers can fine-tune specific tokens (e.g., [BACKTRACK-RACISM]) to adjust the sensitivity of different safety policies independently.
  3. Controlled Finetuning: A new objective function constrains the model's deviation from a safe reference state specifically at potential backtrack points, acting as a per-token safety filter during training.

Experimental Evaluation

BSAFE was trained on a synthetic dataset of 128,000 question-answer pairs designed to elicit responses that start safe but deviate into harmful territory. Evaluation was conducted across several dimensions:

  • Safety Benchmarks: A custom 100-example prefilling attack dataset and the Harmful HEx-PHI benchmark.
  • Utility Benchmarks: Alpaca (general instruction), GSM8K, and MATH (reasoning) to ensure no loss in general intelligence.

Key Results

BSAFE significantly outperforms existing alignment and mitigation strategies. On prefilling attacks, baseline models like LLaMA 3 and Gemma 2 showed failure rates as high as 83%. BSAFE reduced these rates to between 6% and 9%.

Attack Success Rate comparison for Gemma2 9B across Pre-trained (PT), Instruction-Tuned (IT), Reset, and BSAFE methods.

Notably, BSAFE achieved an attack success rate of only 9% compared to 45% for the "Reset" approach, which discards the entire output. Furthermore, BSAFE-trained models showed virtually no degradation in utility; for instance, LLaMA3 8B maintained its performance on GSM8K (63.4% vs 63.1% baseline).

Conclusion and Future Work

BSAFE demonstrates that safety alignment must be "deep" and corrigible. By moving away from the "refusal-only" paradigm, LLMs can remain helpful while robustly defending against adversarial manipulation. Future research will explore expanding the scope of adversarial attacks tested, optimizing computational overhead for high-throughput environments, and implementing dynamic backtracking depths based on violation severity.

Summary updated

BibTeX
@misc{sel2025backtracking,
  author = {Bilgehan Sel and Dingcheng Li and Phillip Wallis and Vaishakh Keshava and Ming Jin and Siddhartha Reddy Jonnalagadda},
  title = {{Backtracking for Safety}},
  year = {2025},
  eprint = {2503.08919},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.08919},
}
Figure