Reasoning-to-Defend

August 22, 2025 · View on GitHub

License: MIT

Code for paper

Reasoning-to-Defend: Safety-Aware Reasoning Can Defend Large Language Models from Jailbreaking
Junda Zhu, Lingyong Yan, Shuaiqiang Wang, Dawei Yin, Lei Sha

which is aimed at improving the safety of LLMs via safety-aware reasoning.

overview

News:

  • Aug 20th, 2025: R2D is accepted by EMNLP 2025 Main Conference.
  • May 31st, 2025: Dataset released, and is available at huggingface.
  • Mar 9th, 2025: Code for R2D has been released. The dataset is currently being organized.
  • Feb 18th, 2025: R2D's paper is publicly available at arxiv.

Usage

Training R2D Model

In order to better conduct Contrastive Pivot Optimization proposed in the paper, we expand the vocabularies before training.

cd r2d_train
bash expand_and_train.sh

Evaluation

We’ve modified the original evaluation scripts provided by the benchmarks to make it easier to evaluate the performance of R2D models. These scripts can be found in the respective folders.

Acknowledgement

Citation

If you find this repository useful, please cite our paper:

@article{zhu2025reasoning,
  title={Reasoning-to-Defend: Safety-Aware Reasoning Can Defend Large Language Models from Jailbreaking},
  author={Zhu, Junda and Yan, Lingyong and Wang, Shuaiqiang and Yin, Dawei and Sha, Lei},
  journal={arXiv preprint arXiv:2502.12970},
  year={2025}
}