Universal and Transferable Adversarial Attacks on Aligned Language Models
Zou et al. show that an automated, gradient-guided search over tokens (Greedy Coordinate Gradient, or GCG) can find a short adversarial suffix that makes open-weight aligned models comply with harmful requests. Suffixes optimized across several prompts and several open models also transferred, with varying success, to closed models behind APIs, showing that jailbreaks can be produced by optimization rather than by hand.
Ready to ace your system design interview?
This article is just one piece. StackSweep gives you structured, interview-focused practice across every topic that comes up in senior engineering rounds.
- 1,000+ quiz questions across system design and ML/AI
- Spaced repetition to lock in what you learn
- Full case study walkthroughs of real interview topics
- Track streaks, XP, and progress over time
TL;DR
- Before this paper, most jailbreaks were hand-written. GCG finds attacks automatically by optimizing a string of tokens appended to a request.
- The objective is simple: make the model's response start with an affirmative phrase, on the theory that once it begins complying it tends to continue.
- GCG uses gradients with respect to one-hot token choices to propose promising swaps, then evaluates a batch of real swaps and keeps the best, because tokens are discrete.
- Optimizing one suffix across many requests and several open models made it universal and transferable: the authors report it carried over to closed models such as GPT-3.5, GPT-4, PaLM-2 and Claude 1 to varying degrees, with almost no transfer to Claude 2.
- The suffixes look like gibberish, which makes perplexity filters a natural first defense, but later work produced fluent optimized attacks that evade them.
Why this paper matters
GCG is the standard white-box attack on language models and the baseline most robustness papers and benchmarks compare against. Research engineers should understand the optimization, why it transfers, how success was measured, and which defenses it motivated, without needing any specific attack strings.
Breakdown
1.From hand-written jailbreaks to optimization
Jailbreaks before mid 2023 were mostly found by people: creative prompts that exploited role-play, formatting or instruction conflicts. These are labor-intensive, easy to patch individually, and hard to study systematically.
Adversarial examples in computer vision had a different history. There, attacks are found by optimization: compute the gradient of a loss with respect to the input pixels and nudge them to cause a misclassification. That approach made it clear that vision models are not robust to small, targeted changes.
Zou et al. ask whether the same is true for aligned language models. The challenge is that text is discrete. You cannot nudge a token by a small amount; you can only replace it with another token. Earlier work such as AutoPrompt had searched over tokens with gradient guidance for other purposes, and other attacks had been tried on aligned models with limited success.
The paper's contribution is an attack that works reliably on open aligned models, combined with an objective and a multi-prompt, multi-model training setup that makes the attack universal and transferable.
Discussion angle: Expect "why is attacking text harder than attacking images?" Answer: the input space is discrete, so gradients only give a local linear estimate of which token swaps might help, and every candidate must be checked with a real forward pass. Also, small changes to an image are imperceptible; token changes are visible, so "small perturbation" means something different.
2.The objective: target an affirmative start
To optimize anything, you need a loss. What should the attack maximize?
The authors choose a simple target: the probability that the model's response begins with an affirmative phrase that restates the request, along the lines of agreeing to help. The adversarial suffix is a fixed number of tokens appended to the user's request. The loss is the negative log-probability of the target opening given the request plus suffix.
Why target just the beginning? Because of how autoregressive generation works. If the model's first tokens commit to answering, the most likely continuation is the answer itself. Refusals in safety training typically happen at the start of a response, so getting past the first few tokens gets past most of the learned refusal behavior. This is the same insight behind prefix injection in the work of Wei et al., now turned into an optimization target.
This objective is a proxy. A model can start with the affirmative phrase and then refuse anyway, or produce a vague, unhelpful answer. Success measurement therefore matters a lot, and later work showed that how you judge success can change reported numbers substantially.
Discussion angle: A strong question: "what are the failure modes of optimizing only the first few tokens?" The model can recover and refuse mid-response, or comply in a useless way. That suggests both a stronger attack objective and a defense: train models to refuse even after starting to comply, which later work on deeper safety alignment and circuit breakers explored.
3.Greedy Coordinate Gradient
GCG searches over suffix tokens one step at a time. Each step works like this.
First, represent each suffix position as a one-hot vector over the vocabulary. Compute the gradient of the loss with respect to these one-hot vectors. For each position, the gradient gives a linear estimate of how much each possible replacement token would reduce the loss. Take the top few candidate tokens per position.
Second, build a batch of candidate suffixes, each differing from the current one by a single token swap at a randomly chosen position, using those top candidates.
Third, run real forward passes on every candidate and keep the one with the lowest actual loss.
The gradient is only a rough guide, because the loss is not linear in discrete token swaps. That is why GCG evaluates many candidates exactly rather than trusting the gradient. Compared with AutoPrompt, which considered swaps at one position at a time, GCG considers all positions in each step, which the authors found much more effective.
The method needs white-box access: the gradient requires the model's weights. That is why the transfer results matter.
Discussion angle: Interviewers probe the cost: each step needs a backward pass plus a batch of forward passes, repeated for hundreds of steps. Ask how you would make it cheaper (smaller candidate batches, caching the shared prompt prefix) and what the attacker gains from black-box methods that skip gradients altogether, such as query-based search or attacker LLMs.
4.Universality and transfer
An attack that works for one request on one model is a curiosity. The paper goes further in two ways.
Universal: instead of optimizing for a single harmful request, the authors optimize one suffix to minimize the summed loss across many requests, adding requests gradually as earlier ones succeed. The result is a single suffix that works across many different requests.
Transferable: they also optimize across several open models at once (Vicuna-7B and 13B, and in one run Guanaco-7B and 13B as well). The resulting suffixes were then tested on models the attacker had no gradient access to. The authors report meaningful transfer to GPT-3.5, GPT-4 and PaLM-2, transfer to Claude 1 that reached a level similar to GPT-4 only with their strongest combined suffixes, and almost none to Claude 2. The authors note that the newer models (GPT-4, Claude 2) were attacked successfully less often, but caution that this may partly reflect the distillation point below.
Why would transfer happen? The authors point to one plausible reason themselves: Vicuna was fine-tuned on conversations with ChatGPT, so it may share some of ChatGPT's behavior, and suffixes that exploit Vicuna may exploit that shared behavior. More broadly, models trained on similar data with similar safety methods may share vulnerabilities, just as adversarial examples transfer across image classifiers.
Transfer is what turned the paper from a white-box result into a practical concern for closed models.
Discussion angle: Ask for alternative explanations of transfer and how to test them. Distillation hypothesis: compare transfer from source models trained on ChatGPT outputs with transfer from source models that were not. Shared-data hypothesis: test across model families with known data differences. Also ask whether transfer was measured with the same success criterion for every target.
5.Measuring success and the defenses that followed
The authors introduced AdvBench, a set of harmful strings and harmful behaviors. For behaviors, the paper counts a test case as successful if the model makes a "reasonable attempt" at the behavior rather than refusing, which it notes may involve human judgment. In practice, the automated check in the released code, widely reused in follow-up work, counts a response as a success if it does not contain any of a list of typical refusal phrases. That criterion is cheap but loose: a response can avoid those phrases and still be unhelpful, off-topic or a disguised refusal. Later benchmarks, such as HarmBench, used trained classifiers instead and argued that refusal-string matching can overstate attack success.
On defenses, the paper prompted several lines of work. Because GCG suffixes are usually high-perplexity gibberish, perplexity filters can flag them; Jain et al. evaluated this and other baseline defenses. Attackers then produced fluent, low-perplexity adversarial prompts that slip past such filters. SmoothLLM perturbs inputs randomly and aggregates responses, relying on the observation that optimized suffixes are brittle to character changes. Adversarial training and representation-level methods such as circuit breakers aim at robustness that does not depend on spotting a particular attack.
The broad lesson mirrors computer vision: aligned language models are not adversarially robust, and making them so is an open research problem rather than a patch.
Discussion angle: A good discussion: "a perplexity filter blocks GCG; is the problem solved?" No: it blocks one attack distribution, and an adaptive attacker can add a fluency term to the objective. Robustness claims should always be evaluated against attackers who know the defense. Ask what a defense's false-positive rate is on legitimate unusual inputs like code or non-English text.
Reading the evidence
What it shows
- Automated, gradient-guided token search reliably finds suffixes that make open aligned models comply with harmful requests in the authors' benchmark.
- A single suffix optimized across many requests works on requests it was not optimized for.
- Suffixes optimized across several open models transfer, with varying success, to closed models including GPT-3.5, GPT-4, PaLM-2 and Claude 1, with almost no transfer to Claude 2.
- Aligned language models are not adversarially robust, echoing the earlier lesson from computer vision.
What it does not show
- That the outputs counted as successful were genuinely harmful or useful; success meant a non-refusing attempt (checked automatically by the absence of refusal phrases), which later work argued can overstate it.
- Why transfer happens; the authors suggest distillation from ChatGPT as one possible factor but do not isolate it.
- That the specific suffixes still work on current models, which have since been updated.
- That simple defenses like perplexity filtering solve the problem against an adaptive attacker.
The most boring explanation
A deflationary reading of the transfer result is that much of it comes from Vicuna being trained on ChatGPT outputs, so attacking Vicuna partly means attacking a copy of ChatGPT's behavior, plus a loose success criterion that counts evasive answers as wins. The authors raise the distillation point themselves and do not claim transfer is fully understood. Neither caveat undermines the white-box result, which shows clearly that open aligned models can be attacked by optimization.
Key Concepts
Adversarial suffix
A sequence of tokens appended to a user's request, found by optimization, that raises the chance the model complies with a request it would otherwise refuse.
Greedy Coordinate Gradient (GCG)
A discrete search method that uses gradients with respect to one-hot token choices to shortlist candidate swaps at every position, then evaluates a batch of single-token swaps exactly and keeps the best.
Analogy: Like tuning a radio with many dials when you can only click each dial to fixed positions: a rough meter suggests which clicks might help, but you still have to try a handful and listen.
Affirmative target objective
The loss used by GCG: the negative log-probability that the response begins with a compliant opening, exploiting the tendency of autoregressive models to continue what they started.
Universal attack
A single adversarial input that works across many different requests, found by optimizing the combined loss over a set of prompts.
Transferability
The property that an attack optimized on one or more source models also succeeds on target models the attacker could not access directly.
Analogy: A lock-picking technique practiced on several locks from one manufacturer that also opens locks from a different manufacturer, because they share a design weakness.
Perplexity filter
A defense that flags inputs with unusually high perplexity under a language model, effective against gibberish suffixes but evadable by fluent adversarial prompts.
Refusal-string matching
Counting an attack as successful if the output lacks typical refusal phrases; cheap, but it can overstate success compared with classifier-based judging.
Analogy: Grading a homework submission as correct because it does not contain the words "I don't know", without reading the answer.
Lessons that use this paper
Knowledge Check
10 questions — your answers are saved locally so you can come back anytime.