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

# Guardrails

> Define safety rules that are evaluated on every request before it reaches the provider.

Guardrails protect your application from malicious input and ensure your outputs meet specific constraints. They are evaluated directly at the gateway layer, requiring no code changes in your app.

## Enforcement modes

When a guardrail matches, it can take one of two actions:

* **Block:** The gateway immediately halts the request and returns a `400 Bad Request` to your application. The upstream provider is never called, saving you money and tokens.
* **Log Only:** The request proceeds normally, but the guardrail match is flagged in your Request Logs. This is useful for testing a new rule before enforcing it.

## Scopes

A guardrail can be applied to:

* **Input:** Evaluates the prompt sent *to* the LLM.
* **Output:** Evaluates the response coming *from* the LLM.
* **Both:** Evaluates both the prompt and the response.

## Built-in guardrail types

<CardGroup cols={2}>
  <Card title="Keyword Blocklist" icon="list">
    Blocks requests/responses containing any word from a configurable list (case sensitive or insensitive).
  </Card>

  <Card title="Regex Match" icon="code">
    Matches content against a custom regular expression pattern.
  </Card>

  <Card title="Substring Match" icon="magnifying-glass">
    Blocks if the text contains a specific exact substring.
  </Card>

  <Card title="Length Constraints" icon="ruler">
    Enforces a minimum and maximum word count or character count.
  </Card>
</CardGroup>

## Configuring guardrails

<Steps>
  <Step title="Open Guardrails">
    In your workspace, go to the **Guardrails** page and click **New Guardrail**.
  </Step>

  <Step title="Set the rule">
    Give it a name, select the type (e.g. `word_count`), and configure the settings (e.g. `max: 500`).
  </Step>

  <Step title="Set enforcement">
    Choose whether the rule should apply to `Input`, `Output`, or `Both`, and select `Block` or `Log Only`.
  </Step>
</Steps>

Guardrails are evaluated in the order they appear on the page. The first guardrail set to **Block** that matches will immediately halt evaluation.
