> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://www.comet.com/docs/opik/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://www.comet.com/docs/opik/_mcp/server.

# Policies

A **policy** is a named group of one or more guards, stored in your Opik workspace. Your application references the policy by name rather than spelling out the checks itself.

That splits the work cleanly in two. Policies are created and edited **in the Opik UI**, and the SDK's job is to fetch them and run the checks. Changing what a guardrail enforces — adding an entity, tightening a threshold, switching a model — is something a teammate does in the UI, with no code change and no redeploy.

This is how we recommend running guardrails. It keeps the checks visible to everyone on the team, lets you tighten them in response to something you saw in production without waiting on a release, and applies the same protection consistently across every application that references the policy.

![](https://fdr-prod-docs-files-public.s3.us-east-1.amazonaws.com/opik.docs.buildwithfern.com/21f9ed08c3b790a067ab566f8daf222b3990354e15b7ab9499e4bcc6fd2a3265/img/guardrails/policies-table.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIA6KXJSKKNFOCF7G4B%2F20260920%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260920T231149Z&X-Amz-Expires=604800&X-Amz-Signature=d1fb35627aad570ccebf92e2ed4566310caaf196c770e01318efc128206cb6e9&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject)

## Create a policy

Open **Guardrails** in the sidebar and stay on the **Policies** tab, then choose **Create policy**.

A policy has a name, an optional description, an execution mode, and the guards it runs.

#### Name it

The name is what your application passes to the SDK, so pick something that reads well in code — `no-contact-information`, `support-tone`. Names are unique within a workspace.

Applications reference a policy by name. Renaming a policy that is already in use breaks every application still asking for the old name, so treat the name as part of your public interface.

#### Choose an execution mode

* **On request** — the policy applies only to applications that name it. This is the default.
* **Always** — the policy applies to every application in the workspace, whether or not it names the policy. Use this for baseline protection you want enforced everywhere, such as blocking personal data.

#### Switch on the guards it runs

Turn on the checks you want and configure each one. A policy holds at most one guard of each type, so a policy is a set of distinct checks rather than a list that can repeat.

![](https://fdr-prod-docs-files-public.s3.us-east-1.amazonaws.com/opik.docs.buildwithfern.com/be015366e7565053895392728bae4cfd9d10630cb85f7dad7be6f4c8afdc0da9/img/guardrails/policy-configuration.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIA6KXJSKKNFOCF7G4B%2F20260920%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260920T231149Z&X-Amz-Expires=604800&X-Amz-Signature=3a4605b51e5bcd11ad008859eec6f86456e9b063b1d3508979456b2f405b1669&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject)

Most guards take a **threshold** — the score at or above which the guard fails. Lower is stricter. The other fields depend on the type: PII asks which categories of personal data to block, Topic takes lists of allowed and restricted topics, the LLM judge takes your rule in plain language plus a model, and the custom classifier takes one of your models.

The five types are described in full on the [Guards](/guardrails/guardrails) page. The **LLM judge** guard needs a model from the providers configured under [AI Providers](/administration/workspace-settings/ai_providers), and the **custom classifier** guard needs one of your [custom models](/guardrails/custom-guardrails).

Rather than putting every check into one large policy, split them by what they protect against. A guardrail can be built from several policies at once, and small policies are far easier to reuse across applications.

## Use a policy in your application

Build a guardrail from stored policies with `Guardrail.from_stored_policies`, then call `validate` exactly as you would with a guardrail defined in code:

```python
from opik.guardrails import Guardrail
from opik import exceptions

guardrail = Guardrail.from_stored_policies(names=["no-contact-information"])

try:
    guardrail.validate("Call me at 555-0123")
except exceptions.GuardrailValidationFailed as e:
    print("Guardrail failed:", e)
```

Pass several names to combine policies. Their guards are checked together as one set, and the guardrail fails if any single guard fails:

```python
guardrail = Guardrail.from_stored_policies(
    names=["no-contact-information", "support-tone"],
)
```

Policies set to **Always** are included automatically, so a workspace-wide rule applies even to an application that names nothing:

```python
# Runs every "Always" policy in the workspace
guardrail = Guardrail.from_stored_policies()
```

A few things worth knowing about the call:

* Policies are read **once**, when you build the guardrail. Build it at startup rather than on every request, and restart (or rebuild the guardrail) to pick up a change made in the UI.
* Every name you pass must exist. A name that does not is an error, rather than a check quietly not running.

## Manage policies

The **Policies** tab lists every policy in the workspace with the guards it holds, its execution mode, and who last changed it. Selecting a row opens the policy for editing, and the row menu offers **Duplicate** — a quick way to build a variant without retyping the guards.

Saved changes apply to every application that references the policy the next time it builds its guardrail.

## Next steps

#### [Guards](/guardrails/guardrails)

What each of the five guard types checks, and how to configure it.

#### [Custom models](/guardrails/custom-guardrails)

Fine-tune a model for a check the built-in guards do not cover.