SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2025.acl-long.851 · ACL · 2025

AGD: Adversarial Game Defense Against Jailbreak Attacks in Large Language Models

Minlie Huang, Dongsheng Li, Xinwang Liu, Kai Lu, Zhen Huang, Zhiliang Tian, Zhihua Wen, Shilong Pan, Wanlong Yu

Open in the Atlas

Code that ran

8 of 8 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 5 have no contract verdict; 3 failures of our instrument; 0 no recorded run), measured 2026-11-24; 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/2025.acl-long.851.json · badge: /api/ran/2025.acl-long.851.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
uw-nsl/SafeDecoding canonical (classifier label)
classifier basis: census
8 ran · 0 no recorded run
FunctionStatusWhere it lives
extract_content Ran
ran on a synthesized input
uw-nsl/SafeDecoding/exp/safe_eval.py
code served (permissive licence) · get_code("00a0bbf79e4f82c8")
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 int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape 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

torch.manual_seed(0)

# The function extract_content takes two parameters: tag and text
# Both are strings based on how they're used in the function
# tag: a string to search for in text (e.g., '#thescore:')
# text: a string to search within

ARGS = {
    'tag': '#thescore:',
    'text': '#thescore: 42 some other content # more text'
}
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 int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
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
get_judge_name Ran
ran on a synthesized input
uw-nsl/SafeDecoding/mt_bench/compute_agreement.py
code served (permissive licence) · get_code("d24ec6691ff04146")
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 get_judge_name(judge):
    if isinstance(judge, list) and judge[0] == 'gpt-4' and judge[1].startswith('pair'):
        return 'gpt4-pair'
    if judge.startswith('expert'):
        return 'human'
    if judge.startswith('author'):
        return 'author'

# Test case 1: judge is a string starting with 'expert'
judge_1 = 'expert_evaluator'

# Test case 2: judge is a string starting with 'author'
judge_2 = 'author_review'

# Test case 3: judge is a list with 'gpt-4' and a string starting with 'pair'
judge_3 = ['gpt-4', 'pairwise_comparison']

