Clavata Integration
Clavata provides real-time moderation capabilities allowing anyone to detect and filter content. The exact rules of what to filter are up to you, but we do provide a number of rulesets for common issues.
This integration enables NeMo Guardrails to use Clavata for content moderation, topic moderation, and dialog moderation in both input and output flows.
Getting Access
To sign up for Clavata or obtain an API key:
- Request access through the website
- Contact support at hello@clavata.ai
Setup
-
Ensure you have access to the Clavata platform and have configured your content moderation policies. You’ll need:
- Your Clavata API key
- Policy IDs for the content types you want to moderate
- (Optional) A custom server endpoint if provided by Clavata.ai
-
Set the
CLAVATA_API_KEYenvironment variable with your Clavata API key: -
Configure your
config.ymlaccording to the following example:
Configuration Details
server_endpoint: The Clavata API endpoint (only if provided by Clavata.ai)policies: Map of policy aliases to each policy’s unique ID in your Clavata.ai accountlabel_match_logic: (Optional)ALLrequires all labels specified for a rail to match,ANYrequires at least one match. Defaults toANYif not set.input/output: Flow-specific configurationspolicy: The policy alias to use for this flowlabels: (Optional) List of specific labels to check for
Usage
The Clavata integration provides two ways to implement content moderation:
1. Built-in Flows
For users of Colang 1.0
Add these flows to your configuration to automatically check content when using Colang 1.0:
For users of Colang 2.0
If you’re using Colang 2.0, there’s no need to specify configuration for input and output rails in your config.yml. In fact, doing so is now deprecated. The good news is that because Colang 2.0 supports flows with variables, you can specify which policy to use (and even which labels to match) inline in the definitions for any of your rails (i.e., input, output, dialog, etc.)
Here’s an example of how to configure an input rail to check against a specific Clavata policy:
The same is true for
outputflows, of course. See our example for more.
2. Programmatic Usage
If you are using colang 2.x, you can make use of the Clavata action in your own flows:
The action returns True if the content matches the specified policy’s criteria.
Customization
You can customize the content moderation behavior by:
- Configuring different policies for input and output flows
- Specifying which labels must match within a policy
- Setting the label match logic to either “ALL” (all specified labels must match) or “ANY” (at least one label must match)
Error Handling
If the Clavata API request fails, the system will raise a ClavataPluginAPIError. The integration will also raise a ClavataPluginValueError if there are configuration issues, such as:
- Invalid policy aliases
- Missing required configuration
- Invalid flow types
Notes
- Ensure that your Clavata API key is properly set up and accessible
- The integration currently supports content moderation checks for input and output flows
- You can configure different policies and label requirements for input and output flows
- If no labels are specified for a policy, any label match will be considered a hit
For more information on Clavata and its capabilities, please refer to the Clavata documentation.