> 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/wild-guard.md).

# WildGuard

One-pass safety-moderation judge reporting prompt harm, response harm, and refusal.

WildGuard is a generative safety classifier that evaluates a prompt-response interaction in a single forward pass, reporting three signals: (1) whether the user request is harmful, (2) whether the assistant response is a refusal, and (3) whether the assistant response is harmful. It is trained on the WildGuardMix dataset and covers both vanilla (direct) prompts and adversarial jailbreaks.

Verdict mapping onto `GuardrailOutput`:

* `valid` is `False` when the request is harmful, or — when an `output_text` response is supplied — when the response is harmful; `True` otherwise.
* `categories` surfaces the three parsed signals as `triggered` booleans: `harmful_request`, `harmful_response`, and `response_refusal`.
* `explanation` holds WildGuard's raw generation (the `Harmful request: ... / Response refusal: ... / Harmful response: ...` block).
* `score` is left `None` — WildGuard emits categorical yes/no verdicts rather than a calibrated risk probability.
* `usage` records the prompt/completion token counts when the backend reports them.
* Fails closed (`valid=False` with `extra={"parse_failure": True}`) when the always-present request verdict is missing, or when a response was being judged but its harm verdict could not be parsed (so a response is never silently passed as safe).

Expected inputs: a single `input_text` (the user request; required) plus an optional `output_text` (the assistant response). With no `output_text` only the request is judged and the response-side signals may be absent. List/batch input is not supported — passing a list raises `TypeError`.

Caveat: WildGuard ships its own instruction wrapper instead of a chat template, so the prompt is fed to the model verbatim (`apply_chat_template=False`). That makes it HuggingFace-only: `LlamafileProvider` rejects `apply_chat_template=False`.

For more information, see:

* [WildGuard model card](https://huggingface.co/allenai/wildguard)
* [WildGuard: Open One-Stop Moderation Tools for Safety Risks, Jailbreaks, and Refusals of LLMs (arXiv:2406.18495)](https://arxiv.org/abs/2406.18495)

## Supported Models

* `allenai/wildguard`

## Constructor

| Parameter        | Type                                                 | Required | Default | Description                                                                                                                                                                                                                                                                                          |
| ---------------- | ---------------------------------------------------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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 the model as a causal LM. When a `HuggingFaceProvider` is supplied, it is loaded with `model_class=AutoModelForCausalLM` / `tokenizer_class=AutoTokenizer` so its default sequence-classification loader is corrected. |
| `prompt`         | \`PromptTemplate                                     | None\`   | No      | `None`                                                                                                                                                                                                                                                                                               |
| `prompt_version` | \`str                                                | None\`   | No      | `None`                                                                                                                                                                                                                                                                                               |

Initialize the WildGuard guardrail.

## validate

Classify a user request and, optionally, the assistant response to it.

**Parameters**

| Parameter     | Type  | Required | Default | Description                                                                                                                |
| ------------- | ----- | -------- | ------- | -------------------------------------------------------------------------------------------------------------------------- |
| `input_text`  | `str` | Yes      | —       | The user request to judge, e.g. `"How do I pick a lock?"`. A single string; list/batch input is rejected with `TypeError`. |
| `output_text` | \`str | None\`   | No      | `None`                                                                                                                     |

**Returns:** `GuardrailOutput`

## Benchmarks

### Content Safety

| Dataset (rev)                    | Metric | Threshold    | Value    | Harness                 | Source                           | Contam. |
| -------------------------------- | ------ | ------------ | -------- | ----------------------- | -------------------------------- | ------- |
| openai\_moderation (unspecified) | f1     | native-valid | 0.816327 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| xstest (unspecified)             | fpr    | native-valid | 0.012    | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| wildguardmix (unspecified)       | f1     | native-valid | 0.955932 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 | ⚠️      |
| aegis (unspecified)              | f1     | native-valid | 0.860606 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| jbb (unspecified)                | f1     | native-valid | 0.811475 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| orbench (unspecified)            | fpr    | native-valid | 0.789474 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |

## License

* **Vendor:** Allen Institute for AI
* **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/wild-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.
