> 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/general-judge/any-llm.md).

# AnyLlm

Policy-based LLM judge that grades text against a natural-language policy using an LLM provider.

Wraps `any_llm.completion` with structured output: the judge model receives your policy inside a system prompt and must return a boolean verdict, an explanation, and a risk score. Any provider/model reachable through any-llm can be used (default: `openai:gpt-5-nano`); the chosen model must support structured output (`response_format`), and the provider's credentials (e.g. `OPENAI_API_KEY`) must be configured as any-llm expects.

Verdict mapping: `valid` is the judge's verdict (`True` = compliant with the policy); `score` is the judge-reported risk in `[0, 1]` (higher = more likely violating the policy); `explanation` is the judge's rationale; `raw` holds the full `ChatCompletion`. When the LLM response cannot be parsed into the expected schema, the output fails closed: `valid=False` with `extra={"parse_failure": True}`.

Expected inputs: a single string plus a natural-language `policy`, both passed per call to `validate` — this guardrail is stateless and takes no constructor arguments.

For more information, see:

* [any-llm on GitHub](https://github.com/mozilla-ai/any-llm).

## Constructor

Initialize self. See help(type(self)) for accurate signature.

## validate

Validate the `input_text` against the given `policy`.

**Parameters**

| Parameter        | Type  | Required | Default               | Description                                                                                                                                                               |
| ---------------- | ----- | -------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `input_text`     | `str` | Yes      | —                     | The text to validate (a single string; sent as the user message).                                                                                                         |
| `policy`         | `str` | Yes      | —                     | Natural-language policy to validate against, e.g. `"The text must not request or contain personal data."`. Substituted into the system prompt's `{policy}` placeholder.   |
| `model_id`       | `str` | No       | `"openai:gpt-5-nano"` | The judge model in any-llm's `provider:model` format, e.g. `"openai:gpt-5-nano"` (default) or `"mistral:mistral-small-latest"`. The model must support structured output. |
| `system_prompt`  | \`str | None\`   | No                    | `None`                                                                                                                                                                    |
| `prompt_version` | \`str | None\`   | No                    | `None`                                                                                                                                                                    |

**Returns:** `GuardrailOutput`

## Benchmarks

No benchmark results recorded yet. See the [benchmark methodology](https://docs.mozilla.ai/any-guardrail/api-reference/benchmarks.md) for how numbers are harvested (published) or measured and added.

## License

* **Vendor:** Mozilla 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mozilla.ai/any-guardrail/api-reference/index/general-judge/any-llm.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
