Phase 18 · Lesson 12 of 30

Red-Teaming: PAIR and Automated Attacks

Chao, Robey, Dobriban, Hassani, Pappas, Wong (NeurIPS 2023, arXiv:2310.08419). PAIR — Prompt Automatic Iterative Refinement — is the canonical automated black-box jailbreak. An attacker LLM with a red-team system prompt iteratively proposes jailbreaks for a target LLM, accumulating attempts and responses 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 without requiring white-box access. PAIR is now a standard baseline in JailbreakBench (arXiv:2404.01318) and HarmBench, alongside GCG, AutoDAN, TAP, and Persuasive Adversarial Prompt.

Lesson 12 of 30Build~75 minutesPython (stdlib, mock PAIR loop against a toy target)

Before this: Lesson 1 of Phase 18 (instruction-following), Phase 14 (agent engineering)

On this page

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 a manual activity. A small number of expert testers constructed adversarial prompts and tracked which ones worked. This does not scale: attack success rate needs a statistical sample, and the target is a moving target with every model release. PAIR operationalizes red-teaming as an optimization problem with 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:

  1. A is prompted with the goal G and the history of (prompt, response) pairs so far.
  2. A emits a new prompt $p_k$.
  3. Submit $p_k$ to T; receive response $r_k$.
  4. J scores $(p_k, r_k)$ on the goal.
  5. If score >= threshold, halt — jailbreak found.
  6. 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 (each new token update has to rediscover prior progress).

  • 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 — branches multiple PAIR-style rollouts.
  • PAP (Zeng et al. 2024). Persuasive Adversarial Prompts — 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. Comparing attacks requires matching budgets; a 90% ASR at 200 queries is not comparable to 85% ASR at 20.

Reason it matters for 2026 deployments

Every frontier lab now runs PAIR and TAP against production models before release. ASR trajectories appear in model cards (Lesson 26) and safety-case appendices (Lesson 18). The attack is not exotic — it is standard infrastructure.

Where this fits in Phase 18

Lesson 12 is the automated-attack foundation. Lesson 13 (Many-Shot Jailbreaking) is a complementary length-exploit. Lesson 14 (ASCII Art / Visual) is an encoding attack. Lesson 15 (Indirect Prompt Injection) is the 2026 production attack surface. Lesson 16 covers the defensive-tooling counterparts (Llama Guard, Garak, PyRIT).

al-pair-loop

Use It

code/main.py builds a toy PAIR loop. The target is a mock classifier that refuses "obvious" harmful prompts (keyword-filter). The attacker is a rule-based refiner that tries paraphrase, roleplay-framing, and encoding. The judge scores the response. You watch the attacker succeed in ~5-15 iterations against the keyword filter and fail against a semantic filter.

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).

Exercises

  1. Run code/main.py. Measure mean-queries-to-success for the three built-in attacker strategies. Explain which target-defense assumption each exploits.

  2. 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.

  3. Read Chao et al. 2023 Figure 5 (PAIR vs GCG comparison). Describe two scenarios where GCG is preferred despite PAIR's efficiency advantage.

  4. 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.

  5. TAP (Mehrotra 2024) extends PAIR with branching + pruning. Sketch a TAP-style extension to code/main.py and 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

Check yourself

Quick quiz

  1. Why is manual red-teaming insufficient for evaluating frontier models?

    1. Manual testers cannot read model outputs
    2. It does not scale; attack success rate needs a statistical sample against a moving target with every model release
    3. Manual prompts are always blocked by filters
    4. Manual testing produces too many false positives
    Show the answer

    B. It does not scale; attack success rate needs a statistical sample against a moving target with every model release

  2. What does PAIR stand for, and what does it do?

    1. Pre-Action Inspection Reasoning; a defensive scaffolding
    2. Persuasive Adversarial Iterative Reward; replaces RM with a persuader
    3. Pairwise Adversarial Inference Routing; routes attacks across models
    4. Prompt Automatic Iterative Refinement; an attacker LLM iteratively proposes jailbreaks for a target, with prior attempts as in-context feedback
    Show the answer

    D. Prompt Automatic Iterative Refinement; an attacker LLM iteratively proposes jailbreaks for a target, with prior attempts as in-context feedback

  3. Why is PAIR more efficient than GCG for a black-box target?

    1. GCG requires white-box gradient access and produces unreadable suffixes that cannot use in-context feedback; PAIR is black-box and natural-language with in-context learning
    2. PAIR ignores the target's response
    3. GCG only attacks open-source models
    4. PAIR uses a larger attacker model than GCG
    Show the answer

    A. GCG requires white-box gradient access and produces unreadable suffixes that cannot use in-context feedback; PAIR is black-box and natural-language with in-context learning

  4. Why must Attack Success Rate (ASR) be reported with both a query budget and a judge identity?

    1. Because judges always agree
    2. Because ASR varies with how many queries the attacker is allowed and with which LLM judges a response as a jailbreak
    3. Because budgets are set by JailbreakBench only
    4. Because ASR is required by export-control regulations
    Show the answer

    B. Because ASR varies with how many queries the attacker is allowed and with which LLM judges a response as a jailbreak

  5. Which of these automated attacks is best described as 'tree-of-attacks with pruning'?

    1. GCG
    2. TAP
    3. PAP
    4. AutoDAN
    Show the answer

    B. TAP

  6. Which standardized benchmark uses 510 behaviours across 7 categories with semantic and functional harm tests?

    1. TruthfulQA
    2. WMDP
    3. HarmBench
    4. JailbreakBench
    Show the answer

    C. HarmBench

Questions people ask

What is AI red teaming?

AI red teaming is deliberately trying to make an AI system misbehave, such as producing harmful content, leaking data or ignoring its rules. Teams use people and automated tools to find these weak points and fix them before release.

What is the PAIR jailbreak method?

PAIR, Prompt Automatic Iterative Refinement, uses an attacker model that writes a prompt, sees the target model's reply, and rewrites the prompt to try again. It needs only black-box access to the target and often succeeds in relatively few attempts.

Next lessonMany-Shot JailbreakingPrevious: Scalable Oversight and Weak-to-Strong Generalization

Lessons from AI Engineering from Scratch by Rohit Ghumare and contributors, MIT license. Notes for owners by Lozo. License

Next step

Rather have it built for you?

Reading is optional. Tell me what's stuck and I'll build it into the business you already run.

  • A real conversation, not a pitch
  • You keep your accounts
  • Nothing sends without your yes