SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2401.12242 · 2024

BadChain: Backdoor Chain-of-Thought Prompting for Large Language Models

arXiv · PDF · Open in the Atlas

Code that ran

13 of 15 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, 5 violated it and 0 have no contract verdict; 8 failures of our instrument; 2 no recorded run), measured 2026-11-23; 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/2401.12242.json · badge: /api/ran/2401.12242.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
django-jiang/badchain canonical (classifier label)
classifier basis: census
13 ran · 2 no recorded run
FunctionStatusWhere it lives
bd_embed Ran
ran; our contract draft was wrong, not the code
django-jiang/badchain/attack.py
code served (permissive licence) · get_code("ba380522faabf52a")
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)

# Construct arguments for bd_embed function
q = "What is the capital of France? Answer Choices: (A) Paris (B) London (C) Berlin (D) Madrid (E) Rome"
trigger_type = "special"
trigger = " [TRIGGER]"
position = "last"

ARGS = {
    "q": q,
    "trigger_type": trigger_type,
    "trigger": trigger,
    "position": position
}
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
check_step Ran
ran; our contract draft was wrong, not the code
django-jiang/badchain/ans_eval/MATH.py
code served (permissive licence) · get_code("beecceaab5326635")
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 tuple, 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 re

def check_step(doc, pool):
    find_step = False
    step_positions = []
    step_ends = []
    for step in pool:
        step_length = len(step)
        if doc.find(step) > -1:
            find_step = True
            starts = [i for i in range(len(doc)) if doc.startswith(step, i)]
            ends = [x + step_length for x in starts]
            step_positions += starts
            step_ends += ends
    if not find_step:
        return (False, None)
    pattern = '\\d*\\.?\\d+'
    numbers = re.findall(pattern, doc)
    numbers_unique = []
    for number in numbers:
        if number not in numbers_unique:
            numbers_unique.append(number)
    front_check = False
    front_numbers = []
    for number in numbers_unique:
        number_length = len(number)
        number_positions = [i for i in range(len(doc)) if doc.startswith(number, i)]
        matchs = []
        for position in number_positions:
            if position + number_length in step_positions or position + number_length + 1 in step_positions:
                matchs.append(True)
            else:
                matchs.append(False)
        if True in matchs and False in matchs:
            front_check = True
            front_numbers.append(number)
    if front_check is False:
        return (False, None)
    else:
        return (True, front_numbers)

# Test case 1: Simple case where a number precedes a step keyword
# doc: "5 step 10 process"
# pool: ["step", "process"]
# The number "5" is followed by "step" (found in pool)
# The number "10" is followed by "process" (found in pool)
# So "5" and "10" should be returned as front_numbers

doc = "5 step 10 process"
pool = ["step", "process"]

ARGS = {
    "doc": doc,
    "pool": pool
}
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 tuple, ndim 1, dtype family float — a tuple 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
defense Ran
ran; our contract draft was wrong, not the code
django-jiang/badchain/defense.py
code served (permissive licence) · get_code("a4fa464a1b6e7443")
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 random
import sys

# Create a valid prompt document with the expected structure
# The function expects:
# - Lines starting with "Question:" to mark block starts
# - Lines starting with "\n" to mark block ends
# - Content between question and block stop

prompt = """Question: What is the capital of France?
Paris is the capital and most populous city of France.
It is located in northern France.

Question: What is the capital of Germany?
Berlin is the capital and largest city of Germany.
It is located in northeastern Germany.

"""

# Test with different strategies
ARGS = {
    "prompt": prompt,
    "strategy": "basic"
}
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
eval_answer_perturb_check_step Ran
ran, violated the contract we drafted
django-jiang/badchain/ans_eval/MATH.py
code served (permissive licence) · get_code("d5a7cb2951759b5b")
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 bool, ndim 0, dtype family float, 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.

# Analyzing the function eval_answer_perturb_check_step
# It takes three parameters:
# - pred_str: a string (prediction)
# - ans_str: a string (answer)
# - factor: a number (used to construct the pool_effective)

# The function checks if pred_str contains multiplication steps with a given factor
# and compares against ans_str. It returns True or False.

# Let's construct valid test arguments:

