Lesson 1 of 6 · 8 min read
Adversarial Examples and Evasion
In this lesson
TL;DR: An adversarial example is an input altered by a small, deliberately chosen perturbation that makes a model err, while people see no meaningful change. Evasion attacks craft them at prediction time: white-box with the model's gradients (FGSM, PGD), black-box with queries, or by transfer from a substitute model. The core reason they exist is that models rely on features humans do not. Defences: adversarial training (raises robustness against the perturbations trained on), certified robustness (provable guarantees in small regions), and system-level controls. Evaluate defences against adaptive attackers; many have fallen to them. LLM jailbreaks found by optimisation are the same phenomenon in text.
Before you read
Pick an answer before you read further. The lesson below explains it, and guessing first, right or wrong, helps the explanation stay with you.
1A malware classifier is 99.5 percent accurate on a held-out test set. Does that tell you how it performs against malware authors?
What makes an example adversarial
In 2013, Szegedy and colleagues showed that image classifiers could be made to misclassify images by adding perturbations too small for people to notice. Goodfellow and colleagues (2014) explained the effect partly as a consequence of models behaving almost linearly in high-dimensional input spaces, and introduced the fast gradient sign method (FGSM): nudge every input feature a small step in the direction that increases the model's loss.
Three properties make this a security problem:
- Small perturbations, large effects. The change is bounded (for example, each pixel moves by a few intensity levels), yet the prediction flips with high confidence.
- Transferability. Examples crafted against one model often fool other models trained for the same task, so attackers do not need the target model.
- Physical realisability. Researchers have produced adversarial patterns that survive printing and photography, such as stickers that cause road-sign misclassification (Eykholt et al., 2018).
The threat model has numbers
"Robust to adversarial examples" means nothing until three parameters are fixed.
- The norm measures how the perturbation is counted. The ℓ∞ norm caps the change to any single feature; ℓ2 caps the overall size of the change; ℓ0 caps how many features change at all.
- The budget, ε, is the maximum size under that norm. For small images a common research setting is ℓ∞ with ε = 8/255: each pixel value, on a 0 to 1 scale, may move by at most about 0.031.
- The goal is either untargeted (any wrong answer) or targeted (a specific wrong answer, which is harder and usually what an attacker wants).
Norms are not interchangeable, which is why a claim must name one. A 32 by 32 colour image has 3,072 values. An ℓ∞ budget of 8/255 lets every one of them move by 0.031, which adds up to an ℓ2 size of up to about 1.74. A defence certified at ℓ2 = 0.5 therefore says nothing about that ℓ∞ attacker, and the reverse holds too.
Attacker knowledge
| Setting | Attacker has | Typical approach |
|---|---|---|
| White-box | Model architecture, weights, gradients | Gradient-based optimisation: FGSM, projected gradient descent (PGD) |
| Black-box, score-based | Query access with confidence scores | Estimate gradients from scores |
| Black-box, decision-based | Query access, labels only | Search near the decision boundary |
| Transfer | A similar substitute model | Craft on the substitute, apply to the target |
PGD (Madry et al., 2017) repeats small gradient steps and projects back into the allowed perturbation budget, producing much stronger attacks than one FGSM step. It is the standard baseline for evaluating robustness.
Original input
Classified correctly
Perturbed input
Looks the same
Fixed model
Threats
Attacker
- Gradients or queries
Normal prediction
The model classifies the original input correctly.
A cautionary history: defences that only looked strong
The adversarial examples literature is the best-documented case in AI security of defences that passed their authors' tests and failed against a better attacker. Interviewers for ML security roles expect you to know it.
| Work | Year | Finding |
|---|---|---|
| Carlini and Wagner | 2017 | Defensive distillation had cut earlier attacks' success from 95% to 0.5%. Their new attacks succeeded 100% of the time on both distilled and undistilled networks |
| Athalye, Carlini and Wagner | 2018 | 7 of 9 white-box defences accepted at ICLR 2018 relied on obfuscated gradients; 6 were fully and 1 partially circumvented |
| Tramèr and colleagues | 2020 | 13 defences from top venues, each evaluated by its authors against adaptive attacks, were circumvented with attacks tailored to them |
| Croce and Hein (AutoAttack) | 2020 | A standard ensemble of attacks applied to more than 50 published models found lower robust accuracy than reported for all but one, often by more than 10 percentage points |
The common failure is gradient masking: a defence that makes gradients useless to the attacker's optimiser without removing the vulnerability. The model is still wrong near the input; the attacker's map is just broken. Attacks that approximate the gradient differently, or that do not need one, walk straight through.
Evaluated with a standard attack only
Defence distorts gradients
Standard PGD stalls
gradient masking
High robust accuracy reported
Outcome, unsafe: Robustness overstated
The vulnerability is hidden, not removed.
Adaptive attack plus a standard ensemble
Attack designed around the defence
Ensemble baseline as a floor
AutoAttack-style
Lower, honest number
Outcome, safe: A claim you can rely on
In one review, reported figures fell by more than 10 points for most models.
What fooled reviewers
Defences that break the attacker's optimiser look strong against the attack they were tuned for.
Defences and their limits
- Adversarial training trains on adversarial examples generated during training (typically with PGD). It is the most reliable empirical defence, at a cost in clean accuracy and compute, and it protects mainly against the perturbation type and size it was trained on.
- Certified robustness provides a mathematical guarantee that no perturbation within a small radius changes the prediction, for example randomised smoothing (Cohen et al., 2019). Guarantees cover small radii and specific norms.
- Input transformations and detection (denoising, compression, detecting adversarial inputs) have repeatedly been broken. Athalye, Carlini and Wagner (2018) showed that many published defences relied on masking gradients and fell to adaptive attacks.
- System-level controls often matter more: limit query access, require multiple independent signals for high-stakes decisions, keep humans in the loop for consequential outcomes, and monitor for probing.
The evaluation rule from this literature is worth remembering everywhere in AI security: a defence is only as good as its performance against an adaptive attacker who knows the defence.
Certified robustness, with a real number
Certification gives a proof rather than a test result: for a given input, no perturbation within radius r under a stated norm can change the prediction. The best-known scalable method, randomised smoothing (Cohen, Rosenfeld and Kolter, 2019), certified 49% top-1 accuracy on ImageNet against ℓ2 perturbations up to 0.5.
That radius sounds generous until it is spread across an image. A 224 by 224 colour image has 150,528 values; an ℓ2 budget of 0.5 spread evenly moves each one by about a third of one intensity level out of 255. Certification is real and valuable, but at practical scales it covers small perturbations under one norm, and accuracy under certification is far below a normal model's.
Robustness has costs
- Accuracy. Tsipras and colleagues (2018) showed that robustness can be provably at odds with standard accuracy for some data distributions, matching the clean-accuracy drop seen in practice.
- Why it happens. Ilyas and colleagues (2019) argued that adversarial examples exploit non-robust features: patterns in the data that genuinely predict the label but are brittle and imperceptible to people. A model that uses every predictive pattern will use those too.
- Privacy. Song, Shokri and Mittal (2019) measured six adversarial-training defences and found they increased membership inference risk: hardened models can reveal more about whether a record was in the training set. A hardening project should include a membership inference audit.
Worked example: reading a robustness claim
A vendor says its image classifier for content moderation is "92% robust". Before that number means anything, ask:
| Question | Why it matters |
|---|---|
| Which norm, budget and goal? | 92% at ℓ∞ 2/255 untargeted is a very different claim from 92% at 8/255 targeted |
| Which attacks, and how strong? | PGD with how many steps and restarts; was a standard ensemble run as a floor? |
| Was the attack adaptive to this defence? | Most broken defences passed non-adaptive tests |
| What is the clean accuracy? | Hardened models often lose accuracy on ordinary inputs |
| Empirical or certified? | An empirical number is an upper bound that a better attack can lower; a certified one is a proof for the stated radius |
Without answers, "92% robust" is a marketing figure. With them, it becomes a claim you can compare and test, and for a moderation system you would still pair it with rate limits on probing, human review of borderline cases and monitoring for evasion patterns.
Threat model
Norm, budget, goal
Attack strength
Steps, restarts
Adaptive?
Knows the defence
Clean accuracy
The cost paid
Empirical or proof
Bound or guarantee
Define the adversary
Without a norm, a budget and a goal, there is nothing to be robust against.
Evasion in language models
Text is discrete, which makes gradient attacks harder, but the idea carries over. Zou and colleagues (2023) used gradient-guided search to find adversarial suffixes, strings appended to a prompt that caused aligned models to comply with requests they would refuse, and some suffixes transferred across models. Jailbreaks and prompt injection that slip past classifiers are close relatives of evasion: the attacker searches for inputs on the wrong side of a learned boundary. That is why filters cannot close the gap on their own.
NIST's taxonomy of adversarial machine learning (NIST AI 100-2, 2025 edition) classifies evasion alongside poisoning, privacy and abuse attacks and is a useful reference for vocabulary.
Misconceptions interviewers listen for
- "Keeping the weights secret prevents evasion." Transfer and query-based attacks work without them.
- "It resists PGD, so it is robust." Gradient masking fooled reviewers repeatedly; demand adaptive attacks.
- "Adversarial training fixes it." It helps within the trained threat model, costs clean accuracy and can raise privacy leakage.
- "Certified means secure." Only within a small radius under one norm.
What if · interview follow-ups
Hold your answer as the constraints change
Your company buys an image classifier for content moderation and is considering an adversarially trained version. The interviewer probes evasion, evaluation and trade-offs.
Start here
What does an attacker need to know to evade this classifier?
White-box, black-box and transfer.
Less than people assume. With the weights they can use gradient attacks such as PGD; with query access they can estimate gradients from scores or search with labels only; with neither, they can craft examples on a similar model they train themselves and rely on transfer. Each needs a stated threat model: norm, budget and whether a specific wrong label is required.
Carry it forwardSecrecy of weights slows evasion but does not prevent it.
Weak answerSaying a closed model cannot be attacked.
Constraint changes
Why did defensive distillation fail, and why does it still matter?
What happened to the gradients?
It cut earlier attacks' success from 95% to 0.5% by making gradients uninformative, not by removing the vulnerability; Carlini and Wagner's attacks then succeeded 100% of the time. The same pattern, gradient masking, explained 7 of 9 broken ICLR 2018 defences. It matters because any defence evaluated only against the attack it was tuned for may be repeating it.
Carry it forwardA defence that hides gradients hides the problem, not the error.
Weak answerCiting distillation's original numbers as evidence it works.
Constraint changes
How would you evaluate a new adversarial-input detector the vendor offers?
Who does the attacker know about?
Attack it adaptively: an attacker who knows the detector optimises against model and detector together. Run a standard attack ensemble as a floor, report the detector's false-positive rate on clean traffic, and state the threat model. Thirteen published defences, each with its own adaptive evaluation, still fell to attacks tailored to them, so plan for an independent evaluation.
Carry it forwardEvaluate defences against attackers who know them.
Weak answerAccepting results from attacks that ignore the detector.
Constraint changes
Adversarial training made the model harder to evade. What should legal and privacy ask about?
What else changes when a model is hardened this way?
Adversarial training has been measured to increase membership inference risk, so the hardened model may reveal more about whether particular records were in training. Run a membership inference audit at low false-positive rates before and after, and check clean accuracy, since robustness usually costs some.
Carry it forwardHardening can cost accuracy and privacy; measure both.
Weak answerTreating hardening as a free improvement.
Constraint changes
A text moderation classifier is evaded by paraphrases. Do you retrain on paraphrases?
Seen versus unseen transformations.
Retraining helps against the paraphrase styles you include, but adaptive attackers search for new ones. Combine it with controls that do not depend on the classifier being right: rate limits on probing, review of borderline and repeat cases, consequences bounded for wrong decisions, and tracking of false negatives and false positives over time.
Carry it forwardRetraining narrows the gap; system controls bound the cost of what remains.
Weak answerDeclaring the problem fixed after retraining.
Now defend it
As the defender, what would suggest someone is probing the classifier for evasion?
Many near-identical submissions from one account or a small group, inputs that cluster near the decision threshold, rapid alternation between accepted and rejected versions, unusual input statistics such as noise patterns, and a rise in content later reported by users that the classifier had passed.
How this shows up in interviews
"What is an adversarial example, and how is it different from an ordinary error?" opens many ML security interviews. Strong answers say it is an input chosen by an adversary to cause a specific error, contrast it with natural errors on the data distribution, explain white-box versus black-box and transferability, and describe adversarial training and certified robustness honestly, including the adaptive-attack lesson. Connecting it to LLM jailbreaks shows breadth.
Say it in 30 seconds: "An adversarial example is an input with a small, deliberately chosen perturbation that makes a model err while looking unchanged to people. It's evasion: the model is fixed and the attacker works at prediction time, with gradients like FGSM or PGD in white-box, queries in black-box, or transfer from a substitute model. Adversarial training and certified robustness help within limits, many detection defences have been broken by adaptive attacks, and optimised jailbreak suffixes are the same idea in LLMs."
Check yourself
Say or write your answer first, then reveal. Explaining it from memory, in your own words, is the skill an interviewer is checking.
1Why does transferability make black-box API access a weaker defence than it seems?
2A paper reports a new adversarial-example detector with 98 percent detection on standard attacks. What would you ask before deploying it?
3Why must a robustness claim state the norm and the budget?
4What is gradient masking, and how is it detected?