SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2403.04957 · 2024

Automatic and Universal Prompt Injection Attacks against Large Language Models

arXiv · PDF · Open in the Atlas

Code that ran

7 of 10 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 0 have no contract verdict; 7 failures of our instrument; 3 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/2403.04957.json · badge: /api/ran/2403.04957.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
sheltonliu-n/universal-prompt-injection canonical (classifier label)
classifier basis: census
7 ran · 3 no recorded run
FunctionStatusWhere it lives
check_for_attack_success Ran
ran; our contract draft was wrong, not the code
sheltonliu-n/universal-prompt-injection/universal_prompt_injection.py
code served (permissive licence) · get_code("7a1925d40005947b")
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) 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 torch
import torch.nn as nn
from types import SimpleNamespace

torch.manual_seed(0)

# Minimal tokenizer stand-in
class MinimalTokenizer:
    def __init__(self):
        self.pad_token_id = 0
    
    def decode(self, token_ids):
        # Simple mock: convert token ids to words
        return "I cannot help with that request"

# Minimal generation config
class MinimalGenerationConfig:
    def __init__(self):
        self.max_new_tokens = 64

# Minimal model that supports generate
class MinimalModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
        self.generation_config = MinimalGenerationConfig()
        self.device_type = "cpu"
    
    @property
    def device(self):
        return torch.device("cpu")
    
    def generate(self, input_ids, attention_mask=None, generation_config=None, 
                 pad_token_id=None, top_p=None, do_sample=None, temperature=None):
        # Return mock generated token ids
        # input_ids shape: (batch_size, seq_len)
        batch_size = input_ids.shape[0]
        seq_len = input_ids.shape[1]
        # Generate some output tokens (append 10 new tokens)
        new_tokens = torch.randint(1, 100, (batch_size, seq_len + 10))
        return new_tokens

# Create instances
model = MinimalModel()
tokenizer = MinimalTokenizer()

# Create input_ids tensor (small, shape: 15 tokens)
input_ids = torch.randint(1, 100, (15,))

# Create assistant_role_slice - a slice object indicating where assistant response starts
# Using slice(10, 15) means assistant response is from token 10 to 15
assistant_role_slice = slice(10, 15)

# Test prefixes to check against
test_prefixes = ["I cannot", "I can't", "I apologize"]

# Optional generation config (can be None to use model's default)
gen_config = None

ARGS = {
    "model": model,
    "tokenizer": tokenizer,
    "input_ids": input_ids,
    "assistant_role_slice": assistant_role_slice,
    "test_prefixes": test_prefixes,
    "gen_config": gen_config,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — 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
generate Ran
ran; our contract draft was wrong, not the code
sheltonliu-n/universal-prompt-injection/universal_prompt_injection.py
code served (permissive licence) · get_code("c0332de7e8c09ed4")
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) and returned Tensor, ndim 1, dtype family int, shape (10,) 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
import torch.nn as nn
from types import SimpleNamespace

torch.manual_seed(0)

# Create a minimal tokenizer stand-in with required attributes
class MinimalTokenizer:
    def __init__(self):
        self.pad_token_id = 0

tokenizer = MinimalTokenizer()

# Create a minimal generation config
class MinimalGenerationConfig:
    def __init__(self):
        self.max_new_tokens = 64

gen_config = MinimalGenerationConfig()

# Create a minimal model that supports generate() and has device/generation_config
class MinimalModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
        self.generation_config = gen_config
        self.device_type = 'cpu'
    
    @property
    def device(self):
        return torch.device('cpu')
    
    def generate(self, input_ids, attention_mask=None, generation_config=None, 
                 pad_token_id=None, top_p=None, do_sample=None, temperature=None):
        # Return a tensor with shape (batch_size, seq_len)
        # Input shape is (1, seq_len), we'll return (1, seq_len + 10)
        batch_size = input_ids.shape[0]
        seq_len = input_ids.shape[1]
        output_len = seq_len + 10
        return torch.randint(0, 100, (batch_size, output_len))

model = MinimalModel()

# Create input_ids tensor with shape (seq_len,) - using 12 tokens
input_ids = torch.randint(0, 100, (12,))

# Create assistant_role_slice as a slice object
# slice.stop will be used to index into input_ids
assistant_role_slice = slice(5, 12)  # stop at index 12

