SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2306.06815 · NeurIPS · 2023

TrojLLM: A Black-box Trojan Prompt Attack on Large Language Models

Yilin Shen, Ladislau Bölöni, Ting Hua, Qian Lou, Yepeng Liu, Jiaqi Xue, Mengxin Zheng

arXiv · PDF · Open in the Atlas

Code that ran

4 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 3 have no contract verdict; 1 failure 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/2306.06815.json · badge: /api/ran/2306.06815.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
UCF-ML-Research/TrojLLM canonical (classifier label)
classifier basis: census
4 ran · 2 no recorded run
FunctionStatusWhere it lives
gather_2d_on_last_dim Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
UCF-ML-Research/TrojLLM/ProgressiveTuning/rlprompt/losses/loss_utils.py
pointer only (licence: MIT); the stored copy get_code serves, from UCF-ML-Research/CR-UTP, is pointer only (licence: NONE) · get_code("b812784740a81e0d")
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 UCF-ML-Research/CR-UTP, 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.

get_dataset_verbalizers Ran
ran on a synthesized input
UCF-ML-Research/TrojLLM/ProgressiveTuning/few-shot-classification/fsc_helpers.py
code served (permissive licence) · get_code("0305c3488d11bace")
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.

# SETUP CODE

def get_dataset_verbalizers(dataset: str):
    if dataset in ['sst-2', 'yelp-2', 'mr', 'cr']:
        verbalizers = ['Ġterrible', 'Ġgreat']
    elif dataset == 'agnews':
        verbalizers = ['World', 'Sports', 'Business', 'Tech']
    elif dataset in ['sst-5', 'yelp-5']:
        verbalizers = ['Ġterrible', 'Ġbad', 'Ġokay', 'Ġgood', 'Ġgreat']
    elif dataset == 'subj':
        verbalizers = ['Ġsubjective', 'Ġobjective']
    elif dataset == 'trec':
        verbalizers = ['ĠDescription', 'ĠEntity', 'ĠExpression', 'ĠHuman', 'ĠLocation', 'ĠNumber']
    elif dataset == 'yahoo':
        verbalizers = ['culture', 'science', 'health', 'education', 'computer', 'sports', 'business', 'music', 'family', 'politics']
    elif dataset == 'dbpedia':
        verbalizers = ['ĠCompany', 'ĠEducation', 'ĠArtist', 'ĠSports', 'ĠOffice', 'ĠTransportation', 'ĠBuilding', 'ĠNatural', 'ĠVillage', 'ĠAnimal', 'ĠPlant', 'ĠAlbum', 'ĠFilm', 'ĠWritten']
    return verbalizers


