SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2602.04893 · 2026

A Causal Perspective for Enhancing Jailbreak Attack and Defense

Kui Ren, Hui Xue, Zhixuan Chu, Licheng Pan, Jiexi Liu, Yunsheng Lu, Haozhe Feng, Jialing Tao

arXiv · PDF · Open in the Atlas

Code that ran

3 of 5 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (3 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 0 failures of our instrument; 2 no recorded run), measured 2026-11-22; 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/2602.04893.json · badge: /api/ran/2602.04893.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
Master-PLC/Causal-Analyst community
Papers with Code archive
3 ran · 2 no recorded run
FunctionStatusWhere it lives
CausalAnalystOutputWithPast Ran
ran on a synthesized input · constructed an object; no result was computed
Master-PLC/Causal-Analyst/src/llamafactory/custom/qwen2causal/modeling_qwen2custom.py
code served (permissive licence) · get_code("3a1da1d05f23b202")
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 an instance of its own class, CausalAnalystOutputWithPast: the run constructed the object and did not call it, so no result was computed. 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
from transformers.utils import ModelOutput

torch.manual_seed(0)

# Create small tensors for the output
batch_size = 2
seq_length = 4
vocab_size = 3
hidden_dim = 4
num_layers = 2
num_heads = 2

# loss: Optional[torch.FloatTensor]
loss = torch.tensor(0.5)

# logits: Optional[torch.FloatTensor]
logits = torch.randn(batch_size, seq_length, vocab_size)

# past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]]
# Typical structure: tuple of tuples containing key/value pairs per layer
past_key_values = tuple(
    (torch.randn(batch_size, num_heads, seq_length, hidden_dim),
     torch.randn(batch_size, num_heads, seq_length, hidden_dim))
    for _ in range(num_layers)
)

# hidden_states: Optional[Tuple[torch.FloatTensor, ...]]
hidden_states = tuple(
    torch.randn(batch_size, seq_length, hidden_dim)
    for _ in range(num_layers + 1)
)

# attentions: Optional[Tuple[torch.FloatTensor, ...]]
attentions = tuple(
    torch.randn(batch_size, num_heads, seq_length, seq_length)
    for _ in range(num_layers)
)

# classes: Optional[torch.FloatTensor]
classes = torch.randn(batch_size, 5)

# losses: Optional[Dict[str, float]]
losses = {
    "loss_cls": 0.3,
    "loss_mlm": 0.2,
}

