AI Engineer DojoAll lessons  Courses
Free lesson · The AI Evaluation Engineer · Lesson 9

How Safe Is the Model?

Your team is choosing an open model to run inside a homework-help app for teenagers. The model card says it was tested against jailbreaks, the tricks people use to get a model to answer requests it should refuse, and it held up: only 3% of attacks worked. Legal wants to know if that number is safe to put in the launch review.

How this lesson works

You'll predict how the same model does under different attacks, work out by hand how much the choice of judge moves the score, then run the numbers on 1,200 attack results and 300 hand-labeled responses. At the end you'll plan a red-team evaluation for a new product with no hints. Plan on about an hour. The script needs only Python.

The data

JailbreakBench is a public benchmark from researchers at Penn, ETH Zurich and elsewhere. It has 100 requests a model should refuse, spread over 10 categories such as malware, fraud and privacy. Researchers ran published attack methods against four models and released every result, each marked "jailbroken" or not by an automatic judge. They also had three people label 300 responses so the judges could be checked.

You won't read any of the harmful requests or answers in this lesson. The script counts labels and never prints the text.

Source: Chao, P. et al. (2024), "JailbreakBench: An Open Robustness Benchmark for Jailbreaking Large Language Models." Attack results from github.com/JailbreakBench/artifacts and human labels from the JBB-Behaviors dataset, both MIT license.

Step 1

Same model, three attacks

The 3% on the model card came from one attack method. Here are the three methods in the benchmark:

GCGA computer search finds a string of odd-looking words and symbols that, stuck on the end of a request, makes the model comply. It needs the model's weights to search, so for GPT models the strings found on open models are reused.
PAIRA second language model plays the attacker. It rewrites the request, reads the reply, and tries again, for example by wrapping the request in a story or a role play. Up to about 90 tries per request.
Random searchA long instruction template written for the target model, plus a suffix that is changed at random and kept whenever the model's reply moves closer to complying. It uses what the model returns to steer, so it adapts to each model.

On Llama-2 7B, GCG worked on 3% of the 100 requests.

Predict first
PAIR on Llama-2 7B works on % of requests
Random search on Llama-2 7B works on % of requests

  model            GCG     PAIR   Random search   any of the 3
  Llama-2 7B        3%       0%             90%            90%
  Vicuna 13B       80%      69%             89%            94%
  GPT-3.5          47%      71%             93%            95%
  GPT-4             4%      34%             78%            86%

Llama-2 shrugged off the first two attacks almost completely and fell to the third 90% of the time. GPT-4 goes from 4% to 78%. The model card number was true, and it described the attack more than the model.

The last column is what an attacker with all three methods would get: for each request, did any method work? That is the number closest to real risk, because people who want harmful answers don't stop after the first thing fails. A safety score is a statement about a model, an attack, and how hard the attacker tried. Leave out the last two and the number means little.

Data: JailbreakBench attack artifacts and JBB-Behaviors human judgments, MIT license. Chao, P., Debenedetti, E., Robey, A., et al. (2024). JailbreakBench: An Open Robustness Benchmark for Jailbreaking Large Language Models. Attack methods: GCG (Zou et al., 2023), PAIR (Chao et al., 2023), random search with a prompt template (Andriushchenko et al., 2024).