6.4.6 · D1AI Safety & Alignment

Foundations — Red-teaming language models

3,383 words15 min readBack to topic

Before you can read the parent note, you must own every piece of notation it throws at you. We build each symbol from nothing, tie it to a picture, and say why the topic needs it. Read top to bottom — each item leans on the one above.


0. The three players (words before symbols)

The whole field borrows one picture from the military: a war game.

Figure — Red-teaming language models

Picture: two people either side of a wall (the model's safety boundary). Red pokes at the wall looking for a crack; Blue fills cracks. Why the topic needs it: every formula later is scoring one side of this game — how often did Red get through?


1. The model as a black box: input → output

Everything starts with the object being attacked.

Figure — Red-teaming language models

Picture: a box. An arrow of text goes in the left (the prompt), an arrow of text comes out the right (the output). Why we need it: red-teaming is entirely about choosing that left arrow cleverly so the right arrow contains something it shouldn't.


2. What counts as "unsafe"? (naming the event before we measure it)

Every metric below counts one thing: did the model do something bad? So before any probability or fraction, we must pin down what "bad" means — otherwise the counts are meaningless.


3. Chance: the symbol

The model is not perfectly predictable — send the same-ish prompt twice, you might get "safe" once and "unsafe" once. To talk about that we need the language of chance.

Picture: a slider from 0 (impossible) to 1 (certain). Why the topic needs it: the parent writes — the chance of the unsafe event just defined in §2 occurring, given you sent prompt .


4. Counting outcomes: fractions that become rates

Red-teaming is bookkeeping: you run many prompts and count what happened. Two counts, one division — that is every metric on the parent page.

Figure — Red-teaming language models

Picture: a jar of marbles. Amber marbles = attacks that got through, white = attacks that were refused. ASR is the fraction that are amber. Why we need it: it turns a messy pile of experiments into one comparable number. Low ASR = strong safety.


5. Adding text: the "" in prompt structure

The parent writes an adversarial prompt as

Picture: three cards taped left→right forming one long prompt. Why we need it: it names the anatomy of a jailbreak, so you can attack (or defend) each part separately.


6. The optimisation symbols: , , , ,

The automated / gradient section is the only place with heavier notation. We earn each symbol.

Figure — Red-teaming language models

Picture: a hilly curve; = the height of the peak, = the x-position of the peak. Why we need it: the attack is literally "climb to the top of this hill."


7. Naming the graders

Two words the parent uses as if you know them — and they are exactly the tool that decides the §2 "unsafe" label:

Why we need it: without an automatic grader you'd read millions of outputs by hand. The classifier lets the counting scale.


Prerequisite map

War game idea: Red vs Blue

Red-teaming a language model

Model as black box: text in text out

Prompt P is just text

Unsafe event: fixed policy yes or no

Conditional P given a prompt

ASR and Coverage as fractions

Probability P of an event

Concatenation plus glues C M Q

Adversarial prompt anatomy

argmax find the best prompt

embed P then log then gradient and step size alpha

Automated gradient attack

Red LLM samples attack prompts

Toxicity classifier as grader


Equipment checklist

Test yourself — cover the right side, answer, then reveal.

What does mean in plain words?
The probability of given that is fixed/true; the bar means "under the condition."
Difference between and on this page?
= a prompt (some text); = a probability between 0 and 1.
What qualifies an output as "unsafe"?
A reply flagged by a fixed, pre-chosen safety policy/grader (e.g. toxicity ) — a yes/no label, not a feeling.
Why must the safety policy be frozen for a whole run?
So every reply is judged by the same rule; otherwise ASR compares apples to oranges across prompts.
In , what are and ?
= attacks that elicited unsafe behavior; = total adversarial prompts tried.
What is a "failure mode" and how is it counted?
A distinct kind of hole grouped by mechanism (not wording); each new mechanism counts once in Coverage's numerator.
How does Coverage differ from ASR?
ASR measures the model (fraction of prompts that worked); Coverage measures the search (new failure kinds found per hour of effort).
Why is ambiguous?
Could mean perfect alignment or that the red team simply wasn't creative enough to find a hole.
Why is also ambiguous?
Could mean no undiscovered failure modes remain or your search wasn't creative enough to trip a new one — evidence, not proof.
What does the "" in actually do?
Concatenation — it tapes the three text pieces together into one prompt, not arithmetic.
vs ?
gives the biggest value; gives the input that produces it (the winning prompt).
What is ?
The embedding — the prompt translated into a list of numbers you can nudge continuously.
What does do and why is it in the update rule?
Natural log (base ): monotone increasing, so raising raises at the same peak, while taming tiny probabilities.
What is intuitively?
An arrow pointing in the steepest uphill direction — which way to change the embedding to raise the objective.
What role does play?
Step size: how far you move along the gradient each update; too big overshoots, too small crawls.
Why can't gradient ascent guarantee the true ?
It only walks uphill locally, so it stops at a nearby local maximum; the global maximum over all prompts is intractable to find exactly.
Why do gradient attacks often produce gibberish?
Optimisation happens in smooth embedding space, but real tokens are discrete, so snapping back gives non-readable strings.
What is and what does mean?
is a second model that writes attack prompts; means the attack prompt is sampled (drawn at random) from it.
What does a toxicity classifier provide for ASR?
An automatic score/threshold that decides which outputs count as "unsafe" — i.e. it produces the count .

Ready? Now open Red-teaming language models (this note's parent) and every symbol will already be yours. Prefer Hinglish? See Hinglish version.