> 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/gpt-oss-safeguard.md).

# gpt-oss-safeguard

Policy-grounded reasoning safety classifier that judges text against a bring-your-own written policy.

A reasoning LLM that classifies content against a written `policy` supplied at construction (bring-your-own-taxonomy). The policy becomes the system message; the model reasons (OpenAI harmony format) and emits a verdict. A short output instruction is appended so the reply ends with `VIOLATION` or `SAFE`.

Verdict mapping onto `GuardrailOutput`:

* `valid` is `True` on `SAFE` and `False` on `VIOLATION`.
* `categories` holds a single `policy_violation` entry (`triggered=True` on `VIOLATION`).
* `score` is not populated — the model emits a discrete verdict, not a calibrated probability.
* `extra["verdict"]` carries the raw verdict string and `explanation` the full generation, including the model's reasoning.
* Fails closed (`valid=False` with `extra={"parse_failure": True}`) when no verdict parses.

Input is a single string `input_text` (the content to moderate, sent as the user message); list/batch input is not supported, and there is no separate response argument — include any conversation context in the text itself.

Note: the 120B variant is large; `gpt-oss-safeguard-20b` is the practical default.

For more information, see the model cards:

* [gpt-oss-safeguard-20b](https://huggingface.co/openai/gpt-oss-safeguard-20b) (default).
* [gpt-oss-safeguard-120b](https://huggingface.co/openai/gpt-oss-safeguard-120b).

## Supported Models

* `openai/gpt-oss-safeguard-20b`
* `openai/gpt-oss-safeguard-120b`

## Constructor

| Parameter  | Type                                                 | Required | Default | Description                                                                                                                                                                                                                                                                                                       |
| ---------- | ---------------------------------------------------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `policy`   | `str`                                                | Yes      | —       | The written safety policy (bring-your-own-taxonomy) the model evaluates content against — e.g. a numbered list of disallowed-content rules with definitions and examples. It is installed as the system message, with a short output instruction appended so the model ends its reply with `VIOLATION` or `SAFE`. |
| `model_id` | \`str                                                | None\`   | No      | `None`                                                                                                                                                                                                                                                                                                            |
| `provider` | `Optional[Provider[dict[str, Any], dict[str, Any]]]` | No       | `None`  | Optional pre-configured provider (e.g. a `LlamafileProvider` or a customized `HuggingFaceProvider`). Defaults to a `HuggingFaceProvider` loading the model with `AutoModelForCausalLM`/`AutoTokenizer`; when a `HuggingFaceProvider` is supplied, the causal-LM loader classes are enforced at load time.         |

Initialize the gpt-oss-safeguard guardrail.

## validate

Classify `input_text` against the configured policy.

**Parameters**

| Parameter    | Type  | Required | Default | Description                                                                                                                             |
| ------------ | ----- | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `input_text` | `str` | Yes      | —       | The content to moderate, sent as the user message beneath the policy system message. Single string only; list input raises `TypeError`. |

**Returns:** `GuardrailOutput`

## Benchmarks

### Content Safety

| Dataset (rev)                    | Metric | Threshold    | Value    | Harness                 | Source                           | Contam. |
| -------------------------------- | ------ | ------------ | -------- | ----------------------- | -------------------------------- | ------- |
| openai\_moderation (unspecified) | f1     | native-valid | 0.825    | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| xstest (unspecified)             | fpr    | native-valid | 0.1      | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| wildguardmix (unspecified)       | f1     | native-valid | 0.916364 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| aegis (unspecified)              | f1     | native-valid | 0.775665 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| jbb (unspecified)                | f1     | native-valid | 0.817308 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| orbench (unspecified)            | fpr    | native-valid | 0.438596 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |

### General Judge

| Dataset (rev)              | Metric           | Threshold    | Value    | Harness                 | Source                           | Contam. |
| -------------------------- | ---------------- | ------------ | -------- | ----------------------- | -------------------------------- | ------- |
| judgebench (unspecified)   | choice\_accuracy | native-valid | 0.659649 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| llmbar (unspecified)       | choice\_accuracy | native-valid | 0.74386  | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |
| rewardbench2 (unspecified) | choice\_accuracy | native-valid | 0.473684 | guardrail-bench+ag0.7.4 | measured:guardrail-bench+ag0.7.4 |         |

## License

* **Vendor:** OpenAI
* **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/gpt-oss-safeguard.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.
