> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orq.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Guardrail Rules

> Configure guardrail rules in the AI Gateway to validate and control LLM requests and responses with evaluators triggered by CEL conditions.

Guardrail Rules define conditions under which [**Evaluators**](/docs/ai-studio/optimize/evaluators) (automated checks that inspect a request or response) run against requests passing through the [**AI Gateway**](/docs/ai-gateway/get-started/introduction). Conditions are written as CEL expressions, built visually with the Rule Builder covered below. A guardrail is only triggered when its rule conditions are matched, not on every request.

## Use cases

Guardrail rules are most useful when the same safety or compliance check needs to apply consistently across many requests.

<AccordionGroup>
  <Accordion title="Add jailbreak protection to all customer-facing banking traffic" icon="shield">
    Runs a jailbreak detection [**Evaluator**](/docs/ai-studio/optimize/evaluators) on all customer-facing requests at the gateway level, adding an extra security layer across **AI Gateway** traffic.
  </Accordion>

  <Accordion title="Enforce GDPR PII checks across the entire workspace" icon="lock">
    Enforces GDPR compliance by running PII detection on all matching requests workspace-wide from a single rule.
  </Accordion>

  <Accordion title="Validate customer detail access for the sales team" icon="users">
    Validates customer detail access for the sales team by calling an external [**Evaluator**](/docs/ai-studio/optimize/evaluators) on every matching request before it reaches the model.
  </Accordion>

  <Accordion title="Monitor tone of voice across all company traffic" icon="waveform">
    Applies a tone of voice [**Evaluator**](/docs/ai-studio/optimize/evaluators) at the gateway level so every response is checked against the company's tone guidelines.
  </Accordion>

  <Accordion title="Apply EU AI Act compliance checks to EU-routed requests" icon="scale-balanced">
    Runs a compliance [**Evaluator**](/docs/ai-studio/optimize/evaluators) on EU-routed requests only, scoped using the Rule Builder so the guardrail applies exactly where it is needed without affecting other traffic.
  </Accordion>

  <Accordion title="Run safety and quality checks on targeted traffic using metadata" icon="robot">
    Runs jailbreak detection and response relevance [**Evaluators**](/docs/ai-studio/optimize/evaluators) at 50% sample rate each, scoped to specific traffic using a metadata condition in the Rule Builder.
  </Accordion>
</AccordionGroup>

## Visibility

* Visible to workspace administrators only.

## Creating a guardrail rule

From the **Guardrail Rules** list, click <kbd className="key"><Icon icon="circle-plus" color="#fff" /> Add New Rule</kbd>. A panel opens on the right with the following fields.

<Frame caption="Create Guardrail Rule panel in the AI Gateway.">
  <img src="https://mintcdn.com/orqai/dycyWau_l9E63fTw/images/guardrail-rule-create.png?fit=max&auto=format&n=dycyWau_l9E63fTw&q=85&s=ab8de239478b0add2f9c33961145aa77" alt="Create Guardrail Rule" width="1525" height="1217" data-path="images/guardrail-rule-create.png" />
</Frame>

### General

| Field           | Description                                                                                                   |
| --------------- | ------------------------------------------------------------------------------------------------------------- |
| **Rule Name**   | A display name for the guardrail rule.                                                                        |
| **Description** | Optional context for administrators.                                                                          |
| **Enable Rule** | Toggle to activate or deactivate the rule. When enabled, the rule is active and applied to matching requests. |

### Evaluators

Select the [**Evaluators**](/docs/ai-studio/optimize/evaluators) to run when this rule is triggered. Click <kbd className="key"><Icon icon="circle-plus" color="#fff" /> Add</kbd> to attach one or more evaluators from the scoped project. The Add menu groups options into **System** and **Workspace**: Workspace evaluators are the project's custom evaluators; System guardrails are covered below.

#### System Guardrails

System Guardrails are the pre-built checks **Orq.ai** maintains in the Evaluators list's System group. Attach one and it runs immediately as a pass/fail check that can block a request; it never rewrites content.

| System Guardrail     | What it checks                                                                                                                   | Configurable                                                                                                                                                                        |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **PII Detection**    | Detects personally identifiable information in requests or responses and blocks the request by default, instead of redacting it. | Yes. Once added, a <Icon icon="sliders" /> icon appears next to it in the Evaluators list. Click it to set `language`, `regions`, `entities`, `threshold`, and `entity_thresholds`. |
| **Secret Detection** | Detects API keys, tokens, credentials, and other secrets in requests or responses and blocks the request by default.             | No configurable options.                                                                                                                                                            |

Toggle the <Icon icon="shield" /> icon next to a System Guardrail in the Evaluators list to switch it to monitoring-only mode. The same check still runs and its result is still recorded, but a match no longer blocks the request.

The detectable entity catalog for **PII Detection** is shared with the [**PII Redaction**](/docs/ai-gateway/features/plugins/pii-redaction#supported-entity-types) plugin, and is region-scoped rather than language-scoped. `GET /v2/pii/capabilities` is the live source of truth for the supported regions, base and regional entity types, and the `region_entities` mapping. A few [entity type names changed](/docs/ai-gateway/features/plugins/pii-redaction#entity-type-names-that-changed) when the catalog moved to regions; the old keys are rejected at write time.

Each guardrail runs on the request **Input**, the model **Output**, or both. Click the icon next to a guardrail in the Evaluators list to cycle through <kbd><Icon icon="arrow-up-right" color="#22c55e" /></kbd> **Input**, <kbd><Icon icon="arrow-down-left" color="#ef4444" /></kbd> **Output**, and <kbd><Icon icon="up-right-and-down-left-from-center" /></kbd> **Both**, set independently per guardrail.

<Warning>
  System Guardrails always fail closed: if the underlying check errors (for example the detection service is unavailable or the call itself fails), the guardrail blocks the request instead of letting it through unchecked.
</Warning>

### Rule Builder

The Rule Builder constructs the match conditions that determine when the guardrail is triggered. Clicking <kbd className="key"><Icon icon="circle-plus" color="#fff" /> Add</kbd> opens a dropdown with the following condition types:

| Condition    | Description                                |
| ------------ | ------------------------------------------ |
| **Header**   | Match on a request header name and value.  |
| **Model**    | Match on the model being called.           |
| **Identity** | Match on the identity making the request.  |
| **Metadata** | Match on metadata attached to the request. |
| **Project**  | Match on the project scope of the request. |

You can also click **Add group** to nest conditions into a logical group. Multiple conditions within a group are joined with `and`. Groups themselves can be joined with either `and` or `or`. Select the operator between groups to control how they combine. Each condition can be removed with <kbd><Icon icon="xmark" /></kbd>.

The builder generates a CEL (Common Expression Language) expression shown read-only in the **CEL Expression Preview** below. The guardrail is only triggered when the expression evaluates to true.
