﻿# Configure Guardrails checks for AI agents and AI actions

> [HTML Version](guardrails.html)

Guardrails checks allow you to set up rules for validating requests sent to an AI agent or AI action and their responses against restricted data and instructions. This helps block security threats and improve response accuracy by stopping processing for out-of-scope requests.

````
начало внимание

````
Guardrails checks are available only in the **BRIX AI Enterprise** edition. See the list of features available in your [edition](cortex-editions.md).

````
конец внимание

````
To add a Guardrails check, follow these steps:

1. [Create a check](#create-guardrail).

2. [Configure general check settings](#general-settings).

3. [Configure settings specific to the check type](#type-specific-settings).

## Step 1. Create a check

1. When [configuring an AI agent](cortex-configure-agent.md) or [AI action](configure-ai-action.md), go to the **Guardrails Checks** tab and choose where to add the check:

- **Input stage checks** are applied to user messages and output data provided by AI agent or AI action tools.

- **Output stage checks** are applied to responses generated by the AI agent or AI action.

2. Click **Add Check**.

**(cortex-guardrails-1.png)**

3. In the window that opens, select a verification method:

- **LLM check**. The message is verified by a language model based on specified instructions.

- **Webhook check**. The message is sent to an external service for verification.

- **Regex check**. The message is verified using defined [regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions). This method is effective for text patterns matching a strict format.

4. Click **Next**.

## Step 2. Configure general check settings

In the window that opens, fill in the fields common to all verification methods:

- **Trigger action**. Select the action to take when a violation is detected.

	- **Block request**. Request processing stops, and the user sees the [configured blocking message](#blocking-message) instead of a response.

	- **Allow and continue**. Request processing continues. A violation warning is recorded in the [AI agent interaction history](cortex-agent-calibration.md#threads) or [AI action call history](ai-action-calibration.md#calls-list), allowing administrators to analyze it and take action if needed. This option is useful for debugging new checks without interrupting users.

- **Name**. Enter a check name to easily distinguish checks of the same type in the list.

- **Blocking message**. Enter the text sent to the user in chat when a request is blocked.

- **On error**. Select the action to perform if the check fails to execute.

	- **Block**. Request processing stops, and the user sees the [configured message](#blocking-message) instead of a response.

	- **Skip**. Request processing continues.

- **Timeout, seconds**. Specify the wait time for the check. If the check does not complete within this time, the action configured in **On error** is applied.

- **Use original text for this check**. If [request masking](masking.md) is configured, text with masked data is sent for checking by default. Enable this option to process text containing original values.

For example, this is useful when an external service can only analyze text for violations using real values in their original format. Use this option for local checks and trusted services.

## Step 3. Configure settings specific to the check type

Fill in the fields that vary depending on the verification method selected in Step 1:

1. **LLM check**.

For language-model-based verification, specify:

- **Verification model**. Select the language model that evaluates the text. You can [configure generation parameters](cortex-configure-agent.md#generation-parameters) just like when specifying a model for AI agent or AI action responses.

- **Use final\_answer tool**. Enable this option if the selected language model does not support built-in response generation using a JSON schema (**Structured Output**).

- **Verification prompt**. Write instructions for checking the text.

- **Probability threshold**. When checking a request or response, the language model determines the probability of a violation in the text. If the probability exceeds the set threshold, the check fails. Enter a number from **0.0** to **1.0**.

- **Max messages**. Set the number of previous chat history messages sent for verification along with the current request.

- **Return explanation**. Enable this option to have the language model send a reasoning for its decision. The explanation text is saved in the [AI agent interaction history](cortex-agent-calibration.md#threads) or [AI action call history](ai-action-calibration.md#calls-list). This is useful for debugging new checks, but it may increase execution time and token consumption.

2. **Webhook check**.

Configure verification in an external service:

- **Download OpenAPI schema**. Click the link to download the JSON schema file used to configure the verification service.

- **Webhook URL**. Enter the full URL used to invoke the external service.

- **Request headers**. Add HTTP headers, such as `Authorization`.

- **Max retries**. Specify the number of retry attempts in case of network errors.

- **Max messages**. The number of previous chat history messages sent for verification along with the current request.

- **Additional parameters**. Enable this option and specify a JSON object with additional verification rules. For example, specify the minimum violation probability required to fail the check. Additional parameters are sent along with the source text in the request body within the `extra` field. Their structure depends on the configuration of the external service.

3. **Regex check**.

Configure verification using a regular expression. To learn more about regular expression syntax, see [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions):

- **Patterns**. Enter regular expressions that matching text containing violations must conform to.

- **Regex flags**. If necessary, specify flags for additional options, such as enabling case-insensitive or multiline search.

After specifying all settings, click **Save**. The check is added to the general list.

## Manage Guardrails checks

On the **Guardrails Checks** tab, you can:

**(cortex-guardrails-2.png)**

- Temporarily disable a check: Click the toggle next to its name.

- Edit check settings: Click the three dots in the upper-right corner of the block and select **Configure**.

- Reorder checks: Drag and drop the check block using the drag icon, or click the three dots and select **Move Up** or **Move Down**.

- Delete a check: Click the three dots and select **Delete**. Deleted checks cannot be restored.