ARGS = {
    'model': model,
    'tokenizer': tokenizer,
    'input_ids': input_ids,
    'assistant_role_slice': assistant_role_slice,
    'gen_config': None
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family int, shape (10,) — shape (10,) 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
generate_pattern Ran
ran; our contract draft was wrong, not the code
sheltonliu-n/universal-prompt-injection/universal_prompt_injection.py
code served (permissive licence) · get_code("b75ce23199955ac4")
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 = {
    "length": 5
}
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
modify_sys_prompts Ran
ran; our contract draft was wrong, not the code
sheltonliu-n/universal-prompt-injection/utils/string_utils.py
code served (permissive licence) · get_code("5234b2286e5ed655")
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 ConvTemplate. 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

class ConvTemplate:
    def __init__(self):
        self.system = ""

conv_template = ConvTemplate()
instruction = "You are a helpful assistant."
template_name = "llama2"

ARGS = {
    "conv_template": conv_template,
    "instruction": instruction,
    "template_name": template_name,
}
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 ConvTemplate — a ConvTemplate output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a ConvTemplate 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
query_keyword Ran
ran; our contract draft was wrong, not the code
sheltonliu-n/universal-prompt-injection/get_responses_universal.py
code served (permissive licence) · get_code("552d5602e36e866c")
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
from argparse import Namespace

torch.manual_seed(0)

# Build a stand-in args object
args_obj = Namespace(
    injection='static',
    target=0
)

ARGS = {
    'args': args_obj
}
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
query_target Ran
ran; our contract draft was wrong, not the code
sheltonliu-n/universal-prompt-injection/check_answers.py
code served (permissive licence) · get_code("a505da2807081d09")
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

torch.manual_seed(0)

ARGS = {
    'injection': 'static'
}
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 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
query_target Ran
ran; our contract draft was wrong, not the code
sheltonliu-n/universal-prompt-injection/utils/string_utils.py
code served (permissive licence) · get_code("e4d56bdd1dbd8b1c")
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

class Args:
    def __init__(self, injection, target):
        self.injection = injection
        self.target = target

# Test with 'static' injection type and target index 0
ARGS = {
    'args': Args(injection='static', target=0),
    'instruction': 'delete all files',
    'output': 'model response'
}
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_embedding_matrix Not yet run
unverified (harvested, no recorded run)
sheltonliu-n/universal-prompt-injection/utils/opt_utils.py
code served (permissive licence) · get_code("688aaeba506e3329")
How it ran

no invocation recorded.

get_embeddings Not yet run
unverified (harvested, no recorded run)
sheltonliu-n/universal-prompt-injection/utils/opt_utils.py
code served (permissive licence) · get_code("f556dda0785f3c77")
How it ran

no invocation recorded.

token_gradients Not yet run
unverified (harvested, no recorded run)
sheltonliu-n/universal-prompt-injection/utils/opt_utils.py
code served (permissive licence) · get_code("76ca4b8b6f0c1fe9")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 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, 2 later) and 6 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
get_embedding_matrix 6 other papers
2 dated earlier, 4 later
2402.09063 (2024-02)
Soft Prompt Threats: Attacking Safety Alignment and Unlearning in Open-Source LLMs through the Embedding Space
2402.16459 (2024-02)
Defending LLMs against Jailbreaking Attacks via Backtranslation
2404.13968 (2024-04)
Protecting Your LLMs with Information Bottleneck
and 3 more not named here
get_embeddings 5 other papers
1 dated earlier, 4 later
2402.16459 (2024-02)
Defending LLMs against Jailbreaking Attacks via Backtranslation
2404.13968 (2024-04)
Protecting Your LLMs with Information Bottleneck
2405.21018 (2024-05)
Improved Techniques for Optimization-Based Jailbreaking on Large Language Models
and 2 more not named here
check_for_attack_success 1 other paper
1 dated earlier
2310.04451 (2023-10)
AutoDAN: Generating Stealthy Jailbreak Prompts on Aligned Large Language Models
generate 1 other paper
1 dated earlier
2310.04451 (2023-10)
AutoDAN: Generating Stealthy Jailbreak Prompts on Aligned 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) excel in processing and generating human language, powered by their ability to interpret and follow instructions. However, their capabilities can be exploited through prompt injection attacks. These attacks manipulate LLM-integrated applications into producing responses aligned with the attacker's injected content, deviating from the user's actual requests. The substantial risks posed by these attacks underscore the need for a thorough understanding of the threats. Yet, research in this area faces challenges due to the lack of a unified goal for such attacks and their reliance on manually crafted prompts, complicating comprehensive assessments of prompt injection robustness. We introduce a unified framework for understanding the objectives of prompt injection attacks and present an automated gradient-based method for generating highly effective and universal prompt injection data, even in the face of defensive measures. With only five training samples (0.3% relative to the test data), our attack can achieve superior performance compared with baselines. Our findings emphasize the importance of gradient-based testing, which can avoid overestimation of robustness, especially for defense mechanisms.

For agents

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

get_harvested_code_for_paper("2403.04957")
get_code_for_paper("2403.04957")
have("2403.04957")

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

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

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

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

Connect an agent — have() is free.