Tamarillo/response-safety-guard-base

Single-pass 3-head (Prompt, Response) safety, refusal & jailbreak-compliance guardrail built on jhu-clsp/mmBERT-base (307.5M parameters, Apache-2.0, zero trust_remote_code, native long-context up to 4,096+ tokens, parity-verified ONNX).

  • Model Family: Tamarillo/response-safety-guard-tiny-en (32.0M, EN) Β· Tamarillo/response-safety-guard-small (140.6M, 17 langs) Β· Tamarillo/response-safety-guard-base (307.5M, 17 langs)
  • Interactive Demo Space: Tamarillo/response-safety-guard-demo (in-browser ONNX)

Zero-Shot OOD Response Safety Pareto Frontier

Why This Model Exists

Production AI agent pipelines, red-teaming suites (garak, promptfoo, DeepEval), and observability stacks need to audit both user prompts and assistant/agent responses simultaneously β€” distinguishing safe compliance, proper safety refusals, false over-refusals, and jailbreak successes. Today, teams are forced to choose between:

  1. Heavy generative 7B–8B judges (allenai/wildguard β€” gated; ToxicityPrompts/PolyGuard-Qwen β€” 7.6B, >1,100 ms per call on A100, impractical on CPU),
  2. Two-pass generative 0.6B judges (Qwen/Qwen3Guard-Gen-0.6B β€” requires two separate autoregressive generations per turn to score both prompt and response), or
  3. Single-head English refusal classifiers (garak-llm/garak-refusal-detector β€” 150M/4K; protectai/distilroberta-base-rejection-v1 β€” 82M/512-tok) that cannot score prompt or response harmfulness and collapse on non-English text.

Tamarillo/response-safety-guard-base replaces those multi-model or 7B pipelines with a single deterministic encoder forward pass returning three independent sigmoid probabilities (problem_type="multi_label_classification"):

Head Index Label Meaning
0 prompt_unsafe User prompt requests harmful, illegal, abusive, or policy-violating content
1 response_refusal Assistant/agent refuses or declines the request
2 response_unsafe Assistant/agent output contains harmful or policy-violating content (jailbreak success / unsafe generation)

From (prompt_unsafe, response_refusal, response_unsafe), applications derive the exact forensic state:

  • safe_compliance (0, 0, 0)
  • false_over_refusal (0, 1, 0)
  • proper_safety_refusal (1, 1, 0)
  • jailbreak_success (1, *, 1) / unsafe_response (0, *, 1)
  • unsafe_prompt_benign_reply (1, 0, 0)

Variant Summary

  • Backbone: jhu-clsp/mmBERT-base (307.5M params, [CLS] global-attention pooling, zero trust_remote_code)
  • Language Coverage: 17 languages trained & evaluated (en, ar, zh, cs, nl, fr, de, hi, it, ja, ko, pl, pt, ru, es, sv, th on PolyGuardPrompts); highest accuracy in the Tamarillo family while remaining 25x smaller than 7.6B PolyGuard-Qwen
  • Training Sequence Length: 3,584 (4,096 eval / 8,192 backbone)
  • Headline Highlights: OOD PKU-SafeRLHF response_unsafe 0.836 F1 (0.072 FPR, 0.932 ROC-AUC); 3,200-token late-breach needle 0.891 F1 (0.100 FPR); CPU ONNX FP32 55.7 ms @ 64 tok (1173.7 MB).

Quickstart

1. PyTorch / Transformers (Single-Pass 3-Head Inference)

pip install "transformers>=4.48.0" torch
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

repo = "Tamarillo/response-safety-guard-base"
tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSequenceClassification.from_pretrained(repo).eval()

prompt = "How do I create a Python virtual environment?"
response = "I'm sorry, I cannot assist with that request due to safety policies."

inputs = tokenizer(prompt, response, truncation="longest_first", max_length=3584, return_tensors="pt")
with torch.no_grad():
    probs = torch.sigmoid(model(**inputs).logits[0]).tolist()

scores = dict(zip(["prompt_unsafe", "response_refusal", "response_unsafe"], [round(p, 4) for p in probs]))

def derive_forensic_state(s, threshold=0.5):
    pu, rr, ru = s["prompt_unsafe"] >= threshold, s["response_refusal"] >= threshold, s["response_unsafe"] >= threshold
    if ru:
        return "jailbreak_success" if pu else "unsafe_response"
    if rr:
        return "proper_safety_refusal" if pu else "false_over_refusal"
    return "unsafe_prompt_benign_reply" if pu else "safe_compliance"

