Appearance
Guard Rails
Guard rails are safety rules that evaluate user input before it reaches your main LLM response pipeline. Each guard rail uses an LLM classifier to determine if the user's input matches a rule, and can trigger corrections, response overrides, and email alerts.
Overview
Guard rails protect your chat widget from:
- Inappropriate or harmful content
- Personal information sharing (PII)
- Off-topic questions
- Competitor mentions
- Any custom rule you define
How It Works
- User sends a message through the chat widget.
- All enabled guard rails are evaluated in parallel using a lightweight LLM classification call.
- If any guard rail is triggered:
- Correction prompts are injected into the system prompt to steer the response
- Response overrides completely replace the LLM response
- Email alerts are sent to configured contacts
- The trigger count is incremented for each triggered rail.
Configuration
Each guard rail has the following fields:
| Field | Type | Description |
|---|---|---|
name | string | Short identifier for the rule |
description | string | What the guard rail detects (used as the LLM classifier prompt) |
severity | enum | "low", "medium", "high", "critical" |
correction_prompt | string | Text injected into the system prompt when triggered |
response_override | string | Completely replaces the LLM response when triggered |
email_contacts | string[] | Email addresses to notify when triggered |
enabled | boolean | Toggle the guard rail on/off |
trigger_count | integer | How many times this rail has been triggered (read-only) |
API Access
Guard rails can be fully managed via API:
GET /guard-rails— List all guard railsPOST /guard-rails— Create a new guard railPUT /guard-rails/:id— Update a guard railDELETE /guard-rails/:id— Delete a guard railPOST /guard-rails/:id/test— Test a guard rail against sample input
See the API Reference for full details.
Testing
Use the test endpoint to verify a guard rail behaves as expected before enabling it:
bash
curl -X POST https://api.canny.bot/api/guard-rails/abc123/test \
-H "x-api-key: <your_api_key>" \
-H "Content-Type: application/json" \
-d '{"input": "What is your social security number?"}'
The response includes whether the rail was triggered, the correction prompt, and any response override.