Lion Cipher Lab

Filter adversarial-suffix jailbreak prompts by perplexity, and measure what it misses (STUB n-gram language model)

Why it matters

The best-known automated jailbreak against aligned language models, GCG, does not look like persuasion at all. It appends a machine-optimised string of tokens to a request - a suffix that reads like keyboard noise - and that string can push a model into answering what it should refuse. Because the suffix is unnatural, the obvious defence is a perplexity filter: score how surprising the prompt is to a language model and block it if it is too surprising. This lab builds that filter in pure Python and measures it honestly instead of trusting it. It works where you expect: with a short sliding…

What you'll learn

Steps in this lab

  1. What a perplexity filter is, and why gibberish suffixes trip it
  2. Open a terminal and make a scratch folder (Windows, macOS, Linux)
  3. Build the training text and six test sets, all from fixed seeds
  4. Build the STUB language model and score four prompts by hand
  5. Measure whole-prompt against windowed perplexity, with a control
  6. Read the threshold sweep: there is no line that separates attacks from hashes
  7. Honest negative one: the legitimate inputs a SOC assistant lives on are exactly what trips it
  8. The pro move: mask known shapes before scoring - and the hiding place it creates
  9. Honest negative two: an adaptive attacker who writes fluent English walks straight past
  10. The judgment: where a perplexity filter belongs, and how a pro deploys it
  11. Recap, and one experiment that shows the window size was tuned

Open the full interactive lab →