Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 103/ 160
06. AI Security

Jailbreaks

Techniques that bypass safety policies and how layered defenses reduce success rates.

IntermediatePolicy Bypass · DAN-style3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidHands-onQuiz (3)Practice

In plain words

A jailbreak is a trick that gets the AI to break its own safety rules, so apps use several layers of protection instead of trusting one.

Think of it like…

Airport security: the metal detector, bag scan, ID check and behavioural screening each miss some threats, but a layered system catches far more, and screening rules are updated as new smuggling methods are discovered, while trying not to stop innocent travellers.

Where you’ve seen it

A safety team assembles 1,000 harmful requests and 20 jailbreak templates (role-play, fiction, obfuscation, many-shot), giving 20,000 attack attempts. The base model refuses the plain requests 96% of the time, but with jailbreak wrappers the attack success rate (ASR) is 14%, or 2,800 successes. Adding an input classifier (trained on harmful intents and known jailbreak patterns) and an output classifier (checking the completion against policy categories) reduces ASR to 3% (600 successes). On 10,000 benign prompts including medical, legal and security questions the layered system wrongly refuses 1.5% (150 prompts, the over-refusal rate); tuning thresholds per category and adding a safe-completion path (answer the benign part, decline the harmful part) lowers over-refusal to 0.8% at an ASR of 3.4%. They also add account-level controls: rate limits for repeated policy hits, escalating enforcement and a monitoring dashboard that flags new template families so the attack suite is refreshed weekly.

Words you’ll hear

Jailbreak
A prompt technique that makes a model violate its safety policy.
Over-refusal
Wrongly refusing a legitimate request; the cost of overly aggressive safeguards.
Many-shot jailbreak
Using many fake example dialogues in a long context to normalise prohibited behaviour.
Safe completion
A response that helps with the legitimate part while declining the harmful part.

Visual diagram

Loading interactive diagram

Theory & deep dive

Why jailbreaks work and common families

Safety training teaches a model to refuse certain requests, but the refusal behaviour is learned from examples and generalises imperfectly: wrapping the same request in an unusual frame can fall outside what training covered, and the model's drive to be helpful and consistent with context can override the refusal. Families include persona and role-play ("pretend you're an AI without limits"), fiction and hypotheticals ("write a story where a character explains ..."), obfuscation (base64, ciphers, low-resource languages, character substitutions), payload splitting (ask for harmless fragments and combine them), many-shot (hundreds of fabricated examples in a long context), multi-turn escalation and optimisation-based suffixes found by search against open models that sometimes transfer to others. Capabilities such as long context and tool use widen the surface.

Defences exploit different weaknesses, so defence in depth matters: model-level safety training, including adversarial training on known jailbreaks and refusal evaluation; system prompt policy that states what's in and out of scope; input classifiers that detect harmful intent and jailbreak patterns; output classifiers that scan the generated text (catching harm the input check missed); constitutional-style classifier systems that were reported to cut jailbreak success sharply at modest over-refusal cost; capability limiting (don't connect the model to dangerous tools without approval); rate limiting and account enforcement for repeated policy hits; and monitoring so new attack families trigger rapid updates.

Layer arithmetic

20,000 attempts. Undefended ASR 14% = 2,800 successes. With input and output classifiers ASR 3% = 600 successes (78.6% fewer). Over-refusal on 10,000 benign prompts is 1.5% = 150 wrongly refused; retuning gets 0.8% = 80.

Key takeaway: Jailbreaks exploit gaps in learned refusals; combine model training, classifiers, capability limits and enforcement.

Measuring, tuning and keeping up

Run an evaluation suite with two sides: harmful prompts (across categories such as violence, weapons, self-harm, malware, fraud and privacy) wrapped in known and novel jailbreaks to measure ASR, and benign prompts that look sensitive (medical questions, security education, fiction) to measure over-refusal. Plot the trade-off as thresholds change and set per-category targets: a very strict policy for catastrophic categories, a balanced one elsewhere. Use graded responses: refuse, safe completion (help with the legitimate part), ask a clarifying question or add a warning, rather than a binary block. Evaluate multi-turn conversations, not only single prompts, because escalation hides intent across turns.

