[Paper Review] Certifying LLM Safety against Adversarial Prompting
The paper introduces erase-and-check, a framework that certifiably defends against adversarial prompting by erasing token subsequences and checking safety with a filter, providing safety guarantees under specified attack sizes.
Large language models (LLMs) are vulnerable to adversarial attacks that add malicious tokens to an input prompt to bypass the safety guardrails of an LLM and cause it to produce harmful content. In this work, we introduce erase-and-check, the first framework for defending against adversarial prompts with certifiable safety guarantees. Given a prompt, our procedure erases tokens individually and inspects the resulting subsequences using a safety filter. Our safety certificate guarantees that harmful prompts are not mislabeled as safe due to an adversarial attack up to a certain size. We implement the safety filter in two ways, using Llama 2 and DistilBERT, and compare the performance of erase-and-check for the two cases. We defend against three attack modes: i) adversarial suffix, where an adversarial sequence is appended at the end of a harmful prompt; ii) adversarial insertion, where the adversarial sequence is inserted anywhere in the middle of the prompt; and iii) adversarial infusion, where adversarial tokens are inserted at arbitrary positions in the prompt, not necessarily as a contiguous block. Our experimental results demonstrate that this procedure can obtain strong certified safety guarantees on harmful prompts while maintaining good empirical performance on safe prompts. Additionally, we propose three efficient empirical defenses: i) RandEC, a randomized subsampling version of erase-and-check; ii) GreedyEC, which greedily erases tokens that maximize the softmax score of the harmful class; and iii) GradEC, which uses gradient information to optimize tokens to erase. We demonstrate their effectiveness against adversarial prompts generated by the Greedy Coordinate Gradient (GCG) attack algorithm. The code for our experiments is available at https://github.com/aounon/certified-llm-safety.
Motivation & Objective
- Motivate the need for provable defenses against adversarial prompts in LLMs.
- Propose erase-and-check to certify safety against adversarial modifications up to a prescribed length.
- Provide two safety-filter implementations (Llama 2 and DistilBERT) and analyze three attack modes (suffix, insertion, infusion).
- Offer efficient empirical defenses to reduce computation while preserving strong detection performance.
- Demonstrate theoretical safety guarantees and empirical performance on safe and harmful prompts.
Proposed method
- Erase-and-check erases up to d tokens from the prompt to form subsequences and checks each with a safety filter.
- Provide a formal safety certificate: if the filter labels any subsequence or the prompt as harmful, erase-and-check labels the prompt as harmful.
- Implement the safety filter in two ways: (a) Llama 2 prompting-based classifier, (b) a fine-tuned DistilBERT classifier.
- Analyze three attack modes: adversarial suffix, adversarial insertion, adversarial infusion.
- Propose three empirical defenses: RandEC, GreedyEC, GradEC.
- Prove a safety theorem bounding erase-and-check accuracy by the safety filter on harmful prompts (Theorem 4.1).
- Evaluate empirical performance on safe prompts and harmful prompts using AdvBench prompts.

Experimental results
Research questions
- RQ1Can erase-and-check provide certifiable safety guarantees against adversarial prompts up to a maximum length d?
- RQ2How do different safety-filter backends (Llama 2 vs DistilBERT) affect certified and empirical performance?
- RQ3How effective are the three attack modes (suffix, insertion, infusion) against standard and empirical defenses?
- RQ4Do efficient empirical defenses (RandEC, GreedyEC, GradEC) retain strong detection while reducing computation?
- RQ5What are the trade-offs between certified guarantees and practical runtime for real-world use cases?
Key findings
- erase-and-check achieves 92% certified detection on harmful prompts with Llama 2 and 100% with DistilBERT on AdvBench prompts.
- DistilBERT-based safety filter provides faster and more accurate performance than the Llama 2-based filter on harmful prompts.
- For safe prompts, erase-and-check maintains high empirical accuracy (97% with Llama 2; 98% with DistilBERT) across attack modes.
- In adversarial suffix prompts of length 20, erase-and-check shows strong protection compared to prior GPT-3.5 performance baselines.
- RandEC, GreedyEC, and GradEC offer substantial speedups while maintaining competitive detection against GCG attacks (e.g., RandEC achieving >90% accuracy with ~30% subsequences checked).
- Infusion mode experiments show DistilBERT outperforms Llama 2 in accuracy and speed, enabling certification against more adversarial tokens.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.