ARGS = {
    "loss": loss,
    "logits": logits,
    "past_key_values": past_key_values,
    "hidden_states": hidden_states,
    "attentions": attentions,
    "classes": classes,
    "losses": losses,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type CausalAnalystOutputWithPast — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a CausalAnalystOutputWithPast 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
DAGGNN_MLPDecoder Ran
ran on a synthesized input · constructed an object; no result was computed
Master-PLC/Causal-Analyst/src/llamafactory/custom/qwen2causal/modeling_qwen2custom.py
code served (permissive licence) · get_code("5f86e84a8bd6d2d5")
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 an instance of its own class, DAGGNN_MLPDecoder: the run constructed the object and did not call it, so no result was computed. 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
import torch.nn as nn

torch.manual_seed(0)

# Stand-in config class with required attributes
class Config:
    def __init__(self):
        self.decoder_dropout = 0.1

# Helper function that's called in forward()
def preprocess_adj_new1(adj):
    """Simple preprocessing: normalize adjacency matrix"""
    return adj / (adj.sum(dim=1, keepdim=True) + 1e-8)

# Create config
config = Config()

# Parameters for DAGGNN_MLPDecoder
n_feat = 5  # number of features
in_dim = 4  # input dimension
hidden_dim = 8  # hidden dimension (different from in_dim for clarity)
out_dim = 3  # output dimension (different from hidden_dim)

# Create dummy tensors for forward pass
# batch_size=2, n_nodes=2
batch_size = 2
n_nodes = 2

input_z = torch.randn(n_nodes, in_dim)  # shape: (2, 4)
origin_A = torch.randn(n_nodes, n_nodes)  # adjacency matrix: (2, 2)
Wa = torch.randn(n_nodes, in_dim)  # shape: (2, 4)

ARGS = {
    'config': config,
    'n_feat': n_feat,
    'in_dim': in_dim,
    'hidden_dim': hidden_dim,
    'out_dim': out_dim,
}
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 DAGGNN_MLPDecoder — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a DAGGNN_MLPDecoder 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
DAGGNN_MLPEncoder Ran
ran on a synthesized input · constructed an object; no result was computed
Master-PLC/Causal-Analyst/src/llamafactory/custom/qwen2causal/modeling_qwen2custom.py
code served (permissive licence) · get_code("7e423932593696a9")
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 an instance of its own class, DAGGNN_MLPEncoder: the run constructed the object and did not call it, so no result was computed. 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
import torch.nn as nn

torch.manual_seed(0)

# Define a minimal config class with the required attribute
class MinimalConfig:
    def __init__(self):
        self.encoder_dropout = 0.1

# Define preprocess_adj_new function since it's used in forward()
def preprocess_adj_new(adj):
    # Simple stand-in: just normalize or process the adjacency matrix
    # For testing purposes, return a normalized version
    return adj / (torch.sum(adj, dim=1, keepdim=True) + 1e-8)

# Make it available in the global scope for the forward method
import builtins
builtins.preprocess_adj_new = preprocess_adj_new

# Create test data
config = MinimalConfig()
n_feat = 5
in_dim = 4
hidden_dim = 8
out_dim = 3

# Create small input tensor (batch_size=2, in_dim=4)
inputs = torch.randn(2, in_dim)

ARGS = {
    "config": config,
    "n_feat": n_feat,
    "in_dim": in_dim,
    "hidden_dim": hidden_dim,
    "out_dim": out_dim,
    "tol": 0.1
}
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 DAGGNN_MLPEncoder — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a DAGGNN_MLPEncoder 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
DAGGNN Not yet run
unverified (harvested, no recorded run)
Master-PLC/Causal-Analyst/src/llamafactory/custom/qwen2causal/modeling_qwen2custom.py
code served (permissive licence) · get_code("aee6beb843bd077e")
How it ran

no invocation recorded.

Qwen2Custom Not yet run
unverified (harvested, no recorded run)
Master-PLC/Causal-Analyst/src/llamafactory/custom/qwen2causal/modeling_qwen2custom.py
code served (permissive licence) · get_code("beb993005a8f2ad3")
How it ran

no invocation recorded.

Also present in other papers' code

Of 5 samples lifted from this paper's linked repositories, 5 carry a function identity and 0 do not. Of the 5 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 5 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.

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

Uncovering the mechanisms behind "jailbreaks" in large language models (LLMs) is crucial for enhancing their safety and reliability, yet these mechanisms remain poorly understood. Existing studies predominantly analyze jailbreak prompts by probing latent representations, often overlooking the causal relationships between interpretable prompt features and jailbreak occurrences. In this work, we propose Causal Analyst, a framework that integrates LLMs into data-driven causal discovery to identify the direct causes of jailbreaks and leverage them for both attack and defense. We introduce a comprehensive dataset comprising 35k jailbreak attempts across seven LLMs, systematically constructed from 100 attack templates and 50 harmful queries, annotated with 37 meticulously designed human-readable prompt features. By jointly training LLM-based prompt encoding and GNN-based causal graph learning, we reconstruct causal pathways linking prompt features to jailbreak responses. Our analysis reveals that specific features, such as "Positive Character" and "Number of Task Steps", act as direct causal drivers of jailbreaks. We demonstrate the practical utility of these insights through two applications: ❶ a Jailbreaking Enhancer that targets identified causal features to significantly boost attack success rates on public benchmarks, and ❷ a Guardrail Advisor that utilizes the learned causal graph to extract true malicious intent from obfuscated queries. Extensive experiments, including baseline comparisons and causal structure validation, confirm the robustness of our causal analysis and its superiority over non-causal approaches. Our results suggest that analyzing jailbreak features from a causal perspective is an effective and interpretable approach for improving LLM reliability. Our code is available at https://github.com/Master-PLC/Causal-Analyst. Warning: Some contents may include disturbing contents.

For agents

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

get_harvested_code_for_paper("2602.04893")
get_code_for_paper("2602.04893")
have("2602.04893")

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

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

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

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

Connect an agent — have() is free.