GraphCanon updated 2w · GitHub synced 2w
Decision brief
PromptAttack is an LLM-targeted adversarial attack tool that leverages prompt engineering to generate adversarial samples keeping semantic intact but misclassifying outputs.
Good fit when
- For targeted analysis of adversarial robustness in specific language models.
- When needing a detailed understanding of how perturbations in input prompts affect model classification performance.
Avoid when
- If the focus is on general model improvement rather than adversarial testing.
- When working with proprietary or sensitive data that cannot be manipulated via external prompt tools, given potential data leakage concerns.
Observed Jul 17, 2026 · Source: enrich:decision_facts
Verify the decision
Maintenance and security
Full trust report- Maintenance
- Dormant (560d since push)
- As of 2w
- Provenance
- Not a fork · Personal account
- As of 2w
- Security (OSV)
- 241 low (241 low)
- As of 1mo
Public GitHub metadata and optional OSV scans. Signals, not a guarantee. Trust methodology.
Install
pip install PromptAttack PyPISimilar tools
Same-category neighbours. No typed graph edges are catalogued for this tool yet.
Evidence and technical details
Sourced facts, taxonomy, compatibility claims, README excerpt, and machine-readable endpoints.
Overview
This repository contains the source code for the ICLR 2024 paper that discusses a prompt-based adversarial attack on language models, allowing users to generate adversarial samples targeting various LLMs.
Capability facts
- Languages
- python
Source: github.language · Aug 5, 2026
Categories
Compatibility
Sourced claims from the README excerpt - not unsourced marketing copy.
Source: README excerpt (regex_v1, Aug 5, 2026)
pip install -r requirements.txtSource link
Source: README excerpt (regex_v1, Aug 5, 2026)
Logs of querying *ChatGPT*:Source link
Tags
README
An LLM can Fool Itself: A Prompt-Based Adversarial Attack
This is the source code for the ICLR 2024 paper "An LLM can Fool Itself: A Prompt-Based Adversarial Attack",
Xilie Xu* (NUS), Keyi Kong* (SDU), Ning Liu (SDU), Lizhen Cui (SDU), Di Wang (KAUST), Jingfeng Zhang (University of Auckland/RIKEN-AIP), Mohan Kankanhalli (NUS).
[PDF] [Project Page]
We provide a Colab Tutorial to help you quickly start to use our proposed PromptAttack!
Logs of querying ChatGPT:
- PromptAttack against GPT-3.5 (left panel);
- GPT3.5's prediction of the original sample (right upper panel);
- GPT3.5's prediction of the adversarial sample (right lower panel).
Logs of querying Gemini (Credit to Yash).
Environment
pip install -r requirements.txt
Let's Attack the LLM via PromptAttack
We generate adversarial samples by querying the LLM via an attack prompt. The attack prompt consists of three key components: original input (OI), attack objective (AO), and attack guidance (AG). We let $\mathcal{D}={(x_i,y_i)}_{i=1}^N$ be the original test dataset consisting of $N \in \mathbb{N}$ data points.
For each data point $(x,y)\in \mathcal{D}$, $x = { t^i, c^i}_{i=1}^n$ is the original sample where $n \in \mathbb{N}$ is the number of sentences, $t^i$ refers to the type of $i$-th sentence, and $c^i$ refers to the content of $i$-th sentence. For example, the original input in QQP and MNLI can have two types of sentences (i.e., $n=2$). We follow the types defined in their datasets, e.g., $t^1$ being question1 and $t^2$ being question2 for QQP, $t^1$ being premise and $t^2$ being hypothesis for MNLI.
Original input (OI)
The OI converts a data point composed of the original sample and ground-truth label sampled from a dataset into a sentence of an attack prompt. Given a data point $(x,y) \in \mathcal{D}$, we can formulate the OI as follows:
The original $t^1c^1$ and $t^2c^2$ and $\dots$ and $t^nc^n$ is classified as $y^k$.
Attack objective (AO)
The adversarial textual attack aims to generate an adversarial sample that should keep the same semantic meaning as its original version and can fool the LLM into doing incorrect classification. Here, we assume PromptAttack can perturb only one type of sentence for each data point. Therefore, given a data point $(x,y)\in \mathcal{D}$ and the type of the sentence that is targeted to be perturbed $t^a \in {t^1,\dots,t^n }$ where $a \in \mathbb{N}$, we formulate the AO as follows:
Your task is to generate a new $t^a$ which must satisfy the following conditions: <br> 1.Keeping the semantic meaning of the new $t^a$ unchanged; <br> 2.The new $t^a$ and the original $t^1$, $\dots$, $t^{a-1}$, $t^{a+1}$, $\dots$, $t^n$, should be classified as $y^1$ or $\dots$ or $y^{k-1}$ or $y^{k+1}$ or $\dots$ or $y^{C}$.
Attack guidance (AG)
AG contains the perturbation instruction to guide the LLM on how to perturb the original sample and specifies the format of the generated text. In the AG, we first ask the LLM to only perturb the type of the target sentence to finish the task. Then, we provide the perturbation instruction that guides the LLM on how to perturb the target sentence to generate the adversarial sample that fits the requirement of AO. Finally, we specify that the output of the LLM should only contain the newly generated sentence. Therefore, given a d
For agents
This page has a .md twin and JSON over the API.