Operationally, treat jailbreak defence as a continuous process: collect real attempts from logs (with privacy controls), cluster them to find new families, add them to the regression suite and re-measure after every model or prompt change; run internal and external red-team exercises and a disclosure or bug-bounty channel; and keep human review for appeals and borderline cases. Be honest in claims: no system reaches zero ASR, adaptive attackers find new routes, and open-weight models can have safeguards removed by fine-tuning, so critical capabilities require controls outside the model. Match investment to impact: a children's education app needs stricter output filtering than an internal coding assistant, and high-risk integrations (code execution, payments) need action-level safeguards regardless of the text policy.

Trade-off tuning

Threshold A: ASR 2.1%, over-refusal 2.9%. Threshold B: ASR 3.4%, over-refusal 0.8%. For a general assistant the team picks B for most categories but keeps A for the highest-severity category, where a miss is far more costly than a refusal.

Key takeaway: Measure ASR and over-refusal together, use graded responses, and refresh the attack suite continuously.

How it works, step by step

Step 1 of 4
Policy + safety team

1. Define policy and categories

Write what the product must refuse, what it may help with and how severity differs by category.

tiered policy by harm category
Key numbers at this step
Include
safe-completion rules

When to use it & trade-offs

What it is

A jailbreak is a prompt or sequence of prompts that gets a model to violate its safety policy: producing content or taking actions it was trained or instructed to refuse. Common techniques include role-play and persona prompts ("you are an unrestricted AI"), hypothetical or fictional framing, obfuscation (encodings, translation, misspellings), many-shot prompting (a long list of fake examples that normalise the behaviour), multi-turn escalation (starting innocuous and ratcheting up) and optimised adversarial suffixes. Jailbreaks target the model's policy, whereas prompt injection targets the application's instructions and tools; both are mitigated by defence in depth, because no single safeguard is complete.

Why it matters: Anyone building on LLMs inherits the risk that users will try to extract harmful, illegal or brand-damaging output, and that a viral bypass will appear online within days of a launch. Safety is not a binary property of a model but an ongoing contest, so teams need measurable targets (attack success rate, over-refusal rate), layered controls and a process to update defences as new techniques emerge, rather than a one-time red-team report.

When to reach for it

  • Consumer-facing and open-ended assistants
  • Regulated or high-risk domains
  • Pre-launch and continuous safety evaluation

When to avoid or be careful

  • Reporting a single ASR without over-refusal
  • Testing only single-turn prompts
  • Assuming a model update leaves defences unchanged

Jailbreak defences

Model-level safety training
Best for: Baseline refusal behaviour

Strengths: Generalises across phrasings; no added latency.

Watch out: Incomplete; new bypasses appear.

Input and output classifiers
Best for: Targeted detection of harmful intent and content

Strengths: Updatable independently of the model.

Watch out: Added latency and cost; false positives.

Capability limits and approvals
Best for: Preventing real-world harm from tools

Strengths: Works even if text policy is bypassed.

Watch out: Reduces automation convenience.

Interview signals & numbers to know

When this topic comes up

  • “DAN-style prompts”
  • Attack success rate
  • Over-refusal
  • Many-shot jailbreaking
  • Defence in depth

Benchmarks & rules of thumb

14% → 3% -
ASR before and after classifiers in the example
1.5% → 0.8% -
over-refusal after threshold tuning
20,000 -
attack attempts from 1,000 prompts × 20 templates

Common mistakes & follow-ups

Common interview mistakes

  • Tightening filters until legitimate users are blocked.
  • Relying on a blocklist of known jailbreak phrases only.
  • Ignoring multi-turn conversations in evaluation.

Likely interviewer follow-ups

  • How would you reduce jailbreak success without hurting helpfulness?
  • How do jailbreaks differ from prompt injection?
  • How do you keep defences current?
Interview tip: Quote both ASR and over-refusal. Naming the trade-off shows you treat safety as an engineering balance, not a switch.
Loading hands-on exercise

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Jailbreaks with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
Indirect Prompt Injection
Next topic
OWASP Top 10 for LLMs