# Use one of the test cases
ARGS = {
    'judge': judge_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 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
get_mt_bench_votes_data Ran
ran on a synthesized input
uw-nsl/SafeDecoding/mt_bench/compute_agreement.py
code served (permissive licence) · get_code("7745c0e675406cf2")
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 list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 numpy as np

def get_judge_name(judge):
    if isinstance(judge, list) and judge[0] == 'gpt-4' and judge[1].startswith('pair'):
        return 'gpt4-pair'
    if judge.startswith('expert'):
        return 'human'
    if judge.startswith('author'):
        return 'author'

def revert(vote):
    if vote == 'model_a':
        return 'model_b'
    elif vote == 'model_b':
        return 'model_a'
    return vote

def get_mt_bench_votes_data(raw_votes):
    data = [{}, {}]
    for judge_votes in raw_votes:
        for vote in judge_votes:
            turn = vote['turn'] - 1
            if vote['model_a'] < vote['model_b']:
                key = (vote['question_id'], vote['model_a'], vote['model_b'])
                winner = vote['winner']
            else:
                key = (vote['question_id'], vote['model_b'], vote['model_a'])
                winner = revert(vote['winner'])
            judge = get_judge_name(vote['judge'])
            if key not in data[turn]:
                data[turn][key] = {}
            if judge not in data[turn][key]:
                data[turn][key][judge] = []
            data[turn][key][judge].append(winner)
    return data

# Construct raw_votes data structure
# raw_votes is a list of judge_votes, where each judge_votes is a list of vote dicts
raw_votes = [
    # First judge's votes
    [
        {
            'turn': 1,
            'question_id': 101,
            'model_a': 'model_x',
            'model_b': 'model_y',
            'winner': 'model_a',
            'judge': ['gpt-4', 'pairwise']
        },
        {
            'turn': 2,
            'question_id': 102,
            'model_a': 'model_y',
            'model_b': 'model_z',
            'winner': 'model_b',
            'judge': 'expert_judge_1'
        }
    ],
    # Second judge's votes
    [
        {
            'turn': 1,
            'question_id': 101,
            'model_a': 'model_z',
            'model_b': 'model_x',
            'winner': 'model_b',
            'judge': 'author_submission'
        },
        {
            'turn': 2,
            'question_id': 102,
            'model_a': 'model_x',
            'model_b': 'model_y',
            'winner': 'model_a',
            'judge': ['gpt-4', 'pairwise']
        }
    ]
]

ARGS = {
    'raw_votes': raw_votes
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
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
load_judge_prompts Ran
ran; our contract draft was wrong, not the code
uw-nsl/SafeDecoding/mt_bench/common.py
code served (permissive licence) · get_code("41fd9954784a1330")
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 dict. 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 json
import tempfile
import os

# Create a temporary file with judge prompt data in JSONL format
temp_dir = tempfile.mkdtemp()
prompt_file = os.path.join(temp_dir, "judge_prompts.jsonl")

# Write sample judge prompts in JSONL format
with open(prompt_file, 'w') as f:
    judge_data_1 = {
        'name': 'judge_a',
        'prompt': 'You are an expert judge.',
        'version': '1.0'
    }
    f.write(json.dumps(judge_data_1) + '\n')
    
    judge_data_2 = {
        'name': 'judge_b',
        'prompt': 'You are a fair evaluator.',
        'version': '2.0'
    }
    f.write(json.dumps(judge_data_2) + '\n')

ARGS = {
    'prompt_file': prompt_file
}
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 dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
load_model Ran
ran on a synthesized input
uw-nsl/SafeDecoding/utils/model.py
code served (permissive licence) · get_code("3ff17004f6e9124f")
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 GPT. 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 os
from unittest.mock import Mock, MagicMock
from openai import OpenAI

# Mock the OpenAI API to avoid actual network calls
os.environ['OPENAI_API_KEY'] = 'sk-test-key-12345'

# Create a mock API response
mock_choice = Mock()
mock_choice.message.content = "This is a test response"

mock_response = Mock()
mock_response.choices = [mock_choice]

# Create a mock client
mock_client = Mock(spec=OpenAI)
mock_client.chat.completions.create.return_value = mock_response

ARGS = {
    'model_name': 'gpt-4',
    'api_idx': 0,
    'api': 'sk-test-key-12345'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
openai, tenacity — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type GPT — a GPT output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a GPT 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
load_model_answers Ran
ran; our contract draft was wrong, not the code
uw-nsl/SafeDecoding/mt_bench/common.py
code served (permissive licence) · get_code("270d3eb4371b0d85")
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 dict. 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 os
import json
import tempfile
import shutil

# Create a temporary directory to hold test JSONL files
test_dir = tempfile.mkdtemp()

# Create sample JSONL files with model answers
model_answers_data = {
    'model_a': [
        {'question_id': 1, 'text': 'answer to question 1', 'score': 0.9},
        {'question_id': 2, 'text': 'answer to question 2', 'score': 0.8},
    ],
    'model_b': [
        {'question_id': 1, 'text': 'another answer to question 1', 'score': 0.7},
        {'question_id': 2, 'text': 'another answer to question 2', 'score': 0.6},
    ]
}

# Write the JSONL files
for model_name, answers in model_answers_data.items():
    filepath = os.path.join(test_dir, f'{model_name}.jsonl')
    with open(filepath, 'w') as f:
        for answer in answers:
            f.write(json.dumps(answer) + '\n')

ARGS = {
    'answer_dir': test_dir
}
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 dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
load_questions Ran
ran; our contract draft was wrong, not the code
uw-nsl/SafeDecoding/mt_bench/common.py
code served (permissive licence) · get_code("88969cdc675c418e")
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 list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 json
import tempfile
import os

# Create a temporary file with sample question data
temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.jsonl')
questions_data = [
    {"id": 1, "question": "What is 2+2?", "answer": "4"},
    {"id": 2, "question": "What is the capital of France?", "answer": "Paris"},
    {"id": 3, "question": "What is 5*3?", "answer": "15"},
    {"id": 4, "question": "What is the largest planet?", "answer": "Jupiter"},
]

for q in questions_data:
    temp_file.write(json.dumps(q) + '\n')
temp_file.close()

ARGS = {
    'question_file': temp_file.name,
    'begin': 1,
    'end': 3,
}
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 list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
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
revert Ran
ran on a synthesized input
uw-nsl/SafeDecoding/mt_bench/compute_agreement.py
code served (permissive licence) · get_code("35801bf32affe123")
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

torch.manual_seed(0)

ARGS = {
    'vote': 'model_a'
}
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

Also present in other papers' code

Of 8 samples lifted from this paper's linked repositories, 8 carry a function identity and 0 do not. Of the 8 distinct functions with an identity, 6 are also present in other papers whose code we hold (6 with at least one paper dated earlier, 0 the same month, 0 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
load_judge_prompts 3 other papers
2 dated earlier, 1 same year, order not determinable
2309.16240 (2023-09)
Beyond Reverse KL: Generalizing Direct Preference Optimization with Diverse Divergence Constraints
2410.11623 (2024-10)
VidEgoThink: Assessing Egocentric Video Understanding Capabilities for Embodied AI
2025.findings-acl.979 (2025 (year only))
From Observation to Understanding: Front-Door Adjustments with Uncertainty Calibration for Enhancing Egocentric Reasoning in LVLMs
load_model_answers 3 other papers
2 dated earlier, 1 same year, order not determinable
2309.16240 (2023-09)
Beyond Reverse KL: Generalizing Direct Preference Optimization with Diverse Divergence Constraints
2410.11623 (2024-10)
VidEgoThink: Assessing Egocentric Video Understanding Capabilities for Embodied AI
2025.findings-acl.979 (2025 (year only))
From Observation to Understanding: Front-Door Adjustments with Uncertainty Calibration for Enhancing Egocentric Reasoning in LVLMs
load_questions 2 other papers
2 dated earlier
2309.16240 (2023-09)
Beyond Reverse KL: Generalizing Direct Preference Optimization with Diverse Divergence Constraints
2410.11623 (2024-10)
VidEgoThink: Assessing Egocentric Video Understanding Capabilities for Embodied AI
get_judge_name 1 other paper
1 dated earlier
2309.16240 (2023-09)
Beyond Reverse KL: Generalizing Direct Preference Optimization with Diverse Divergence Constraints
get_mt_bench_votes_data 1 other paper
1 dated earlier
2309.16240 (2023-09)
Beyond Reverse KL: Generalizing Direct Preference Optimization with Diverse Divergence Constraints
revert 1 other paper
1 dated earlier
2309.16240 (2023-09)
Beyond Reverse KL: Generalizing Direct Preference Optimization with Diverse Divergence Constraints

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-24.

Repositories linked to this paper

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

Abstract

LLMs demonstrate remarkable utility but remain vulnerable to jailbreak attacks that aim to elicit harmful responses. Existing defenses, including post-training alignment and prompt engineering, rely on training on safety-annotated datasets and safe prompt templates, struggling with adaptability to out-of-distribution (OOD) attacks. Steering internal representations of LLMs provides real-time adjustments to defend against OOD attacks. However, it struggles with maintaining model utility, since modifying the representation disrupts the forward pass of inference. It barely considers the competitive objectives of helpfulness and harmlessness in LLMs. We argue that adversarial game-based approaches promise a solution for conflicts between the two objectives. In this paper, we propose Adversarial Game Defense (AGD), an adversarial game-based defense method that dynamically adjusts LLMs' internal representations to achieve a balanced trade-off between helpfulness and harmlessness. AGD first proposes an interquartile range (IQR) method to detect abnormal attention weights and correct the abnormal weights via adversarial training. AGD adopts a bi-level optimization to play a two-player variable-sum game to approach Nash Equilibrium (NE), where the two players adversarially refine head activations for helpfulness and harmlessness respectively. Furthermore, AGD applies an expert model to nexttoken sampling to generate safer responses. Experiments show that AGD significantly improves LLMs' safety over all baselines.

For agents

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

get_harvested_code_for_paper("2025.acl-long.851")
get_code_for_paper("2025.acl-long.851")
have("2025.acl-long.851")

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

curl https://syntology.ai/api/ran/2025.acl-long.851.json

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

[![Syntology run record](https://syntology.ai/api/ran/2025.acl-long.851.svg)](https://syntology.ai/paper/2025.acl-long.851)

Connect an agent — have() is free.