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

# Types

Runtime-validated wrappers used throughout the pipeline and the output type returned by every guardrail.

A machine-readable JSON Schema for `GuardrailOutput` (generated from these models) is published at <https://raw.githubusercontent.com/mozilla-ai/any-guardrail/main/schemas/guardrail_output.schema.json>. Pin a release tag in the URL for a specific version.

## GuardrailOutput

Represents the output of a guardrail evaluation with runtime validation.

This is the single concrete result shape shared by every guardrail implementation, so application code can swap guardrails without changes.

Example: >>> output = GuardrailOutput(valid=True, explanation="Content is safe", score=0.05) >>> output.valid True

| Field           | Type                   | Description |
| --------------- | ---------------------- | ----------- |
| `valid`         | `bool`                 |             |
| `explanation`   | \`str                  | None\`      |
| `score`         | \`float                | None\`      |
| `categories`    | `list[CategoryResult]` |             |
| `spans`         | \`list\[SpanResult]    | None\`      |
| `modified_text` | \`str                  | None\`      |
| `action`        | \`str                  | None\`      |
| `usage`         | \`GuardrailUsage       | None\`      |
| `extra`         | \`dict\[str, Any]      | None\`      |
| `raw`           | \`Any                  | None\`      |

## CategoryResult

Result for one taxonomy category evaluated by a guardrail.

Categories give multi-label and taxonomy guardrails (DuoGuard, Llama Guard S-codes, Azure severities, binary classifiers' label distributions) a lossless, uniform home instead of overloading `explanation`.

Example: >>> CategoryResult(name="S1", description="Violent Crimes", triggered=True)

| Field         | Type    | Description |
| ------------- | ------- | ----------- |
| `name`        | `str`   |             |
| `description` | \`str   | None\`      |
| `triggered`   | \`bool  | None\`      |
| `score`       | \`float | None\`      |
| `severity`    | \`int   | None\`      |

## SpanResult

A character span flagged by a guardrail.

Reserved for span-producing guardrails (PII/NER detection, span-level toxicity, token classification). Offsets are zero-based character indices into the validated text.

| Field   | Type    | Description |
| ------- | ------- | ----------- |
| `start` | `int`   |             |
| `end`   | `int`   |             |
| `text`  | \`str   | None\`      |
| `label` | \`str   | None\`      |
| `score` | \`float | None\`      |

## GuardrailUsage

Provenance and cost envelope for one `validate()` call.

| Field               | Type    | Description |
| ------------------- | ------- | ----------- |
| `model_id`          | \`str   | None\`      |
| `latency_ms`        | \`float | None\`      |
| `prompt_tokens`     | \`int   | None\`      |
| `completion_tokens` | \`int   | None\`      |

## GuardrailPreprocessOutput

Wrapper for preprocessing outputs with runtime validation.

This class wraps the output of the preprocessing stage, providing runtime validation and a consistent interface across all guardrail implementations.

Type Parameters: PreprocessT: The type of the preprocessing result (e.g., tokenized input, API options, chat messages).

Example: >>> output = GuardrailPreprocessOutput(data={"input\_ids": tensor, "attention\_mask": tensor}) >>> output.data\["input\_ids"]

| Field  | Type           | Description |
| ------ | -------------- | ----------- |
| `data` | `~PreprocessT` |             |

## GuardrailInferenceOutput

Wrapper for inference outputs with runtime validation.

This class wraps the output of the inference stage, providing runtime validation and a consistent interface across all guardrail implementations.

Type Parameters: InferenceT: The type of the inference result (e.g., model logits, API response, generated tokens).

Example: >>> output = GuardrailInferenceOutput(data=model\_output) >>> logits = output.data\["logits"]

| Field  | Type          | Description |
| ------ | ------------- | ----------- |
| `data` | `~InferenceT` |             |


---

# 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:

```
GET https://docs.mozilla.ai/any-guardrail/api-reference/types.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
