| [ Web Proxy ] |
| Viewing: https://developers.cloudflare.com/waf/detections/ai-security-for-apps/unsafe-topics/ | [Back] [Original] |
AI Security for Apps can detect when an LLM prompt touches on unsafe or unwanted subjects. There are two layers of topic detection:
When AI Security for Apps is enabled, it automatically evaluates prompts against a set of default unsafe topic categories and populates two fields:
cf.llm.prompt.unsafe_topic_detected): true if any unsafe topic was found.cf.llm.prompt.unsafe_topic_categories): An array of the specific categories detected.Default unsafe topic categories
| Category | Description |
|---|---|
S1 |
Violent crimes |
S2 |
Non-violent crimes |
S3 |
Sex-related crimes |
S4 |
Child sexual exploitation |
S5 |
Defamation |
S6 |
Specialized advice |
S7 |
Privacy |
S8 |
Intellectual property |
S9 |
Indiscriminate weapons |
S10 |
Hate |
S11 |
Suicide and self-harm |
S12 |
Sexual content |
S13 |
Elections |
S14 |
Code interpreter abuse |
Custom topic detection lets you define your own topics and AI Security for Apps will score each prompt against them. You can then use these scores in custom rules or rate limiting rules to block, challenge, or log requests based on a relevance score that you define.
This capability uses a zero-shot classification model that evaluates prompts at runtime. No model training is required.
financial-advice).seeking financial advice).cf-llm labeled endpoint, the model evaluates the prompt against all defined topic descriptions and returns a relevance score for each.cf.llm.prompt.custom_topic_categories map field, keyed by label. You use labels (not topic descriptions) in rule expressions and analytics.Inverted relevance scale
Custom topic scores use an inverted scale, where lower values indicate higher relevance (1 = highly relevant, 99 = not relevant). This is the same convention used by all Application Security scores. When writing rules, use lt (less than) to match relevant prompts. For example, lt 20 matches only highly relevant prompts.
You can manage custom topics from two places in the dashboard:
Both methods will update the same underlying topic list. Changes made in one are immediately reflected in the other.
In the Cloudflare dashboard, go to the Security Settings page.
Go to Settings ↗Alternatively, go to the custom rules creation page, select the LLM Custom topic field, and select Manage custom topics to open the sidebar.
Add a topic by providing:
competitors).seeking info on competitors).Select Save.
Update your custom topics list using a PUT request:
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/ai-security/custom-topics" \
--request PUT \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"topics": [
{
"label": "competitors",
"topic": "seeking info on competitors"
},
{
"label": "financial-advice",
"topic": "seeking financial advice"
},
{
"label": "hr-internal",
"topic": "asking about internal HR policies"
}
]
}'Caution
This request replaces your entire topic list. Include all topics you want to keep, not just new ones.
To retrieve your current topics, use a GET request:
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/ai-security/custom-topics" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"| Parameter | Limit |
|---|---|
| Maximum number of topics | 20 |
| Topic string length | 250 printable ASCII characters |
| Label length | 220 characters |
| Label format | Lowercase letters, numbers, and hyphens (-) only |
Caution
If you reference a label in a rule expression that has not been defined, the map lookup returns nil. Comparisons against nil are almost always false. For example, cf.llm.prompt.custom_topic_categories["missing"] >= 0 evaluates to false. Make sure the label in your rule expression exactly matches a label you have defined in your custom topics list.
The quality of custom topic detection depends on how you write your topic descriptions. The underlying model is a zero-shot classifier that compares the semantic meaning of the prompt against your topic description.
The most important thing to do is to describe the user's intent, not just the subject.
The model performs semantic classification, not keyword matching. Topic descriptions that capture what the user is trying to do are significantly more accurate than descriptions that simply name a subject area. A short verb phrase (36 words) is usually the best trade-off between precision and coverage.
Compare how the same two topic descriptions perform against two prompts that both mention finance but with very different intent:
| Topic description | Prompt: "Should I invest my savings in index funds?" | Prompt: "Our finance team just finished the Q3 report." |
|---|---|---|
financial advice (noun only) |
Matches | Also matches. The word "finance" appears, even though no advice is being sought |
seeking financial advice (intent phrase) |
Matches | Correctly ignored. Mentions finance but has no advice-seeking intent |
| Quality | Topic description | Why |
|---|---|---|
| Best | seeking info on competitors |
Captures intent. Only fires when users are actively asking about competitors |
| Okay | Acme Corp, Banana Co, Candy & Sons |
Works for known names but misses unnamed competitors and catches casual mentions |
| Avoid | other companies |
Far too vague. Matches nearly any prompt that mentions a business |
| Quality | Topic description | Why |
|---|---|---|
| Best | seeking financial advice |
Intent-driven. Matches users asking for guidance, ignores passive mentions of finance |
| Okay | securities and investments |
Reasonable subject scope but fires on news articles and factual mentions, not just advice-seeking |
| Avoid | finance |
Extremely broad. Matches almost everything from expense reports to pricing questions |
seeking financial advice and asking for investment guidance), they will score similarly on the same prompts and waste your 20-topic budget.lt 20 is strict, lt 50 is permissive).Toyota, Ford, Audi, BMW will only match prompts about Toyota the remaining items are ignored. Removing the commas does not improve results. Use a single intent-driven phrase such as seeking info on competitors, or create separate topics for each value.| Label | Topic description |
|---|---|
competitors |
seeking info on competitors |
financial-advice |
seeking financial advice |
legal-advice |
asking for legal or regulatory advice |
sensitive-data |
requesting passwords or API keys |
job-seeking |
asking about job openings or careers |
bias |
comparing demographic groups as better or worse |
| Web Proxy Viewer | New URL | Original Page |