Reasoning-to-Defend: Safety-Aware Reasoning Can Defend Large Language Models from Jailbreaking

Junda Zhu, Lingyong Yan, Shuaiqiang Wang, Dawei Yin, Lei Sha
2/18/2025
cs.CL

No official code found. Best implementation: chuhac/Reasoning-to-Defend (12 stars, MIT, last commit 2025-08-22).

Abstract

Large Reasoning Models (LRMs) have recently demonstrated impressive performances across diverse domains. However, how the safety of Large Language Models (LLMs) benefits from enhanced reasoning capabilities against jailbreak queries remains unexplored. To bridge this gap, in this paper, we propose Reasoning-to-Defend (R2D), a novel training paradigm that integrates a safety-aware reasoning mechanism into LLMs' generation process. This enables self-evaluation at each step of the reasoning process, forming safety pivot tokens as indicators of the safety status of responses. Furthermore, in order to improve the accuracy of predicting pivot tokens, we propose Contrastive Pivot Optimization (CPO), which enhances the model's perception of the safety status of given dialogues. LLMs dynamically adjust their response strategies during reasoning, significantly enhancing their safety capabilities defending jailbreak attacks. Extensive experiments demonstrate that R2D effectively mitigates various attacks and improves overall safety, while maintaining the original performances. This highlights the substantial potential of safety-aware reasoning in improving robustness of LRMs and LLMs against various jailbreaks.

View on arXivView PDF

Code Implementations(1)

MIT

[EMNLP 2025] Reasoning-to-Defend: Safety-Aware Reasoning Can Defend Large Language Models from Jailbreaking

121Shell, PythonFeb 18, 20251 years agoMIT

Similar Papers

Cite this paper

@article{zhu2025reasoningtodefend,
  title  = {Reasoning-to-Defend: Safety-Aware Reasoning Can Defend Large Language Models from Jailbreaking},
  author = {Junda Zhu and Lingyong Yan and Shuaiqiang Wang and Dawei Yin and Lei Sha},
  year   = {2025},
  eprint = {2502.12970},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2502.12970v3}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2502.12970.svg)](https://codeofpaper.com/paper/2502.12970)

Discussion