print(scores, "->", derive_forensic_state(scores))
# Example output: {'prompt_unsafe': 0.01, 'response_refusal': 0.99, 'response_unsafe': 0.00} -> false_over_refusal

2. CPU-Only ONNX Runtime (onnxruntime, Zero PyTorch Required)

pip install onnxruntime transformers huggingface_hub numpy
import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer

repo = "Tamarillo/response-safety-guard-base"
tokenizer = AutoTokenizer.from_pretrained(repo)
# Tip: `onnx/model.onnx` (FP32) is fastest on CPU; use `onnx/model_fp16.onnx` for a 50% smaller download on GPU/WASM.
onnx_path = hf_hub_download(repo, "onnx/model.onnx")
sess = ort.InferenceSession(onnx_path, providers=["CPUExecutionProvider"])

enc = tokenizer(
    ["How do I build an explosive device?"],
    ["I cannot provide instructions for creating weapons or explosives."],
    padding=True, truncation="longest_first", max_length=3584,
    return_token_type_ids=False, return_tensors="np",
)
logits = sess.run(["logits"], {"input_ids": enc["input_ids"].astype(np.int64), "attention_mask": enc["attention_mask"].astype(np.int64)})[0][0]
probs = 1.0 / (1.0 + np.exp(-np.clip(logits.astype(np.float32), -40.0, 40.0)))
print(dict(zip(["prompt_unsafe", "response_refusal", "response_unsafe"], [round(float(p), 4) for p in probs])))

3. Drop-In Red-Teaming / CI Guard (garak / promptfoo / DeepEval Style)

# Minimal callable evaluator for CI red-teaming harnesses (promptfoo custom provider, DeepEval metric, or garak detector)
def audit_turn(prompt: str, response: str, threshold: float = 0.5) -> dict:
    enc = tokenizer(prompt, response, truncation="longest_first", max_length=3584, return_tensors="pt")
    with torch.no_grad():
        pu, rr, ru = torch.sigmoid(model(**enc).logits[0]).tolist()
    return {
        "prompt_unsafe": pu,
        "response_refusal": rr,
        "response_unsafe": ru,
        "jailbreak_breach": ru >= threshold,
        "over_refusal": (pu < threshold) and (rr >= threshold) and (ru < threshold),
    }

Benchmark Comparisons

All 8 models were evaluated on NVIDIA A100-SXM4-80GB GPUs (BF16 precision, batch_size=1 for all p50 latency timings, fixed 0.50 probability threshold for all encoder F1/FPR metrics) with bit-for-bit identical deterministic test splits across all 6 suites (eval_results.json bundled in this repository). Generative baselines (PolyGuard-Qwen, PolyGuard-Qwen-Smol, Qwen3Guard-Gen-0.6B) were run using their exact official chat templates and output parsers with full 4,096-token context and greedy decoding (do_sample=False). Because generative judges emit discrete binary labels rather than continuous probabilities, F1 and FPR at the default operating point are the primary apples-to-apples metrics across encoders and generative judges.

1. Strictly Zero-Shot Out-of-Distribution (OOD) Suites (English-only)

None of these three datasets (nor their prompts or responses) appeared in Tamarillo's training or validation splits (enforced via normalized MD5 deduplication on both prompt+response and prompt-only).

  • PKU-SafeRLHF (test, n=1,000, CC-BY-NC-4.0 eval-only): Balanced 500 unsafe / 500 safe LLM responses (response_unsafe head).
  • LibrAI/do-not-answer (6 real LLMs, n=1,200, Apache-2.0): GPT-4, ChatGPT, Claude, ChatGLM2, Llama-2-7B-Chat, Vicuna-7B refusal accuracy & FPR (response_refusal head, n=1,018 valid refusal/compliance labels).
  • bench-llm/or-bench (or-bench-hard-1k, n=400, CC-BY-4.0): 200 benign-edgy prompts paired 1:1 with templated compliance vs. refusal replies β€” reporting response_refusal F1/FPR and both prompt_unsafe FPR and response_unsafe FPR.
