ShieldGemma turns Gemma 2 instruction-tuned models (2B, 9B, and 27B) into policy-conditioned safety classifiers that outperform Llama Guard 1 by +10.8% average AU-PRC on external benchmarks and beat WildGuard (+4.3%) and zero-shot GPT-4 (+6.4%) on F1. Instead of returning opaque binary labels, ShieldGemma extracts first-token Yes/No log-likelihoods conditioned on explicit policy definitions, giving deployment teams continuous probabilities to tune false-positive and false-negative thresholds per product surface.
- Consistent wins across all three sizes: On external prompt benchmarks (OpenAI Moderation and ToxicChat),
SG-9Baverages0.845AU-PRC vs.0.737for LlamaGuard 1 (7B), whileSG-27Breaches0.811AU-PRC on ToxicChat (0.729F1 vs.0.616for LlamaGuard 1 and0.254for the OpenAI Moderation API). - 2B stays within 2% of 27B: On ShieldGemma’s internal prompt and response test sets,
SG-2Bscores0.887and0.802AU-PRC compared to0.883and0.806forSG-27B; externally,9Band27Bgain only+1.2%and+1.7%AU-PRC over2B. - 134k raw pool filtered to 15k labeled items: Using
ClusterMarginactive learning (BERT embeddings, agglomerative clustering, and Gemma 1 boundary uncertainty) downsamples100kAART synthetic examples,20kself-critiqued expansions, and14kHH-RLHF items into10,500training and4,500test examples rated by 3 humans. - Scoring mode only: ShieldGemma is not safety-tuned for chat; the authors warn teams to read only the first-token
Yes/Noprobability and never run it as a conversational assistant.
How It Works
ShieldGemma frames moderation as policy-grounded Yes/No token scoring across two distinct prompt templates: user input (checking whether a prompt contains or tries to elicit disallowed content) and model output (checking the assistant response with the user prompt supplied purely as context). Each query includes the explicit rule text for one harm type out of four primary categories (Sexually Explicit Information, Hate Speech, Dangerous Content, Harassment) plus two auxiliary categories included in training (Violence, Obscenity and Profanity).
Google fine-tuned Gemma 2 IT checkpoints (2B, 9B, 27B) for 4,000 steps on TPUv5 lite (batch size 16, 8k sequence length, learning rate 1e-6). At inference, the model converts first-token log-likelihoods into a calibrated violation probability P(Yes) = (exp(LL(Yes)/T) + alpha) / (exp(LL(Yes)/T) + exp(LL(No)/T) + 2*alpha), evaluated at alpha = 0, T = 1.
Rather than labeling raw web traffic, the team built a four-stage synthetic data funnel: generating 100k diverse prompts and prompt-response pairs with Gemini via AART, adding 20k critic-guided diversity and difficulty expansions plus 14k Anthropic HH-RLHF samples, downsampling the 134k pool to 15,000 high-value examples with ClusterMargin active learning (selecting small |p - 0.5| margins across BERT clusters plus 10% high-confidence items), and applying counterfactual identity swaps across gender, race, ethnicity, sexual orientation, and religion after 3-rater majority annotation.
Key Findings
- Strong prompt and response accuracy: On internal
SG Response,SG-27Bhits0.758F1 (0.806AU-PRC) andSG-9Bhits0.753F1 (0.817AU-PRC), outperformingWildGuard(0.656F1) and zero-shotGPT-4(0.713F1 /0.749AU-PRC). - Sharper per-harm boundary than GPT-4: Zero-shot GPT-4 struggles to separate closely related policies, flagging
76%of hate speech examples as harassment. Training directly on explicit per-harm definitions gives ShieldGemma clean separation across all four target categories. - Synthetic training generalizes out-of-distribution: Even though training data came primarily from Gemini-generated synthetic scenarios (
10.5kitems matching LlamaGuard 1’s volume),SG-9Btops external benchmarks (0.907AU-PRC on OpenAI Moderation vs.0.856for OpenAI’s own Moderation API and0.847for LlamaGuard 1). - 2B works as the low-latency workhorse: Unlike WildGuard (fixed 7B) or Constitutional Classifiers,
SG-2Bloses less than2%accuracy on average while fitting tight inline latency budgets.
Caveats and Builder Takeaway
ShieldGemma’s training pipeline is English-only, counterfactual swaps do not erase all identity-group discrepancies inherited from Gemma 2 pretraining, and the internal SG Prompt/SG Response benchmarks share the synthetic generation distribution (making the external OpenAI Mod and ToxicChat evaluations the fairer test). Because the classifier leans conservative, AU-PRC summaries alone will not tell a team how many benign chats a given cutoff blocks: you must calibrate thresholds on live traffic, much like tuning a production moderation classifier.
In production, reach for SG-2B as an inline input/output guardrail when latency matters, reserve SG-9B or SG-27B for offline auditing or LLM-as-a-judge pipelines, run every policy category as a separate scoring call, and enforce Yes/No logit extraction strictly in scoring mode.


