SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2502.12970 · EMNLP · 2025

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

Shuaiqiang Wang, Dawei Yin, Lingyong Yan, Sha Lei, Junda Zhu

arXiv · PDF · Open in the Atlas

Code that ran

5 of 6 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 3 failures of our instrument; 1 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2502.12970.json · badge: /api/ran/2502.12970.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
chuhac/Reasoning-to-Defend canonical (classifier label)
classifier basis not recorded on the link
5 ran · 1 no recorded run
FunctionStatusWhere it lives
expand_experiment_configs Ran
ran; our contract draft was wrong, not the code
chuhac/Reasoning-to-Defend/HarmBench/eval_utils.py
pointer only (licence: MIT); the stored copy get_code serves, from youai058/SlotGCG, is pointer only (licence: NONE) · get_code("6fa90dd36057918e")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from youai058/SlotGCG, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

parse_indexing_expression Ran
ran; our contract draft was wrong, not the code
chuhac/Reasoning-to-Defend/HarmBench/eval_utils.py
pointer only (licence: MIT); the stored copy get_code serves, from youai058/SlotGCG, is pointer only (licence: NONE) · get_code("914cce1bc1e0a0d8")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from youai058/SlotGCG, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

r2d_post_process Ran
ran on a synthesized input
chuhac/Reasoning-to-Defend/HarmBench/generate_completions.py
code served (permissive licence) · get_code("0d79bfe766d28836")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import re

def r2d_post_process(text):
    separators = '(\\[SAFE\\]|\\[UNSAFE\\]|\\[RETHINK\\])'
    safe_text = ''
    if re.search(separators, text):
        result = re.split(separators, text)
        for i in range(0, len(result) - 1, 2):
            if result[i + 1] in '[SAFE], [RETHINK]':
                safe_text += result[i]
    else:
        safe_text = text
    return safe_text


# Test case 1: text with separators
text_with_separators = "Hello [SAFE] world [UNSAFE] foo [RETHINK] bar"

# Test case 2: text without separators
text_without_separators = "This is plain text without any markers"

# Test case 3: text with only SAFE markers
text_only_safe = "Start [SAFE] middle [SAFE] end"

ARGS = {
    "text": text_with_separators
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
r2d_post_process Ran
ran on a synthesized input
chuhac/Reasoning-to-Defend/jailbreakbench/jbb_response.py
code served (permissive licence) · get_code("0ea81c2966470a99")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

def r2d_post_process(text):
    return text

torch.manual_seed(0)

ARGS = {
    "text": "sample text output"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
replace_model_parameters Ran
ran; our contract draft was wrong, not the code
chuhac/Reasoning-to-Defend/HarmBench/eval_utils.py
pointer only (licence: MIT); the stored copy get_code serves, from youai058/SlotGCG, is pointer only (licence: NONE) · get_code("0393dcd85dc803dd")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from youai058/SlotGCG, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

load_model_and_tokenizer Not yet run
unverified (harvested, no recorded run)
chuhac/Reasoning-to-Defend/HarmBench/baselines/model_utils.py
code served (permissive licence) · get_code("090eed81a24d4b32")
How it ran

no invocation recorded.

Also present in other papers' code

Of 6 samples lifted from this paper's linked repositories, 6 carry a function identity and 0 do not. Of the 6 distinct functions with an identity, 4 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 0 the same month, 4 later) and 2 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
expand_experiment_configs 3 other papers
1 dated earlier, 2 later
2408.14866 (2024-08)
Advancing Adversarial Suffix Transfer Learning on Aligned Large Language Models
2605.08898 (2026-05)
LLM-Agnostic Semantic Representation Attack
2606.05609 (2026-06)
SlotGCG: Exploiting the Positional Vulnerability in LLMs for Jailbreak Attacks
load_model_and_tokenizer 3 other papers
2 dated earlier, 1 later
2408.14866 (2024-08)
Advancing Adversarial Suffix Transfer Learning on Aligned Large Language Models
2501.01872 (2025-01)
Turning Logic Against Itself : Probing Model Defenses Through Contrastive Questions ! WARNING: This paper contains model outputs that may be considered offensive in nature
2605.08898 (2026-05)
LLM-Agnostic Semantic Representation Attack
parse_indexing_expression 3 other papers
1 dated earlier, 2 later
2408.14866 (2024-08)
Advancing Adversarial Suffix Transfer Learning on Aligned Large Language Models
2605.08898 (2026-05)
LLM-Agnostic Semantic Representation Attack
2606.05609 (2026-06)
SlotGCG: Exploiting the Positional Vulnerability in LLMs for Jailbreak Attacks
replace_model_parameters 3 other papers
1 dated earlier, 2 later
2408.14866 (2024-08)
Advancing Adversarial Suffix Transfer Learning on Aligned Large Language Models
2605.08898 (2026-05)
LLM-Agnostic Semantic Representation Attack
2606.05609 (2026-06)
SlotGCG: Exploiting the Positional Vulnerability in LLMs for Jailbreak Attacks

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

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 Reasoningto-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. 1

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2502.12970")
get_code_for_paper("2502.12970")
have("2502.12970")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2502.12970.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2502.12970.svg)](https://syntology.ai/paper/2502.12970)

Connect an agent — have() is free.