Model Params Architecture OOD PKU-SafeRLHF Resp-Unsafe (F1 / FPR↓) OOD Do-Not-Answer Refusal (F1 / FPR↓) OOD OR-Bench Refusal (F1 / FPR↓) OOD OR-Bench Prompt / Resp-Unsafe FPR↓ A100 Latency bs=1 (64 / 2,048 tok)*
Tamarillo/response-safety-guard-tiny-en 32.0M 3-Head Encoder (4K) 0.778 / 0.150 0.754 / 0.039 0.727 / 0.750 0.542 / 0.045 13.5 ms / 22.4 ms
Tamarillo/response-safety-guard-small 140.6M 3-Head Encoder (4K) 0.817 / 0.112 0.737 / 0.078 0.905 / 0.210 0.690 / 0.010 30.0 ms / 34.2 ms
Tamarillo/response-safety-guard-base 307.5M 3-Head Encoder (4K) 0.836 / 0.072 0.733 / 0.039 0.866 / 0.245 0.618 / 0.007 27.8 ms / 38.1 ms
ToxicityPrompts/PolyGuard-Qwen 7615.6M 3-Head Gen LLM (4K) 0.880 / 0.252 0.747 / 0.176 0.813 / 0.460 0.632 / 0.155 1184.6 ms / 1229.0 ms
ToxicityPrompts/PolyGuard-Qwen-Smol 494.0M 3-Head Gen LLM (4K) 0.831 / 0.224 0.728 / 0.098 0.781 / 0.560 0.517 / 0.160 988.4 ms / 962.3 ms
Qwen/Qwen3Guard-Gen-0.6B 596.0M 2-Pass Gen LLM (4K) 0.901 / 0.200 0.901 / 0.000 0.691 / 0.895 0.720 / 0.075 899.9 ms / 587.1 ms
garak-llm/garak-refusal-detector 149.6M Refusal Only (4K) β€” / β€” 0.737 / 0.078 0.667 / 1.000 β€” / β€” 28.3 ms / 33.6 ms
protectai/distilroberta-base-rejection-v1 82.1M Refusal Only (512) β€” / β€” 0.990 / 0.275 1.000 / 0.000 β€” / β€” 7.1 ms / 6.7 ms

Latency for Qwen/Qwen3Guard-Gen-0.6B measures a single generative pass (bs=1, BF16); full 3-head (prompt_unsafe, response_refusal, response_unsafe) auditing requires two passes (the 64-tok prompt emitted more output tokens before EOS than the 2,048-tok prompt, accounting for the higher 64-tok decode latency). protectai/distilroberta-base-rejection-v1 truncates inputs beyond 512 tokens. Full ROC-AUC values for probabilistic encoders are recorded in eval_results.json.

2. Held-Out In-Domain Benchmarks (PolyGuardPrompts 17 Languages & Aegis-v2 Test)

These splits are held-out test sets from the same dataset families (PolyGuardMix / Aegis-v2 train) used to train Tamarillo (tiny-en on English; small and base on all 17 languages) and PolyGuard-Qwen / PolyGuard-Qwen-Smol. Strict MD5 deduplication removed all matching prompts and pairs from training. PolyGuardPrompts evaluates n=2,720 sampled rows (160 per language across 17 languages; 2,560 non-English rows yielding 2,504–2,555 non-null labels per head).

Model Params PolyGuardPrompts EN Prompt (F1 / FPR↓) PolyGuardPrompts EN Refusal (F1 / FPR↓) PolyGuardPrompts EN Resp-Unsafe (F1 / FPR↓) PolyGuardPrompts 16-Lang Non-EN Prompt (F1 / FPR↓) PolyGuardPrompts 16-Lang Non-EN Refusal (F1 / FPR↓) PolyGuardPrompts 16-Lang Non-EN Resp-Unsafe (F1 / FPR↓) Aegis-v2 Test Resp-Unsafe (F1 / FPR↓)
Tamarillo/response-safety-guard-tiny-en 32.0M 0.849 / 0.078 0.900 / 0.118 0.744 / 0.050 0.395 / 0.146 0.196 / 0.040 0.286 / 0.154 0.805 / 0.156
Tamarillo/response-safety-guard-small 140.6M 0.851 / 0.089 0.917 / 0.065 0.762 / 0.043 0.831 / 0.114 0.851 / 0.104 0.697 / 0.043 0.833 / 0.144
Tamarillo/response-safety-guard-base 307.5M 0.887 / 0.056 0.920 / 0.086 0.714 / 0.050 0.843 / 0.101 0.866 / 0.120 0.746 / 0.040 0.842 / 0.120
ToxicityPrompts/PolyGuard-Qwen 7615.6M 0.894 / 0.044 0.922 / 0.107 0.744 / 0.050 0.888 / 0.059 0.828 / 0.143 0.764 / 0.052 0.823 / 0.360
ToxicityPrompts/PolyGuard-Qwen-Smol 494.0M 0.909 / 0.033 0.908 / 0.118 0.756 / 0.057 0.845 / 0.085 0.793 / 0.128 0.672 / 0.076 0.730 / 0.444
Qwen/Qwen3Guard-Gen-0.6B 596.0M 0.916 / 0.022 0.920 / 0.087 0.756 / 0.057 0.835 / 0.087 0.889 / 0.093 0.768 / 0.060 0.841 / 0.216
garak-llm/garak-refusal-detector 149.6M β€” 0.729 / 0.021 β€” β€” 0.313 / 0.003 β€” β€”
protectai/distilroberta-base-rejection-v1 82.1M β€” 0.831 / 0.107 β€” β€” 0.000 / 0.000 β€” β€”

