Skip to content
On this page

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

  1. User sends a message through the chat widget.
  2. All enabled guard rails are evaluated in parallel using a lightweight LLM classification call.
  3. 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
  4. The trigger count is incremented for each triggered rail.

Configuration

Each guard rail has the following fields:

FieldTypeDescription
namestringShort identifier for the rule
descriptionstringWhat the guard rail detects (used as the LLM classifier prompt)
severityenum"low", "medium", "high", "critical"
correction_promptstringText injected into the system prompt when triggered
response_overridestringCompletely replaces the LLM response when triggered
email_contactsstring[]Email addresses to notify when triggered
enabledbooleanToggle the guard rail on/off
trigger_countintegerHow 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 rails
  • POST /guard-rails — Create a new guard rail
  • PUT /guard-rails/:id — Update a guard rail
  • DELETE /guard-rails/:id — Delete a guard rail
  • POST /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.