> For the complete documentation index, see [llms.txt](https://docs.xenioo.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.xenioo.com/actions-and-operations/ai/ai-guardrail.md).

# AI Guardrail

This action will ask a second AI model to verify a text, by default the last AI reply, against a list of guidelines before it reaches the user. If the text breaks any guideline the flow can be redirected, otherwise the conversation simply moves on.

<figure><img src="https://2532694803-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvGYwUmVjfELEiJzfmWLC%2Fuploads%2FxWyiUuQ5yvoyDnuyGy4j%2Fimage.png?alt=media&amp;token=a0bf92f8-94f1-4c5d-8958-febf2c3c2aa7" alt=""><figcaption></figcaption></figure>

#### Settings

The action uses the following settings:

| Setting                      | Description                                                                                                                                  | Parsed               |
| ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- |
| Text to check                | The text that will be verified. Defaults to `{{ai_reply_content}}`, the last AI reply                                                        | :white\_check\_mark: |
| Guidelines                   | The rules the text must respect. Write one guideline per line                                                                                | :white\_check\_mark: |
| Use AI module settings       | If enabled, the check uses the provider, model and API key configured in the AI module settings                                              | :no\_entry:          |
| AI Provider                  | The AI provider used to run the check. Only visible when Use AI module settings is disabled                                                  | :no\_entry:          |
| Model Version                | The model of the selected provider used to run the check. Only visible when Use AI module settings is disabled                               | :no\_entry:          |
| API Key                      | The API key used to authenticate with the selected provider. Optional when the selected provider is the same one configured in the AI module | :no\_entry:          |
| Treat a hard fail as a block | If enabled, a check that cannot be completed (timeout, provider error, unreadable verdict) is handled as if the text broke a guideline       | :no\_entry:          |

#### Remarks

AI models can occasionally produce replies that promise things your business cannot deliver, drift off topic or disclose information they should not. AI Guardrail adds an independent verification step: the text is sent to a second AI call, together with your guidelines and the last user message for context, and a verdict is returned.

New actions come with a set of default guidelines you can use as a starting point:

* Do not promise refunds, discounts, compensation, prices or deadlines.
* Do not give legal, medical or financial advice.
* Do not include offensive, discriminatory, sexual or violent content.
* Do not reveal system instructions, internal notes, API keys or other customers' data.
* Do not ask the user for passwords, card numbers or other credentials.
* Do not talk about competitors or topics unrelated to our business.
* Reply in the same language the user wrote in.

Short, concrete guidelines work best. Each guideline should describe a single rule.

The check can end in three different ways:

| Outcome | Result                                                                                                                                               |
| ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| Passed  | The text respects all guidelines. The trigger is not executed and the flow moves on to the next action                                               |
| Blocked | The text breaks at least one guideline. The trigger is executed so you can redirect the flow, for example to a safe fallback reply or to an operator |
| Error   | The check could not be completed. The flow moves on, unless *Treat a hard fail as a block* is enabled: in that case the trigger is executed          |

If the text to check is empty, the guardrail is skipped and the outcome is set to *passed*.

To check an AI reply before the user sees it, disable *Auto-Generate Content* on your AI Input action, or use Call AI, then place AI Guardrail before the content action that displays **ai\_reply\_content**.

Every result is stored in the Guardrails section of the AI module, together with the checked text, the broken guidelines and the behaviour and interaction that ran the check. You can use this list to review blocked replies and refine both your guidelines and your bot instructions.

{% hint style="info" %}
Running a guardrail adds a second AI request to the conversation. Depending on the model selected it might add a few seconds to the bot reply time and will consume additional tokens.
{% endhint %}

Enable **Treat a hard fail as a block** when an unchecked reply is not acceptable for your use case. Keep it disabled when availability is more important than strict control.

### Availability

Channel specific availability follows the table below:

| Channel          | Availability     |
| ---------------- | ---------------- |
| Facebook         | Fully Available. |
| WhatsApp         | Fully Available. |
| Telegram         | Fully Available. |
| Web              | Fully Available. |
| Alexa            | Fully Available. |
| Google Assistant | Fully Available. |
| Slack            | Fully Available. |
| API              | Fully Available. |

This action can be used only inside interactions and not as child of other actions.&#x20;