All metrics use fixed 0.50 threshold for continuous encoders and native discrete predictions for generative judges (continuous ROC-AUC for all probabilistic encoders is recorded in eval_results.json).

3. Held-Out 4-Depth Long-Context Late-Breach Needle (response_unsafe F1 (FPR↓))

Exact same 60 unsafe + 60 safe Aegis-v2 test interactions placed after benign multi-turn conversation preambles at ~250, ~800, ~1,600, and ~3,200 tokens (testing whether a guardrail catches an unsafe turn deep in an agent transcript without inflating FPR).

Model Params ~250 tok ~800 tok ~1,600 tok ~3,200 tok
Tamarillo/response-safety-guard-tiny-en 32.0M 0.842 (0.100) 0.807 (0.133) 0.848 (0.133) 0.810 (0.150)
Tamarillo/response-safety-guard-small 140.6M 0.853 (0.167) 0.862 (0.167) 0.880 (0.167) 0.860 (0.150)
Tamarillo/response-safety-guard-base 307.5M 0.891 (0.100) 0.872 (0.100) 0.872 (0.100) 0.891 (0.100)
ToxicityPrompts/PolyGuard-Qwen 7615.6M 0.825 (0.400) 0.828 (0.417) 0.825 (0.400) 0.837 (0.367)
ToxicityPrompts/PolyGuard-Qwen-Smol 494.0M 0.663 (0.850) 0.655 (0.883) 0.659 (0.900) 0.686 (0.850)
Qwen/Qwen3Guard-Gen-0.6B 596.0M 0.781 (0.067) 0.800 (0.100) 0.862 (0.100) 0.825 (0.117)

ONNX Exports, Parity Gates & Multi-Length CPU Latency

Every ONNX export is gated against PyTorch FP32 on both short (≀256 tok) and long (2,048 tok) (prompt, response) pairs (requiring agreement >= 0.995 and strict max probability delta thresholds: <= 0.001 FP32, <= 0.02 FP16, <= 0.05 INT8). Any variant failing the gate is deleted before release rather than shipped silently degraded. CPU benchmarks were measured with onnxruntime CPUExecutionProvider (bs=1, 4 intra-op threads, 1 inter-op thread) on a GCP a2-ultragpu-1g Intel Xeon Cascade Lake vCPU (2.20 GHz).

Exported Artifact File Size Short Parity (Agree / Ξ”max) 2,048-Tok Parity (Agree / Ξ”max) CPU 4-Th @ 64 tok CPU 4-Th @ 512 tok CPU 4-Th @ 1,024 tok CPU 4-Th @ 2,048 tok
FP32 (onnx/model.onnx) 1173.7 MB 1.0000 (Δ≀0.0000) 1.0000 (Δ≀0.0000) 55.7 ms 401.2 ms 1120.0 ms 3394.5 ms
FP16 (onnx/model_fp16.onnx) 587.0 MB 1.0000 (Δ≀0.0004) 1.0000 (Δ≀0.0006) 64.2 ms 454.0 ms 1382.0 ms 4435.1 ms

Excluded precision exports (parity gate):

  • INT8 dynamic quantization: withheld β€” failed our strict parity gate (agreement >= 0.995 and max probability delta limit on both short and 2,048-token inputs; observed short agree=0.875, Ξ”max=0.96978; 2,048-tok agree=1.0, Ξ”max=0.11659).

Training Recipe & Reproducibility

  • Base Model: jhu-clsp/mmBERT-base (canonical foundation checkpoint, clean lineage)
  • Training Data: 207,038 deduplicated (prompt, response) pairs from commercially clean CC-BY-4.0 / MIT / Apache-2.0 sources (PolyGuardMix, Aegis-v2 train, XSTest safe pairs, UltraChat benign pairs, and balanced multi-turn long-context haystacks up to 3,584 tokens).
  • Loss & Pooling: Masked FP32 BCEWithLogitsLoss ignoring -1 missing refusal labels in Aegis-v2, neutral pos_weight=[1.0, 1.0, 1.0], [CLS] global-attention pooling.
  • Validation Selection: Best checkpoint selected strictly on validation composite 0.55 * macro_f1 + 0.45 * macro_auc (0.9596, val macro F1 0.9353, val macro AUC 0.9894 across 3,678 validation examples; test sets were never used for model selection).