# Test with a valid dataset string
ARGS = {
    'dataset': 'sst-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 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_few_shot_classification_dataset Ran
ran on a synthesized input
UCF-ML-Research/TrojLLM/ProgressiveTuning/few-shot-classification/fsc_helpers.py
code served (permissive licence) · get_code("54640fbc2c5ec15d")
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. 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 pandas as pd
import os
import tempfile
from pathlib import Path

# Create a temporary directory structure to hold test data
temp_dir = tempfile.mkdtemp()
base_path = temp_dir

# Create the directory structure
dataset_dir = os.path.join(base_path, '16-shot', 'agnews', '16-100')
os.makedirs(dataset_dir, exist_ok=True)

# Create a sample TSV file for the test split
test_filepath = os.path.join(dataset_dir, 'test.tsv')
df = pd.DataFrame({
    'sentence': ['This is a test sentence about world news', 'Another sports related headline here'],
    'label': [0, 1]
})
df.to_csv(test_filepath, sep='\t', index=False)

# Create dev split as well
dev_filepath = os.path.join(dataset_dir, 'dev.tsv')
df_dev = pd.DataFrame({
    'sentence': ['Dev sentence one', 'Dev sentence two'],
    'label': [0, 1]
})
df_dev.to_csv(dev_filepath, sep='\t', index=False)

# Create train split as well
train_filepath = os.path.join(dataset_dir, 'train.tsv')
df_train = pd.DataFrame({
    'sentence': ['Train sentence one', 'Train sentence two'],
    'label': [0, 1]
})
df_train.to_csv(train_filepath, sep='\t', index=False)

ARGS = {
    'dataset': 'agnews',
    'dataset_seed': 0,
    'split': 'test',
    'base_path': base_path,
    'num_shots': 16,
    'task_lm': 'bert-base-uncased'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
pandas — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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
make_few_shot_classification_dataset Ran
ran on a synthesized input
UCF-ML-Research/TrojLLM/ProgressiveTuning/few-shot-classification/fsc_helpers.py
code served (permissive licence) · get_code("fb1fd6eb3d8e6923")
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. 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 tempfile
import pandas as pd
from omegaconf import DictConfig

# Create a temporary directory for test data
temp_dir = tempfile.mkdtemp()

# Create minimal test TSV files for each split and dataset
def create_test_data(base_path, dataset, seed_path, split):
    """Create a minimal TSV file for testing"""
    dir_path = os.path.join(base_path, f'16-shot/{dataset}/{seed_path}')
    os.makedirs(dir_path, exist_ok=True)
    
    filepath = os.path.join(dir_path, f'{split}.tsv')
    
    # Create sample data with text and label columns
    data = {
        'text': ['sample text one', 'sample text two', 'sample text three'],
        'label': [0, 1, 0]
    }
    df = pd.DataFrame(data)
    df.to_csv(filepath, sep='\t', index=False)

# Set up test data files
base_path = temp_dir
dataset = 'agnews'
dataset_seed = 0
seed_dict = {0: '16-100', 1: '16-13', 2: '16-21', 3: '16-42', 4: '16-87', 5: '16-t'}
seed_path = seed_dict[dataset_seed]

# Create test files for all splits
for split in ['train', 'dev', 'test']:
    create_test_data(base_path, dataset, seed_path, split)

# Create a minimal DictConfig object
config = DictConfig({
    'dataset': 'agnews',
    'dataset_seed': 0,
    'base_path': base_path,
    'num_shots': 16,
    'task_lm': 'bert-base-uncased'
})

ARGS = {
    'config': config
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
omegaconf, pandas, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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_masked_mean_min_max Not yet run
unverified (harvested, no recorded run)
UCF-ML-Research/TrojLLM/ProgressiveTuning/rlprompt/losses/loss_utils.py
pointer only (licence: MIT); the stored copy get_code serves, from UCF-ML-Research/CR-UTP, is pointer only (licence: NONE) · get_code("4d8f96f19e31bf03")
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 UCF-ML-Research/CR-UTP, 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. No invocation recorded.

masked_reverse_cumsum Not yet run
unverified (harvested, no recorded run)
UCF-ML-Research/TrojLLM/ProgressiveTuning/rlprompt/losses/loss_utils.py
pointer only (licence: MIT); the stored copy get_code serves, from UCF-ML-Research/CR-UTP, is pointer only (licence: NONE) · get_code("7e5f5859a590dce8")
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 UCF-ML-Research/CR-UTP, 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. 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, 3 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 3 later) and 3 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
gather_2d_on_last_dim 1 other paper
1 later
2406.01873 (2024-06)
CR-UTP: Certified Robustness against Universal Text Perturbations on Large Language Models
get_masked_mean_min_max 1 other paper
1 later
2406.01873 (2024-06)
CR-UTP: Certified Robustness against Universal Text Perturbations on Large Language Models
masked_reverse_cumsum 1 other paper
1 later
2406.01873 (2024-06)
CR-UTP: Certified Robustness against Universal Text Perturbations on Large Language Models

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 progressively being utilized as machine learning services and interface tools for various applications. However, the security implications of LLMs, particularly in relation to adversarial and Trojan attacks, remain insufficiently examined. In this paper, we propose TrojLLM, an automatic and black-box framework to effectively generate universal and stealthy triggers. When these triggers are incorporated into the input data, the LLMs' outputs can be maliciously manipulated. Moreover, the framework also supports embedding Trojans within discrete prompts, enhancing the overall effectiveness and precision of the triggers' attacks. Specifically, we propose a trigger discovery algorithm for generating universal triggers for various inputs by querying victim LLMbased APIs using few-shot data samples. Furthermore, we introduce a novel progressive Trojan poisoning algorithm designed to generate poisoned prompts that retain efficacy and transferability across a diverse range of models. Our experiments and results demonstrate TrojLLM's capacity to effectively insert Trojans into text prompts in real-world black-box LLM APIs including GPT-3.5 and GPT-4, while maintaining exceptional performance on clean test sets. Our work sheds light on the potential security risks in current models and offers a potential defensive approach. The source code of TrojLLM is available at https://github.com/UCF-ML-Research/TrojLLM. Attaining high-performance prompts typically demands considerable domain expertise and extensive validation sets; concurrently, manually crafted prompts have been identified as sub-optimal, leading to inconsistent performance [8,9]. Consequently, the automatic search and generation of prompts have garnered significant research interest [4,10]. One prevalent approach involves tuning soft prompts (i.e., continuous embedding vectors) as they can readily accommodate gradient descent [5,11]. 37th Conference on Neural Information Processing Systems (NeurIPS 2023).

For agents

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

get_harvested_code_for_paper("2306.06815")
get_code_for_paper("2306.06815")
have("2306.06815")

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

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

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

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

Connect an agent — have() is free.