Create and train an input guardrail

  • Updated

Create an input guardrail to enforce a content policy on the messages users send to Optimizely Opal. This article covers writing a rule, training a classifier, tuning the results, and testing the guardrail.

Access guardrails

To access guardrails in Opal, go to Agents > Input Guardrails.

Screenshot of the Input Guardrails tab

Create a guardrail

To create a guardrail, complete the following steps:

  1. Follow the steps in the Access guardrails section.
  2. Click Create Guardrail.
  3. Enter a Name for the guardrail, such as No competitor discussions.
  4. Enter the Rule in natural language. The rule describes the policy you want to enforce. See Write effective input guardrail rules.
  5. (Optional) Enter a Block message that users see when Opal blocks their input.
  6. Click Create.

    Screenshot of creating a new input guardrail with Create highlighted.

When you leave the block message blank, Opal generates a contextual, one-sentence explanation for each blocked message. This dynamic message tells the user why Opal blocked their message without revealing internal policy details. To switch to a static message later, edit the guardrail and enter one.

Each save creates an immutable version. Create new versions of the same guardrail to update rules without losing previous configurations.

Train the guardrail

After you create a guardrail version, train a classifier to enforce it.

  1. Follow the steps in the Access guardrails section.
  2. Click the guardrail version you want to train.
  3. Click Train to start the training pipeline.

    Screenshot of an Input Guardrail with Train highlighted
  4. Monitor the version status as it moves from Untrained to Training to Ready. Status updates display in real time.

    Screenshot of a Input Guardrail with Training - Synthesize highlighted.

Training runs in the background and takes several minutes. Opal runs one training job per instance at a time. When a job does not finish within 15 minutes, Opal retries it automatically up to three times before it marks the version Failed.

Opal decomposes your rule into a maximum of five atomic policies. When a rule is too broad and decomposes into more than five policies, training fails. To resolve this, simplify or narrow your rule text and train again.

Review training data

After training, review and refine the generated examples to improve accuracy. To view the training data, complete the following steps:

  1. Follow the steps in the Access guardrails section.
  2. Click the guardrail version whose training data you want to review.
  3. Expand Training Data to see the generated examples grouped by policy. Each example is labeled Blocked or Allowed.

    Screenshot of an input guardrail's training data

To generate a fresh set of examples, click Regenerate Training Data. This action creates a new version with fresh examples.

Add training data

To add your own example training data, complete the following steps:

  1. Click Add example.

    Screenshot of an input guardrail's training data with Add example highlighted.
  2. Enter the Prompt. The prompt is the message the guardrail should judge.
  3. Select Blocked or Allowed for the Decision.
  4. (Conditional) When you set the Decision to Blocked, select the Rule aspect.

    Screenshot of an input guardrail's add example training data
  5. Click Add.
  6. Click Save changes.

    Screenshot of an input guardrail with Save changes highlighted
  7. Click Train.

Saving changes to training data creates an untrained draft version. Retrain the guardrail for the changes to take effect.

Edit training data

To edit an individual training example, complete the following steps:

  1. (Optional) Enter a search term in the Search examples field to filter the list.
  2. Click the example you want to edit.

    Screenshot of the training data with one example highlighted
  3. Update the example.
  4. (Conditional) When you set the Decision to Blocked, select the Rule aspect.
  5. Click Save changes.
  6. Click Train.

Saving changes to training data creates an untrained draft version. Retrain the guardrail for the changes to take effect.

Delete training data

To delete an individual training example, complete the following steps:

  1. (Optional) Enter a search term in the Search examples field to filter the list.
  2. Click Delete for the example you want to remove.

    Screenshot of the training data for an input guardrail with delete highlighted
  3. Click Save changes.
  4. Click Train.

Saving changes to training data creates an untrained draft version. Retrain the guardrail for the changes to take effect.

Adjust sensitivity

After training, adjust the sensitivity for each policy within the guardrail by selecting Low, Medium, or High. The level you select changes how strictly the classifier enforces each policy.

  • Low – Allows more messages through. Reduces false positives but misses some violations.
  • Medium – Blocks clear violations while allowing borderline messages. Balances false positives and false negatives.
  • High – Blocks more messages, including borderline cases. Reduces false negatives but increases false positives.
Screenshot of an input guardrail's Sensitivity highlighted

Unlike edits to training data, sensitivity adjustments apply when you click Save changes and do not require retraining.

Test the guardrail

Before you activate a guardrail, test it against sample messages to verify it works as expected.

  1. Follow the steps in the Access guardrails section.
  2. Click the guardrail version you want to test.
  3. Click Test run.

    Screenshot of a Ready Input Guardrail with Test Run highlighted.
  4. Enter sample messages in the Test run panel.
  5. Click Test.

    Screenshot of an Input Guardrail's Test Run panel filled out and Test highlighted
  6. Review whether Opal classifies each message as blocked or allowed. Blocked messages display the block message, either static or dynamically generated.

    Screenshot of the Test run panel of an input guardrail with the Test being Blocked correctly.

Adjust sensitivity or retrain the guardrail when the results do not match your expectations.

Next steps

When your guardrail is ready, Activate an input guardrail for your instance or Assign an input guardrail to a specialized agent to use it.

Additionally, see the following related documentation: