The built-in moderation rules cover most content risks, but some violations are specific to your business. Use keyword libraries to define custom terms that the Text Moderation API should flag or ignore during text analysis.
Prerequisites
Before you begin, ensure that you have:
Access to the Guardrails console
A service configured under Protection Configuration > Configuration (required to attach libraries)
Limits
| Item | Limit |
|---|---|
| Libraries per account | 20 |
| Total keywords per account | 100,000 |
| Lines per library | 1,000 |
| Characters per keyword | 50 |
To add more than 1,000 keywords at once, import them from a file.
Create a library
Log on to the Guardrails console.
In the left navigation pane, choose Protection Configuration > Library Management.
On the Library Management tab, click Create Library.
In the Create Library panel, enter the library details. Enter one keyword per line. Use logical operators to combine keywords:
The
&operator must appear before the~operator in a combined expression.Operator Meaning Example &AND — match only when both keywords appear WeChat&part-time~NOT — exclude the keyword from matching loan~studentClick OK.
If library creation fails, a detailed error message is displayed. Follow the instructions in the message and try again.
Attach libraries to a service
After creating libraries, attach them to a service rule to activate custom keyword detection.
In the left navigation pane, choose Protection Configuration > Configuration.
Select the target service. In the Actions column, click Set keyword library.
On the Keyword blacklist or Keyword whitelist tab, add or remove libraries:
Keyword blacklist: Click Add keyword library to add a library. Click Remove to detach one.
Keyword whitelist: Click Add Library to add a library. Click Remove From Whitelist to detach one.
Click OK to save the configuration.
How blacklists and whitelists work
Blacklists
When the Text Moderation API detects a keyword from a blacklist library in the submitted text, it returns C_customized in the labels parameter. Any labels triggered by built-in rules are also returned.
Example: You add Small Loans and Door-to-door Service to a blacklist library. If the submitted text is:
Our School Offers Small Loans, Safe, Fast, Convenient, No Collateral, Borrow Anytime, Same-day Funding, Door-to-door Service
The API flags both Small Loans and Door-to-door Service. The labels parameter returns C_customized along with any other built-in rule labels that matched.
Whitelists
When the Text Moderation API finds a keyword from a whitelist library in the submitted text, it skips that keyword during risk analysis. Use whitelists to prevent false positives for terms that are safe in your context.
Example: You add Convenient and Fast to a whitelist library. If the submitted text is:
Our School Offers Small Loans, Safe, Fast, Convenient, No Collateral, Borrow Anytime, Same-day Funding, Door-to-door Service
The API ignores Convenient and Fast and only analyzes the remaining text for risks: Our School Offers Small Loans, Safe, No Collateral, Borrow Anytime, Same-day Funding, Door-to-door Service.