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.
The framework treats safety as a dynamic, corrigible process through three primary mechanisms:
- 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. - Modular Policy Tokens: Developers can fine-tune specific tokens (e.g.,
[BACKTRACK-RACISM]) to adjust the sensitivity of different safety policies independently. - 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%.
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