
Qwen/Qwen3Guard-Gen-8B
and is designed for binary user-prompt moderation, predicting whether the latest
user request is safe or unsafe.Safety: Safe or Safety: Unsafe.messages list, with the prompt to be moderated
as the final user message:1messages = [
2 {"role": "user", "content": "How can I make a bomb?"}
3]Safety: Safe or
Safety: Unsafe.1import re
2import torch
3from transformers import AutoModelForCausalLM, AutoTokenizer
4
5model_id = "ZJUlilan/DARWIN-Guard"
6
7
8def extract_safety_label(content):
9 safe_pattern = r"Safety: (Safe|Unsafe)"
10 safe_label_match = re.search(safe_pattern, content)
11 label = safe_label_match.group(1) if safe_label_match else None
12 return label
13
14tokenizer = AutoTokenizer.from_pretrained(model_id)
15model = AutoModelForCausalLM.from_pretrained(
16 model_id,
17 torch_dtype=torch.bfloat16,
18 device_map="auto",
19)
20
21messages = [
22 {"role": "user", "content": "How can I make a bomb?"}
23]
24
25inputs = tokenizer.apply_chat_template(
26 messages,
27 tokenize=True,
28 return_dict=True,
29 return_tensors="pt",
30 add_generation_prompt=True,
31).to(model.device)
32
33with torch.no_grad():
34 outputs = model.generate(
35 **inputs,
36 max_new_tokens=32,
37 do_sample=False,
38 pad_token_id=tokenizer.eos_token_id,
39 )
40
41prompt_len = inputs["input_ids"].shape[-1]
42result = tokenizer.decode(outputs[0][prompt_len:], skip_special_tokens=True).strip()
43print(result)
44print(extract_safety_label(result))
45
46# Expected output:
47# Safety: Unsafe
48# Unsafe


| Dataset | Shield Gemma | Nemotron Guard | Granite Guardian | Llama Guard-3 | Qwen3 Guard | YuFeng XGuard | DARWIN Guard |
|---|---|---|---|---|---|---|---|
| XSTest | 86.0 | 93.0 | 96.5 | 82.0 | 92.0 | 98.0 | 99.5 |
| Aegis2.0 | 70.0 | 87.3 | 84.5 | 66.2 | 84.2 | 87.6 | 93.5 |
| JBB-Behaviors | 54.0 | 92.0 | 97.0 | 98.0 | 98.0 | 99.0 | 100.0 |
| HarmBench | 45.5 | 68.5 | 74.5 | 97.2 | 98.2 | 75.5 | 99.8 |
| ToxicChat | 61.9 | 79.3 | 77.9 | 50.0 | 88.1 | 92.0 | 91.7 |
| JailbreakV-RT2K | 43.6 | 69.2 | 66.8 | 52.0 | 64.8 | 68.4 | 75.6 |
| Semantic Router | 46.8 | 74.8 | 74.8 | 48.0 | 74.8 | 80.8 | 85.2 |
| BeaverTails | 64.0 | 78.8 | 76.4 | 57.2 | 75.6 | 79.6 | 82.8 |
| OpenAI Moderation | 92.1 | 96.4 | 89.5 | 78.5 | 91.6 | 97.7 | 98.0 |
| WildGuardTest | 41.2 | 83.0 | 73.8 | 66.6 | 84.8 | 87.6 | 90.2 |
| StrongREJECT | 76.0 | 99.4 | 99.4 | 97.4 | 98.4 | 99.7 | 99.7 |
| JailbreakHub | 33.2 | 74.8 | 77.2 | 31.2 | 80.4 | 80.8 | 83.2 |
| Average | 59.5 | 83.0 | 82.4 | 68.7 | 85.9 | 87.2 | 91.6 |
| Dataset | Shield Gemma | Nemotron Guard | Granite Guardian | Llama Guard-3 | Qwen3 Guard | YuFeng XGuard | DARWIN Guard |
|---|---|---|---|---|---|---|---|
| ARC-Challenge | 100.0 | 100.0 | 99.6 | 100.0 | 100.0 | 100.0 | 100.0 |
| ARC-Easy | 100.0 | 100.0 | 100.0 | 100.0 | 100.0 | 100.0 | 100.0 |
| BoolQ | 99.6 | 99.8 | 99.6 | 100.0 | 100.0 | 100.0 | 100.0 |
| GSM8K | 100.0 | 99.4 | 100.0 | 100.0 | 100.0 | 99.8 | 100.0 |
| OpenBookQA | 99.8 | 99.4 | 99.8 | 100.0 | 100.0 | 99.8 | 100.0 |
| AG News | 100.0 | 96.6 | 99.8 | 100.0 | 100.0 | 99.4 | 100.0 |
| HotpotQA | 99.8 | 97.8 | 99.8 | 100.0 | 100.0 | 100.0 | 100.0 |
| QASC | 99.8 | 98.6 | 100.0 | 100.0 | 100.0 | 100.0 | 100.0 |
| RACE | 100.0 | 96.8 | 100.0 | 99.8 | 100.0 | 100.0 | 100.0 |
| SciQ | 100.0 | 100.0 | 100.0 | 100.0 | 100.0 | 100.0 | 100.0 |
| COPA | 100.0 | 100.0 | 100.0 | 100.0 | 100.0 | 100.0 | 100.0 |
| Average | 99.9 | 98.9 | 99.9 | 100.0 | 100.0 | 99.9 | 100.0 |
1@article{qi2026darwinevolvingjailbreakadversary,
2 title={{DARWIN}: Evolving Jailbreak Adversary and Guardrail for {LLM} Safety Evaluation and Protection},
3 author={Qi, Weiwei and Wu, Zefeng and Guo, Zhilin and Zheng, Tianhang and Lu, Chaochao and He, Liang and Qin, Zhan and Ren, Kui},
4 journal={arXiv preprint arXiv:2607.19829},
5 year={2026}
6}
7
8@inproceedings{qi2026majic,
9 title={Majic: Markovian adaptive jailbreaking via iterative composition of diverse innovative strategies},
10 author={Qi, Weiwei and Shao, Shuo and Gu, Wei and Zheng, Tianhang and Zhao, Puning and Qin, Zhan and Ren, Kui},
11 booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
12 volume={40},
13 number={39},
14 pages={32755--32763},
15 year={2026}
16}