> For the complete documentation index, see [llms.txt](https://docs.mozilla.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mozilla.ai/any-guardrail/api-reference/index/content-safety/qwen3-guard.md).

# Qwen3Guard

Generative safety moderation with three-level severity across 119 languages.

Decoder LLM (Apache-2.0) whose chat template embeds the safety-classifier instruction: the user prompt alone triggers prompt moderation; supplying an assistant `output_text` switches to response moderation. The model reports a severity (`Safe` / `Controversial` / `Unsafe`, where `Controversial` means harmfulness is context-dependent), the violated categories from a nine-item taxonomy (Violent, Non-violent Illegal Acts, Sexual Content or Sexual Acts, PII, Suicide & Self-Harm, Unethical Acts, Politically Sensitive Topics, Copyright Violation, plus Jailbreak for prompt moderation), and — in response mode — whether the response is a refusal.

`GuardrailOutput` mapping: `valid` is `True` only for `Safe` verdicts (`Controversial` also passes when `strict=False`); `score` maps the severity onto the canonical risk axis, higher = riskier (Safe 0.0, Controversial 0.5, Unsafe 1.0); `categories` holds one triggered entry per reported category (plus a `refusal` entry in response mode); `extra["severity"]` carries the verbatim severity and `explanation` the full generation. Fails closed (`valid=False` with `extra={"parse_failure": True}`) when no severity parses. For the token-level streaming variants (`Qwen3Guard-Stream-*`), see `Qwen3GuardStream`.

For more information, see:

* [Qwen3Guard-Gen-0.6B model card](https://huggingface.co/Qwen/Qwen3Guard-Gen-0.6B) (default).
* [Qwen3Guard-Gen-4B model card](https://huggingface.co/Qwen/Qwen3Guard-Gen-4B).
* [Qwen3Guard-Gen-8B model card](https://huggingface.co/Qwen/Qwen3Guard-Gen-8B).
* [Qwen3Guard Technical Report](https://arxiv.org/abs/2510.14276).

## Supported Models

* `Qwen/Qwen3Guard-Gen-0.6B`
* `Qwen/Qwen3Guard-Gen-4B`
* `Qwen/Qwen3Guard-Gen-8B`

## Constructor

| Parameter  | Type                                                 | Required | Default | Description                                                                                                                                                                              |
| ---------- | ---------------------------------------------------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `strict`   | `bool`                                               | No       | `True`  | If `True` (default), only `Safe` verdicts pass validation; set `False` to let `Controversial` content pass (`valid=True`), leaving it reflected only in `score` and `extra["severity"]`. |
| `model_id` | \`str                                                | None\`   | No      | `None`                                                                                                                                                                                   |
| `provider` | `Optional[Provider[dict[str, Any], dict[str, Any]]]` | No       | `None`  | Optional pre-configured provider. Defaults to a `HuggingFaceProvider` loading a causal LM.                                                                                               |

Initialize the Qwen3Guard guardrail.

## validate

Moderate `input_text` (or, when `output_text` is given, the assistant response to it).

**Parameters**

| Parameter     | Type  | Required | Default |
| ------------- | ----- | -------- | ------- |
| `input_text`  | `str` | Yes      | —       |
| `output_text` | \`str | None\`   | No      |

**Returns:** `GuardrailOutput`

## Benchmarks

### Content Safety

| Dataset (rev)                    | Metric | Threshold    | Value    | Harness                 | Source                           | Contam. |
| -------------------------------- | ------ | ------------ | -------- | ----------------------- | -------------------------------- | ------- |
| openai\_moderation (unspecified) | f1     | native-valid | 0.797508 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| xstest (unspecified)             | fpr    | native-valid | 0.128    | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| wildguardmix (unspecified)       | f1     | native-valid | 0.969072 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| aegis (unspecified)              | f1     | native-valid | 0.863222 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| jbb (unspecified)                | f1     | native-valid | 0.760456 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| orbench (unspecified)            | fpr    | native-valid | 0.814035 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |

## License

* **Vendor:** Qwen
* **Default license:** `apache-2.0` (of the default model/service)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mozilla.ai/any-guardrail/api-reference/index/content-safety/qwen3-guard.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
