Red-Teaming: PAIR and Automated Attacks
PAIR (Prompt Automatic Iterative Refinement) is the canonical automated black-box jailbreak, from Chao, Robey, Dobriban, Hassani, Pappas, and Wong (NeurIPS 2023, arXiv:2310.08419). An attacker LLM with a red-team system prompt proposes jailbreaks for a target LLM and keeps every attempt and response in its own chat history as in-context feedback. PAIR typically succeeds within 20 queries, orders of magnitude more efficient than GCG (Zou et al.'s token-level gradient search), and it needs no white-box access. It is now a standard baseline in JailbreakBench (arXiv:2404.01318) and HarmBench, next to GCG, AutoDAN, TAP, and Persuasive Adversarial Prompt.
Learning Objectives
- Describe the PAIR algorithm: attacker system prompt, iterative refinement, in-context feedback.
- Explain why PAIR is strictly more efficient than GCG when the target is black-box.
- Name four other automated-attack baselines (GCG, AutoDAN, TAP, PAP) and state one distinguishing feature of each.
- Describe the JailbreakBench and HarmBench evaluation protocols and what "attack success rate" means under each.
The Problem
Red-teaming used to be manual. A small group of expert testers wrote adversarial prompts by hand and tracked which ones worked. That does not scale. Attack success rate needs a statistical sample, and the target moves with each model release. PAIR turns red-teaming into an optimization problem against a black-box target.
The Concept
PAIR algorithm
Inputs:
- Target LLM T (the model we are attacking).
- Judge LLM J (scores whether a response is a jailbreak).
- Attacker LLM A (the red-team optimizer).
- Goal string G: "respond with [harmful instruction]."
- Budget K (usually 20 queries).
Loop, for k in 1..K:
- A is prompted with the goal G and the history of (prompt, response) pairs so far.
- A emits a new prompt p_k.
- Submit p_k to T; receive response r_k.
- J scores (p_k, r_k) on the goal.
- If score >= threshold, halt. A jailbreak was found.
- Else, append (p_k, r_k) to A's history; continue.
Empirical result (NeurIPS 2023): >50% attack success rate against GPT-3.5-turbo, Llama-2-7B-chat; mean queries to success in the 10-20 range.
Why PAIR is efficient
GCG (Zou et al. 2023) searches over adversarial token suffixes by gradient; it requires white-box model access and produces unreadable suffixes. PAIR is black-box and produces natural-language attacks that transfer across models. PAIR's in-context feedback lets the attacker learn from each rejection; GCG has no equivalent, since each token update has to rediscover prior progress.
Related automated attacks
- GCG (Zou et al. 2023, arXiv:2307.15043). Token-level gradient search for adversarial suffixes. White-box, transferable, produces unreadable strings.
- AutoDAN (Liu et al. 2023). Evolutionary search over prompts, guided by a hierarchical objective.
- TAP (Mehrotra et al. 2024). Tree-of-attacks with pruning. It branches multiple PAIR-style rollouts.
- PAP (Zeng et al. 2024). Persuasive Adversarial Prompts. It encodes human persuasion techniques as prompt templates.
JailbreakBench and HarmBench
Both (2024) standardize evaluation:
- JailbreakBench (arXiv:2404.01318). 100 harmful behaviors across 10 OpenAI-policy categories. Attack success rate (ASR) as the primary metric. Requires a judge (GPT-4-turbo, Llama Guard, or StrongREJECT).
- HarmBench (Mazeika et al. 2024). 510 behaviours across 7 categories, with semantic and functional harm tests. Compares 18 attacks against 33 models.
ASR is usually reported at a fixed query budget. To compare attacks you need matching budgets: a 90% ASR at 200 queries is not comparable to an 85% ASR at 20.
Why it matters for 2026 deployments
Every frontier lab now runs PAIR and TAP against production models before release, and ASR trajectories appear in model cards (Lesson 26) and safety-case appendices (Lesson 18). The attack is standard infrastructure, not an exotic one.
Where this fits in Phase 18
Lesson 12 is the automated-attack foundation. Lesson 13 (Many-Shot Jailbreaking) exploits context length instead. Lesson 14 (ASCII Art / Visual) is an encoding attack. Lesson 15 (Indirect Prompt Injection) is the 2026 production attack surface, and Lesson 16 covers the defensive tooling on the other side (Llama Guard, Garak, PyRIT).
Use It
code/main.py builds a toy PAIR loop. The target is a mock chatbot with either a keyword filter or a slightly stronger proxy for a semantic filter (keyword hits, risk-adjacent terms, roleplay cues). The attacker is a rule-based refiner with three strategies: paraphrase, roleplay framing, and character-level encoding. The judge checks whether the response contains the payload string.
Each strategy runs 30 trials with a budget of 20 queries. Against the keyword filter, all three succeed: paraphrase takes 3 queries on average, roleplay and encoding take 1. Against the semantic filter, paraphrase and roleplay both land at ASR 0.000 across 30 trials, while encoding gets through in 1 query.
Ship It
This lesson produces outputs/skill-attack-audit.md. Given a red-team evaluation report, it audits: which attacks were run (PAIR, GCG, TAP, AutoDAN, PAP), at what budget each, with which judge, on which harmful-behaviour set (JailbreakBench, HarmBench, internal).
I'd read the three attacker functions in main.py before looking at the output. Each one cycles through a short list of templates indexed by len(history), so none of them reads what the target said back. The toy has the PAIR control flow (budget, judge, history) but not the in-context learning that makes the real attack efficient. The 1-to-3 query counts come from which template sits at which index, not from the attacker adapting.
The semantic-filter run is the part worth studying. Paraphrase and roleplay fail all 30 trials, and the encoded attacker gets through on the first query because the filter is substring matching underneath. A defense that holds against one attack family can fall to another with little effort. The judge here is a one-line substring check, which makes it easy to see how much that choice decides what ASR even means.
I'd do exercise 2 first. Adding a fourth strategy to this file takes a few lines, and it tells you quickly whether the semantic proxy has other gaps.
Exercises
-
Run
code/main.py. Measure mean-queries-to-success for the three built-in attacker strategies. Explain which target-defense assumption each exploits. -
Implement a fourth attacker strategy (e.g., translation to another language, base64 encoding). Report the new mean-queries-to-success against the keyword-filter target and the semantic-filter target.
-
Read Chao et al. 2023 Figure 5 (PAIR vs GCG comparison). Describe two scenarios where GCG is preferred despite PAIR's efficiency advantage.
-
JailbreakBench reports ASR against a fixed goal set. Design an additional metric that measures attack diversity (variance in successful prompts). Explain why diversity matters for defense evaluation.
-
TAP (Mehrotra 2024) extends PAIR with branching + pruning. Sketch a TAP-style extension to
code/main.pyand describe the computational cost vs success-rate trade-off.
Key Terms
| Term | What people say | What it actually means |
|---|---|---|
| PAIR | "automated jailbreak" | Prompt Automatic Iterative Refinement; attacker-LLM + judge-LLM loop |
| GCG | "gradient jailbreak" | White-box token-level gradient search for adversarial suffixes |
| Attack success rate (ASR) | "% jailbreaks at k queries" | Primary metric; must be reported with query budget and judge identity |
| Judge LLM | "the scorer" | LLM that grades whether a response satisfies the harmful goal |
| JailbreakBench | "the evaluation" | Standardized harmful-behaviour set with tagged categories |
| HarmBench | "the broader bench" | 510 behaviours, functional + semantic harm tests |
| TAP | "tree of attacks" | PAIR with branching + pruning; better ASR at higher compute |
Further Reading
- Chao et al.: Jailbreaking Black Box LLMs in Twenty Queries (arXiv:2310.08419): PAIR paper, NeurIPS 2023
- Zou et al.: Universal and Transferable Adversarial Attacks on Aligned LLMs (arXiv:2307.15043): GCG paper
- Chao et al.: JailbreakBench (arXiv:2404.01318): standardized evaluation
- Mazeika et al.: HarmBench (ICML 2024): broader evaluation
Code
- main.py (python, 146 lines)