LLM Prompt Security: WAF Detection, Injection Scoring, and Data Loss Prevention
How Cloudflare AI Security for Apps, WAF fields, and DLP protect LLM endpoints and workforce AI prompts from injection, PII, and unsafe content.
This page summarizes Cloudflare documentation on securing applications that use large language models (LLMs). The main inline control plane is AI Security for Apps in the Web Application Firewall (WAF), which discovers LLM endpoints, scores prompts, and exposes rule fields. Data Loss Prevention (DLP) adds profile-based scanning on AI Gateway traffic and on employee use of SaaS AI apps through Cloudflare One Gateway. Together they address prompt injection, personally identifiable information (PII) in prompts, unsafe topics, and accidental data leaks—without replacing your own application logic.
AI Security for Apps: what WAF adds to LLM traffic
Section titled “AI Security for Apps: what WAF adds to LLM traffic”AI Security for Apps (formerly Firewall for AI) extends existing WAF rules with detections aimed at how LLMs process input.
Applications that use large language models (LLMs) are exposed to threats specific to how LLMs process input — prompt injection attacks, PII exposure in prompts, and prompts about unsafe topics.
— Cloudflare, AI Security for Apps
It is model-agnostic: detections apply regardless of which LLM you use. When enabled, scans run on incoming requests to endpoints labeled cf-llm. Today, prompt extraction and scoring apply only to requests with Content-Type: application/json.
Detection results populate AI detection fields you can use in WAF expressions—either to monitor in Security Analytics or to mitigate with custom rules and rate limiting rules. The WAF must be enabled on the zone before those fields are populated.
Plan availability: discovery vs enforcement fields
Section titled “Plan availability: discovery vs enforcement fields”| Capability | Free | Pro | Business | Enterprise |
|---|---|---|---|---|
LLM endpoint discovery (cf-llm labeling) |
Yes | Yes | Yes | Yes |
| AI Security Log Mode Ruleset (full body + detections) | No | No | No | Paid add-on |
| AI detection fields (PII, injection score, unsafe/custom topics) | No | No | No | Paid add-on |
To enable the log-mode ruleset and detection fields, Cloudflare directs customers to contact their account team. See AI Security for Apps and Get started with AI Security for Apps.
LLM endpoint discovery and the cf-llm label: find AI APIs in your zone
Section titled “LLM endpoint discovery and the cf-llm label: find AI APIs in your zone”LLM Discovery uses heuristics on traffic patterns (for example, slower response bitrates common on LLM endpoints) and filters known false positives such as GraphQL or health checks. Discovered endpoints receive the managed label cf-llm, which you filter in Security Analytics and Web assets.
Once LLM endpoints are identified, Cloudflare API security capabilities automatically label the endpoints with a cf-llm label; this allows for easy filtering in analytics and for easily applying security policies to all discovered LLM endpoints.
— Cloudflare, AI Security for Apps Reference Architecture
AI-specific detections run on traffic to discovered LLM endpoints whether or not you have configured block rules—supporting visibility before enforcement. For an operational checklist on web assets, see Define security protections.
Prompt injection and jailbreak: injection score rules (lower means riskier)
Section titled “Prompt injection and jailbreak: injection score rules (lower means riskier)”Prompt injection detection assigns a numeric score rather than a simple yes/no flag.
Prompt injection detection uses a score-based system rather than a binary detected/not-detected result. The score is written to the LLM Injection score (cf.llm.prompt.injection_score) field.
— Cloudflare, Prompt injection detection
| Score range | Meaning |
|---|---|
| 1–19 | High likelihood of prompt injection |
| 20–49 | Moderate likelihood |
| 50–99 | Low likelihood (normal input) |
Lower scores mean higher risk. Documentation cites scores below 20 as strong injection signals; Example mitigation rules combine cf.llm.prompt.injection_score with bot scores or geography to reduce false positives—for example cf.llm.prompt.injection_score lt 25 with cf.bot_management.score lt 10.
Tuning workflow: start with Log at a moderate threshold, review events in Security Analytics, then tighten or loosen before Block. Log mode versus production mode recommends starting in log mode with payload logging when you need to see prompt text alongside scores.
PII in LLM prompts: categories, regex, and rule scope
Section titled “PII in LLM prompts: categories, regex, and rule scope”PII detection offers two complementary approaches per PII detection:
- AI-based detection — populates
cf.llm.prompt.pii_detectedandcf.llm.prompt.pii_categoriesoncf-llmendpoints (NER-style model). - Exact detection — WAF regex on
http.request.body.rawfor formats you define (for exampleEMP-[0-9]{6}); regex body operators require Business or Enterprise plans.
Blocking on pii_detected alone often over-matches broad categories such as PERSON or DATE_TIME. Cloudflare recommends scoping rules to specific categories—for example CREDIT_CARD and US_SSN only.
Request-side PII in AI Security for Apps does not scan LLM responses; for response patterns, documentation points to Sensitive Data Detection (logging, not blocking) alongside request rules.
Unsafe topics and custom topics: content policy on prompts
Section titled “Unsafe topics and custom topics: content policy on prompts”Default unsafe topics populate cf.llm.prompt.unsafe_topic_detected and cf.llm.prompt.unsafe_topic_categories (categories such as VIOLENCE_AND_WEAPONS, HATE_AND_DISCRIMINATION, CHILD_SAFETY). See Unsafe and custom topic detection.
Custom topics (up to 20 per zone) use zero-shot classification; relevance appears in cf.llm.prompt.custom_topic_categories with the same inverted scale as injection scores—lower means more relevant to that label. Define labels and intent-focused descriptions (for example seeking financial advice, not bare keywords). The PUT API replaces the entire topic list—include all topics you intend to keep.
Example block rule for a support bot: match VIOLENCE_AND_WEAPONS or HATE_AND_DISCRIMINATION and return custom JSON, as in Example mitigation rules.
WAF detection fields reference: build monitor and block rules
Section titled “WAF detection fields reference: build monitor and block rules”When AI Security for Apps is enabled, these fields are available in rule expressions (AI Security for Apps fields):
| Field | API name | Type | Role |
|---|---|---|---|
| LLM Content detected | cf.llm.prompt.detected |
Boolean | LLM prompt found in request |
| LLM PII detected | cf.llm.prompt.pii_detected |
Boolean | Any PII in prompt |
| LLM PII categories | cf.llm.prompt.pii_categories |
Array | Specific PII types |
| LLM Unsafe topic detected | cf.llm.prompt.unsafe_topic_detected |
Boolean | Any unsafe topic |
| LLM Unsafe topic categories | cf.llm.prompt.unsafe_topic_categories |
Array | Unsafe topic types |
| LLM Injection score | cf.llm.prompt.injection_score |
Number | 1–99 injection likelihood |
| LLM Token count | cf.llm.prompt.token_count |
Number | Estimated prompt size |
| LLM Custom topic categories | cf.llm.prompt.custom_topic_categories |
Map | Label → relevance score |
cf.llm.prompt.token_count is an estimate for thresholds and abuse patterns, not provider-accurate billing counts (Token counting).
Mitigation patterns: Log or Block with custom JSON for API clients (Get started with AI Security for Apps), Managed Challenge for moderate injection scores, and rate limits on large prompts (cf.llm.prompt.token_count gt 2000).
Data Loss Prevention: AI Gateway, workforce AI apps, and how it differs from WAF AI fields
Section titled “Data Loss Prevention: AI Gateway, workforce AI apps, and how it differs from WAF AI fields”DLP addresses sensitive data patterns and, in Cloudflare One, AI prompt topics on sanctioned SaaS tools. Data loss prevention states:
AI Security for Apps — DLP complements AI Security for Apps by providing profile-based detection of sensitive data in AI traffic, while AI Security for Apps handles large language model (LLM)-specific threats such as prompt injection and unsafe topics.
DLP on AI Gateway (your apps and agents)
Section titled “DLP on AI Gateway (your apps and agents)”DLP for AI Gateway scans prompt and response text through the gateway, reusing account-level DLP profiles. Enable it under AI > AI Gateway > Firewall (Set up Data Loss Prevention (DLP)). Actions: Flag or Block; Check: Request, Response, or Both.
Important limits from Data Loss Prevention (DLP) and Coding agents:
- Streaming: response scanning buffers the full provider stream before release—increased time-to-first-token unless Check is Request-only or you use a separate gateway.
- Scope: no per-request header to pick profiles; use separate gateways for different policies.
- Cache: cache hits skip DLP; policy updates do not re-scan cached responses until TTL expires (
cf-aig-skip-cachecan force fresh evaluation). - Attachments: base64/binary and external URLs are not decoded—only body text.
DLP scanning on AI Gateway is priced as free on all plans with a reduced profile set without Zero Trust; full profiles follow your Cloudflare One DLP entitlements (Pricing).
AI Gateway Guardrails documentation also references gateway guardrails and DLP for unsafe or sensitive content on gateway traffic.
DLP AI prompt protection on Gateway HTTP (workforce GenAI)
Section titled “DLP AI prompt protection on Gateway HTTP (workforce GenAI)”For ChatGPT, Google Gemini, Claude, and Perplexity, Application Granular Controls inspect prompts at actions such as SendPrompt (Configure detection entries). Topics split into:
- Content — PII, source code, credentials, financial data, customer data in the prompt.
- Intent — jailbreak, malicious code requests, attempts to extract PII.
Predefined bundles include profiles such as AI Prompt: AI Security and AI Prompt: PII (Predefined profiles). Custom prompt topics are natural-language concepts (not keyword lists); literal codenames belong in wordlists (Define custom topics for AI prompt protection).
Example workforce policy pattern: block Financial Information DLP profile when Content Categories include Artificial Intelligence (Build Data Loss Prevention (DLP) policies). Turn on Capture generative AI prompt content in logs on eligible HTTP policies to investigate matches (Logging options).
Holistic adoption steps—risk tolerance, monitoring shadow AI, policy ordering—appear in Holistic AI security concepts and Build security policies for general AI use.
Log mode versus production mode: when you can see full prompts
Section titled “Log mode versus production mode: when you can see full prompts”| Feature | Production mode | Log mode |
|---|---|---|
| Configuration | Custom WAF rules on AI fields | AI Security Log Mode Ruleset |
| Prompt body logging | No (metadata only) | Yes, encrypted payload logging |
| Policy flexibility | Scores, categories, bots, custom topics | Three fixed detection rules |
| Best for | Enforced production controls | Tuning and validation |
Production mode does not log prompt text; combine AI Gateway or DLP prompt capture if you need response or outbound SaaS visibility. See Log mode versus production mode.
Common mistakes when securing LLM prompts
Section titled “Common mistakes when securing LLM prompts”- Enabling Block on
cf.llm.prompt.pii_detectedwithout narrowingpii_categories, causing blocks on ordinary names or dates (PII detection). - Treating injection_score like a “higher is worse” metric; remember low scores are dangerous (Prompt injection detection).
- Expecting AI Security for Apps on non-JSON APIs while your chat endpoint uses another content type (LLM Prompt Detection in the reference architecture).
- Turning on DLP response scanning on streaming coding agents without accepting latency trade-offs (Coding agents).
- Referencing undefined custom topic labels in rules (map lookups on missing labels evaluate false) (Unsafe and custom topic detection).
- Assuming updated DLP policies immediately affect cached AI Gateway responses (Data Loss Prevention (DLP)).
Account-level DLP profile limits (for example 25 custom entries) apply across gateways (Limits).
How to check this on your site
Section titled “How to check this on your site”-
Confirm WAF is on and AI Security for Apps is enabled under Security Settings; send sample
application/jsonPOST traffic to your LLM route. -
In Security Analytics, filter Managed Endpoint Label equals
cf-llmand review PII, unsafe topic, and injection fields on sampled logs. -
If you use AI Gateway DLP, submit a test prompt with sample sensitive data and confirm matches in AI Gateway Logs (
DLP Action,DLP Profiles Matched). -
For workforce AI, verify an HTTP policy with DLP Profile and, if needed, decrypted prompt capture in HTTP request logs.
-
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page disagrees with your dashboard behavior or with current Cloudflare documentation, email yimasynthetic@gmail.com with the page URL and the exact sentence you believe is wrong, and we will clarify or correct it.