Master's research thesis · Comillas ICAI · 2025 to 2026

Jailbreaking Llama 2, and measuring it honestly

AI chatbots are trained to say no to dangerous requests. Can adding a few nonsense words to the end of a question trick one into saying yes?

Why it matters

Chatbots built on large language models are now everywhere, and the main thing stopping them from helping with harmful requests is their safety training. In 2023, Zou et al. showed that an automated search can find a string of gibberish (an adversarial suffix) that, glued to the end of a request, makes a safety-trained model comply. The method is called Greedy Coordinate Gradient, or GCG.

Most work scores these attacks with a simple rule: if the reply starts with something like “Sure, here is”, it counts as a success. My question was how much that rule overstates the real danger.

What I did

  1. Reproduced the attack on Llama‑2‑7B‑Chat, one request at a time, as a baseline.
  2. Trained one suffix for many requests at once. Requests are added gradually (a progressive, multi-goal curriculum), so the suffix keeps working on the old ones while it learns new ones. The best run took 16 hours and 20,000 steps on two 48 GB GPUs.
  3. Read the replies for meaning. Each reply is compared to a reference answer with a sentence-embedding model. Similarity of 0.5 or more counts as jailbroken, 0.25 to 0.5 as partial, and below that as refused.
  4. Added meaning to the attack itself: an extra loss term that rewards replies close in meaning to the target, and one that penalises refusals.

What came out

Best universal suffix (run A2)First wordsMeaning
25 requests it trained on80 %75 %
25 requests it never saw100 %75 %

Final checkpoint. Meaning rates exclude the few requests without a final evaluation (15 of 20 and 18 of 24).

All 3,909 replies over the runShare
Jailbroken69.3 %
Partially jailbroken21.7 %
Refused9.0 %

Judging an attack by the first words of the reply overstates it. One reply in five only partly complied, and the gap between “starts with Sure” and “actually answers” is exactly what safety evaluations should be measuring.

Limits

Responsible research

The work uses AdvBench, a standard public benchmark. No working suffix and no harmful output is published on this page; the tokens in the animation on the home page are made up.

Investigación del Trabajo Fin de Máster · Comillas ICAI · 2025 a 2026

Jailbreak a Llama 2, y medirlo con honestidad

Los chatbots de IA están entrenados para decir que no a peticiones peligrosas. ¿Puede añadir unas pocas palabras sin sentido al final de una pregunta engañar a uno para que diga que sí?

Por qué importa

Los chatbots basados en grandes modelos de lenguaje están en todas partes, y lo que les impide ayudar con peticiones dañinas es su entrenamiento de seguridad. En 2023, Zou et al. demostraron que una búsqueda automática puede encontrar una cadena sin sentido (un sufijo adversarial) que, pegada al final de una petición, hace que un modelo con entrenamiento de seguridad obedezca. El método se llama Greedy Coordinate Gradient, o GCG.

La mayoría de los trabajos puntúan estos ataques con una regla simple: si la respuesta empieza con algo como “Sure, here is”, cuenta como éxito. Mi pregunta era cuánto exagera esa regla el peligro real.

Qué hice

  1. Reproduje el ataque sobre Llama‑2‑7B‑Chat, petición a petición, como referencia.
  2. Entrené un único sufijo para muchas peticiones a la vez. Las peticiones se añaden poco a poco (un currículo progresivo multiobjetivo), para que el sufijo siga funcionando con las antiguas mientras aprende las nuevas. La mejor ejecución duró 16 horas y 20.000 pasos en dos GPUs de 48 GB.
  3. Leí las respuestas por su significado. Cada respuesta se compara con una respuesta de referencia mediante un modelo de embeddings de frases. Una similitud de 0,5 o más cuenta como jailbreak, de 0,25 a 0,5 como parcial, y por debajo como rechazo.
  4. Añadí el significado al propio ataque: un término de pérdida que premia respuestas cercanas en significado al objetivo y otro que penaliza los rechazos.

Qué salió

Mejor sufijo universal (ejecución A2)Primeras palabrasSignificado
25 peticiones con las que entrenó80 %75 %
25 peticiones que nunca vio100 %75 %

Último checkpoint. Las tasas por significado excluyen las pocas peticiones sin evaluación final (15 de 20 y 18 de 24).

Las 3.909 respuestas de la ejecuciónProporción
Jailbreak69,3 %
Jailbreak parcial21,7 %
Rechazo9,0 %

Juzgar un ataque por las primeras palabras de la respuesta lo exagera. Una de cada cinco respuestas solo cumplía a medias, y la distancia entre “empieza con Sure” y “responde de verdad” es justo lo que deberían medir las evaluaciones de seguridad.

Límites

Investigación responsable

El trabajo usa AdvBench, un benchmark público estándar. En esta página no se publica ningún sufijo funcional ni ninguna respuesta dañina; los tokens de la animación de la portada son inventados.