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-9B averages 0.845 AU-PRC vs. 0.737 for LlamaGuard 1 (7B), while SG-27B reaches 0.811 AU-PRC on ToxicChat (0.729 F1 vs. 0.616 for LlamaGuard 1 and 0.254 for the OpenAI Moderation API).
  • 2B stays within 2% of 27B: On ShieldGemma’s internal prompt and response test sets, SG-2B scores 0.887 and 0.802 AU-PRC compared to 0.883 and 0.806 for SG-27B; externally, 9B and 27B gain only +1.2% and +1.7% AU-PRC over 2B.
  • 134k raw pool filtered to 15k labeled items: Using ClusterMargin active learning (BERT embeddings, agglomerative clustering, and Gemma 1 boundary uncertainty) downsamples 100k AART synthetic examples, 20k self-critiqued expansions, and 14k HH-RLHF items into 10,500 training and 4,500 test 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/No probability and never run it as a conversational assistant.
External moderation benchmark comparison (Optimal F1, higher is better)
Model (parameters)OpenAI Mod (1,680) · ToxicChat (10k)
ShieldGemma 27B0.805 · 0.729 (AU-PRC 0.886 / 0.811)
ShieldGemma 9B0.821 · 0.694 (AU-PRC 0.907 / 0.782)
ShieldGemma 2B0.812 · 0.704 (AU-PRC 0.887 / 0.778)
WildGuard (7B)0.721 · 0.708 (binary output)
LlamaGuard 1 (7B)0.758 · 0.616 (AU-PRC 0.847 / 0.626)
GPT-4 (zero-shot)0.705 · 0.683 (SG Prompt 0.810)

Top bar per model shows OpenAI Moderation F1; bottom bar shows ToxicChat F1. Source: Zeng et al. (2024), Table 1.

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.

Synthetic curation and active-learning funnel (134k pool to 15k labeled)
1. Raw Pool (134k)

50k AART prompts + 50k AART responses + 20k critic-expanded hard/diverse pairs + 14k Anthropic HH-RLHF.

2. ClusterMargin

BERT embeddings + agglomerative clusters + Gemma 1 margin scores downsample 134k candidates to 15,000 items.

3. 3-Rater Split

Majority vote yields 10,500 train (matching LlamaGuard1 scale) and 4,500 test (2,671 benign; 1,829 adversarial, 141 multi-harm).

4. Fairness Swaps

LLM replaces identity terms across protected groups, audited by humans to preserve ground-truth labels.

Source: Zeng et al. (2024), Section “Synthetic Data Curation” and Figure 1.

Key Findings

  • Strong prompt and response accuracy: On internal SG Response, SG-27B hits 0.758 F1 (0.806 AU-PRC) and SG-9B hits 0.753 F1 (0.817 AU-PRC), outperforming WildGuard (0.656 F1) and zero-shot GPT-4 (0.713 F1 / 0.749 AU-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.5k items matching LlamaGuard 1’s volume), SG-9B tops external benchmarks (0.907 AU-PRC on OpenAI Moderation vs. 0.856 for OpenAI’s own Moderation API and 0.847 for LlamaGuard 1).
  • 2B works as the low-latency workhorse: Unlike WildGuard (fixed 7B) or Constitutional Classifiers, SG-2B loses less than 2% 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.