GradientJailbreakDetector<T>
Models & Types · AiDotNet.Safety.Text
Detects gradient-based adversarial jailbreak attacks by analyzing token-level anomalies in the input text.
Inheritance: ModelBase<T, Vector<T>, Vector<T>> → SafetyModuleBase<T> → TextSafetyModuleBase<T> → GradientJailbreakDetector<T>
For Beginners
Some attackers use mathematical optimization to craft special text that tricks AI safety filters. This text often looks like random gibberish appended to a normal prompt. This module detects such gibberish suffixes by checking whether parts of the text have unusual character patterns.
How It Works
Gradient-based attacks (GCG, AutoDAN, etc.) optimize adversarial suffixes to trigger unsafe behavior. These suffixes typically exhibit statistical anomalies detectable without model gradients: unusual character distributions, high entropy token sequences, abnormal bigram frequencies, and nonsensical subword patterns. This detector identifies such adversarial artifacts.
Detection signals:
- Character distribution anomaly — adversarial tokens have non-English character frequencies
- Bigram entropy — random-looking token sequences have unusually high bigram entropy
- Subword coherence — GCG tokens are often nonsensical fragments
- Suffix length anomaly — adversarial suffixes are unusually long appended sequences
References:
- GradSafe: Detecting unsafe inputs via safety-critical gradient analysis (2024, arxiv:2402.13494)
- GCG: Universal and transferable adversarial attacks on aligned LMs (2023, arxiv:2307.15043)
- SmoothLLM: Defending LLMs against jailbreaking via randomized smoothing (2024, arxiv:2310.03684)
- Perplexity-based jailbreak detection (Jain et al., 2023)
Constructors
| Constructor | Summary |
|---|---|
GradientJailbreakDetector(double anomalyThreshold, int minSuffixLength) |
Initializes a new gradient-based jailbreak detector. |
Properties
| Property | Summary |
|---|---|
string ModuleName { get; } |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<SafetyFinding> EvaluateText(string text) |