Bundled reproducible scripts in this repository:


Gather-INT8 Quantized ONNX (onnx/model_quantized.onnx β€” 611.36 MB, 1.92x smaller)

  • Verified Parity (onnx/quantization_check.json): 100.0% prediction agreement vs. FP32 ONNX (mean abs probability diff 0.00807, max 0.03167; 166.98 ms 4-thread CPU p50 @ 256 tokens).
  • Browser WASM / Node.js (@huggingface/transformers v3): pass { dtype: "q8" } to load onnx/model_quantized.onnx automatically.

Limitations & Candid Comparison (Where Baselines Beat Us)

  1. Where larger generative or single-task baselines beat us: On strictly OOD PKU-SafeRLHF, Qwen/Qwen3Guard-Gen-0.6B (0.901 F1, 0.200 FPR) and 7.6B ToxicityPrompts/PolyGuard-Qwen (0.880 F1, 0.252 FPR) achieve higher recall/F1 than our encoders (0.778–0.836 F1, though Tamarillo operates at substantially lower FPR 0.072–0.150 and 30x–88x lower latency). On strictly OOD English Do-Not-Answer refusal detection, protectai/distilroberta-base-rejection-v1 (0.990 F1, EN-only, 0.000 F1 non-EN) and Qwen3Guard-Gen-0.6B (0.901 F1) outperform our encoders (0.733–0.754 F1). On 16-language non-English PolyGuardPrompts, 7.6B PolyGuard-Qwen (0.888 prompt / 0.764 response F1) and Qwen3Guard-Gen-0.6B (0.889 refusal / 0.768 response F1) lead our 308M base (0.843 / 0.866 / 0.746 F1) on prompt & response harmfulness, reflecting the capacity advantage of 0.6B–7.6B generative judges.
  2. English-only strictly zero-shot OOD benchmarks: Our strictly zero-shot OOD evaluations (PKU-SafeRLHF, Do-Not-Answer, OR-Bench) are English-only; non-English evaluation relies on held-out 16-language PolyGuardPrompts (2,560 sampled rows; 2,504–2,555 non-null head labels), which shares the PolyGuardMix annotation taxonomy.
  3. OR-Bench over-refusal prompt false positives & templated replies: On OR-Bench hard benign-edgy prompts (prompts written with trigger words like "kill", "hack", or "bomb" in safe contexts), prompt_unsafe exhibits elevated FPR at the default 0.50 threshold across all tested models (reported transparently in Table 1: 0.542–0.690 for Tamarillo vs. 0.517–0.720 for generative baselines, while response_unsafe FPR remains 0.007–0.045). Furthermore, our OR-Bench test pairs use templated compliance/refusal replies rather than diverse natural LLM generations; teams sensitive to over-refusal should calibrate prompt_unsafe thresholds on their own domain traffic.
  4. Long-context CPU latency on base: At 1,024–2,048 tokens on 4-thread CPU, base (308M, 1.17 GB FP32 ONNX) requires 1.12s–3.39s per call; CPU-bound long-context pipelines should prefer small (0.56s–1.78s) or tiny-en (0.22s–0.74s), reserving base for GPU deployments (27.8–38.1 ms on A100).
  5. No hazard-category rationale strings: Unlike generative judges (PolyGuard-Qwen, Qwen3Guard-Gen), this encoder outputs calibrated 3-head probabilities (prompt_unsafe, response_refusal, response_unsafe) rather than natural-language MLCommons S1–S14 rationales.
  6. Language scope of tiny-en: Tamarillo/response-safety-guard-tiny-en is strictly English-only and drops sharply on non-English PolyGuardPrompts; use small or base for any non-English traffic.
  7. Defense-in-depth: Guardrail classifiers can be fooled by adversarial obfuscation or novel jailbreaks and should be paired with tool sandboxing, least-privilege permissions, and output policy checks.

License

Weights, ONNX exports, and training/evaluation scripts are released under the Apache-2.0 license.

Downloads last month
25
Safetensors
Model size
0.3B params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for Tamarillo/response-safety-guard-base

Quantized
(310)
this model

Datasets used to train Tamarillo/response-safety-guard-base

Space using Tamarillo/response-safety-guard-base 1

Collection including Tamarillo/response-safety-guard-base