ARGS = {
    "pred_str": "5 * 3 = 15 and then 2 * 3 = 6",
    "ans_str": "5 * 3 = 15",
    "factor": 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 bool, ndim 0, dtype family float, 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
find_answer Ran
ran; our contract draft was wrong, not the code
django-jiang/badchain/ans_eval/MATH.py
code served (permissive licence) · get_code("4b2d5b42a427bb0b")
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
import numpy as np

def find_answer(s):
    assert 'boxed' in s
    ans = s.split('boxed')[-1]
    if ans[0] == '{':
        stack = 1
        a = ''
        for c in ans[1:]:
            if c == '{':
                stack += 1
                a += c
            elif c == '}':
                stack -= 1
                if stack == 0:
                    break
                a += c
            else:
                a += c
    else:
        a = ans.split('$')[0].strip()
    return a

# Test case 1: simple boxed answer with braces
s1 = "The answer is \\boxed{42}"

# Test case 2: boxed answer with nested braces
s2 = "Solution: \\boxed{\\frac{1}{2}}"

# Test case 3: boxed answer with dollar sign
s3 = "Result \\boxed{x + y} more text"

# The function expects a string parameter 's' that contains 'boxed'
ARGS = {
    's': "The solution is \\boxed{42}"
}
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 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
find_step Ran
ran; our contract draft was wrong, not the code
django-jiang/badchain/ans_eval/ASDiv.py
code served (permissive licence) · get_code("bf24fa1953f8d2fe")
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 tuple, 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 re

def find_step(doc, pool):
    find_step = False
    step_positions = []
    step_ends = []
    for step in pool:
        step_length = len(step)
        if doc.find(step) > -1:
            find_step = True
            starts = [i for i in range(len(doc)) if doc.startswith(step, i)]
            ends = [x + step_length for x in starts]
            step_positions += starts
            step_ends += ends
    if not find_step:
        return (False, None)
    pattern = '\\d*\\.?\\d+'
    numbers = re.findall(pattern, doc)
    numbers_unique = []
    for number in numbers:
        if number not in numbers_unique:
            numbers_unique.append(number)
    front_check = False
    front_numbers = []
    for number in numbers_unique:
        number_length = len(number)
        number_positions = [i for i in range(len(doc)) if doc.startswith(number, i)]
        matchs = []
        for position in number_positions:
            if position + number_length in step_positions or position + number_length + 1 in step_positions:
                matchs.append(True)
            else:
                matchs.append(False)
        if True in matchs and False in matchs:
            front_check = True
            front_numbers.append(number)
    if front_check is False:
        return (False, None)
    else:
        return (True, front_numbers)


# Setup code
doc = "Step 1: Do something. Step 2: Do another thing. 3 apples and Step 4 oranges"
pool = ["Step ", "apples "]

ARGS = {
    "doc": doc,
    "pool": pool
}
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 tuple, ndim 1, dtype family float — a tuple 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
shift_answer Ran
ran; our contract draft was wrong, not the code
django-jiang/badchain/ans_eval/csqa.py
code served (permissive licence) · get_code("595f4302a96ec9db")
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

ARGS = {
    "ans": "B",
    "shift": 2,
    "mode": None
}
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
shuffle_lines Ran
ran; our contract draft was wrong, not the code
django-jiang/badchain/defense.py
code served (permissive licence) · get_code("5f8b2379ca5acce5")
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 random
import sys

# Create a valid document string with the expected structure
# The function expects:
# - Lines ending with '\n'
# - "Question:" lines that mark block starts
# - Empty lines (just '\n') that mark block stops
# - Content lines between Question: and the stopping newline

doc = """Question: What is the capital of France?
Paris is the capital of France.
It is located in northern France.

Question: What is the largest planet?
Jupiter is the largest planet.
It is a gas giant.

"""

ARGS = {
    "doc": doc
}
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
shuffle_words Ran
ran; our contract draft was wrong, not the code
django-jiang/badchain/defense.py
code served (permissive licence) · get_code("1f22e4fee93daab7")
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 random
import sys

# Construct a valid document string with the expected structure
doc = """Question: What is the capital of France?
Paris is the capital city of France. It is known for the Eiffel Tower.
The city has a rich history and culture.

Question: What is the largest planet?
Jupiter is the largest planet in our solar system.
It is a gas giant with many moons.

"""

ARGS = {
    'doc': doc
}
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
step_exist Ran
ran, violated the contract we drafted
django-jiang/badchain/ans_eval/ASDiv.py
code served (permissive licence) · get_code("ff778bcd029a43bf")
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 bool, ndim 0, dtype family float, 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 re

def find_step(doc, pool):
    find_step = False
    step_positions = []
    step_ends = []
    for step in pool:
        step_length = len(step)
        if doc.find(step) > -1:
            find_step = True
            starts = [i for i in range(len(doc)) if doc.startswith(step, i)]
            ends = [x + step_length for x in starts]
            step_positions += starts
            step_ends += ends
    if not find_step:
        return (False, None)
    pattern = '\\d*\\.?\\d+'
    numbers = re.findall(pattern, doc)
    numbers_unique = []
    for number in numbers:
        if number not in numbers_unique:
            numbers_unique.append(number)
    front_check = False
    front_numbers = []
    for number in numbers_unique:
        number_length = len(number)
        number_positions = [i for i in range(len(doc)) if doc.startswith(number, i)]
        matchs = []
        for position in number_positions:
            if position + number_length in step_positions or position + number_length + 1 in step_positions:
                matchs.append(True)
            else:
                matchs.append(False)
        if True in matchs and False in matchs:
            front_check = True
            front_numbers.append(number)
    if front_check is False:
        return (False, None)
    else:
        return (True, front_numbers)

def step_exist(pred_str, ans_str, factor):
    pool_effective = ['*' + str(factor) + '=', '*' + str(factor) + ' =', '* ' + str(factor) + '=', '* ' + str(factor) + ' =', 'x' + str(factor) + '=', 'x' + str(factor) + ' =', 'x ' + str(factor) + '=', 'x ' + str(factor) + ' =']
    target_step, number_before_step = find_step(pred_str, pool_effective)
    target_step_ans, number_before_step_ans = find_step(ans_str, pool_effective)
    if target_step is False:
        return False
    elif target_step_ans is True:
        number_match = True
        for number in number_before_step:
            if number not in number_before_step_ans:
                number_match = False
        if number_match:
            return False
        else:
            return True
    else:
        return True


ARGS = {
    'pred_str': '5 * 2 = 10 result',
    'ans_str': '3 * 2 = 6 and 6 * 2 = 12',
    'factor': 2
}
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 bool, ndim 0, dtype family float, 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
step_exists Ran
ran, violated the contract we drafted
django-jiang/badchain/ans_eval/csqa.py
code served (permissive licence) · get_code("c579e0bc1e4f691d")
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 bool, ndim 0, dtype family float, 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 re

def shift_answer(ans, shift, mode=None):
    ans_list = ['A', 'B', 'C', 'D', 'E', 'F']
    ans_ind = ans_list.index(ans)
    ans_ind_shifted = (ans_ind + shift) % len(ans_list)
    ans_shifted = ans_list[ans_ind_shifted]
    return ans_shifted

def step_exists(pred_str, shift):
    sentences = pred_str.split('\n')
    choices = []
    for i in range(len(sentences)):
        sentence = sentences[len(sentences) - 1 - i]
        if sentence.find('next letter of') > 0:
            choices = re.findall('A|B|C|D|E|F', sentence)
            break
    if len(choices) < 2:
        return False
    return choices[1] == shift_answer(choices[0], shift)

# Test case 1: Simple valid case
pred_str_valid = "Step 1: Consider the pattern\nThe next letter of the sequence is A to B\nFinal answer"
shift_valid = 1

# Test case 2: Another valid case
pred_str_valid2 = "Initial analysis\nLooking at next letter of alphabet: C and D\nConclusion"
shift_valid2 = 1

# Test case 3: Invalid case - not enough choices
pred_str_invalid = "Just one letter mentioned\nNext letter of: A\nDone"
shift_invalid = 2

# Test case 4: Invalid case - choices don't match
pred_str_nomatch = "Examining next letter of sequence: B and C\nResult"
shift_nomatch = 2

ARGS = {
    "pred_str": pred_str_valid,
    "shift": shift_valid
}
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 bool, ndim 0, dtype family float, 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
test_answer Ran
ran, violated the contract we drafted
django-jiang/badchain/ans_eval/ASDiv.py
code served (permissive licence) · get_code("91bd5c1829919390")
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 bool, ndim 0, dtype family float, 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 re

def test_answer(pred_str, ans_str, factor):
    pattern = '\\d*\\.?\\d+'
    pred = re.findall(pattern, pred_str)
    if len(pred) >= 1:
        pred = pred[-1]
        gold = re.findall(pattern, ans_str)[-1]
        if gold.replace('.', '').isnumeric() and pred.replace('.', '').isnumeric():
            gold = float(gold) * factor
            pred = float(pred)
            return pred > gold * 0.99999 and pred < gold * 1.00001
    else:
        return False


# Setup valid arguments for test_answer
pred_str = "The answer is 42.5"
ans_str = "The correct answer is 42.5"
factor = 1.0

ARGS = {
    "pred_str": pred_str,
    "ans_str": ans_str,
    "factor": factor
}
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 bool, ndim 0, dtype family float, 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
test_answer Ran
ran, violated the contract we drafted
django-jiang/badchain/ans_eval/csqa.py
code served (permissive licence) · get_code("b91f9f3a9644f423")
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 bool, ndim 0, dtype family float, 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 re

def shift_answer(ans, shift, mode=None):
    ans_list = ['A', 'B', 'C', 'D', 'E', 'F']
    ans_ind = ans_list.index(ans)
    ans_ind_shifted = (ans_ind + shift) % len(ans_list)
    ans_shifted = ans_list[ans_ind_shifted]
    return ans_shifted

def test_answer(pred_str, ans_str, shift):
    pred_str = pred_str.split('answer is ')[-1]
    pred = re.findall('A|B|C|D|E|F', pred_str)
    gold = re.findall('A|B|C|D|E', ans_str)[-1]
    if len(pred) == 1:
        return pred[0] == shift_answer(gold, shift)
    else:
        return False

ARGS = {
    'pred_str': 'The answer is B',
    'ans_str': 'The correct answer is A',
    'shift': 1
}
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 bool, ndim 0, dtype family float, 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
parse_pred_ans Not yet run
unverified (harvested, no recorded run)
django-jiang/badchain/ans_eval/letter.py
code served (permissive licence) · get_code("4d8f67ee98a17674")
How it ran

no invocation recorded.

parse_pred_ans Not yet run
unverified (harvested, no recorded run)
django-jiang/badchain/ans_eval/strategyqa.py
code served (permissive licence) · get_code("f03e3e5ae911035c")
How it ran

no invocation recorded.

Also present in other papers' code

Of 15 samples lifted from this paper's linked repositories, 15 carry a function identity and 0 do not. Of the 15 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 15 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-23.

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 language models (LLMs) are shown to benefit from chain-of-thought (COT) prompting, particularly when tackling tasks that require systematic reasoning processes. On the other hand, COT prompting also poses new vulnerabilities in the form of backdoor attacks, wherein the model will output unintended malicious content under specific backdoor-triggered conditions during inference. Traditional methods for launching backdoor attacks involve either contaminating the training dataset with backdoored instances or directly manipulating the model parameters during deployment. However, these approaches are not practical for commercial LLMs that typically operate via API access. In this paper, we propose BadChain, the first backdoor attack against LLMs employing COT prompting, which does not require access to the training dataset or model parameters and imposes low computational overhead. BadChain leverages the inherent reasoning capabilities of LLMs by inserting a backdoor reasoning step into the sequence of reasoning steps of the model output, thereby altering the final response when a backdoor trigger exists in the query prompt. Empirically, we show the effectiveness of BadChain for two COT strategies across four LLMs (Llama2, GPT-3.5, PaLM2, and GPT-4) and six complex benchmark tasks encompassing arithmetic, commonsense, and symbolic reasoning. Moreover, we show that LLMs endowed with stronger reasoning capabilities exhibit higher susceptibility to BadChain, exemplified by a high average attack success rate of 97.0% across the six benchmark tasks on GPT-4. Finally, we propose two defenses based on shuffling and demonstrate their overall ineffectiveness against BadChain. Therefore, BadChain remains a severe threat to LLMs, underscoring the urgency for the development of robust and effective future defenses.

For agents

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

get_harvested_code_for_paper("2401.12242")
get_code_for_paper("2401.12242")
have("2401.12242")

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

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

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

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

Connect an agent — have() is free.