A Cloudflare Worker showcasing AI Security for Apps — protect your LLM endpoints against PII leaks, unsafe topics, and prompt injection at the edge.
Blocks prompts containing personal data — emails, phone numbers, SSNs, credit cards.
cf.llm.prompt.pii_detected
Detects violent crimes, hate speech, and other harmful categories.
cf.llm.prompt.unsafe_topic_categories
Identifies attempts to override system instructions. Score 0–100 (lower = more likely).
cf.llm.prompt.injection_score
Counts prompt tokens at the edge so you can rate-limit by usage, not just request count.
cf.llm.prompt.token_count
Click any card to load it into the chat. With WAF rules configured, harmful prompts are blocked at the Cloudflare edge before reaching this Worker.
Configure these in the Cloudflare dashboard under Security > Custom Rules
after labeling POST /v1/messages with the cf-llm endpoint label.
(cf.llm.prompt.pii_detected)
{ "error": "pii_blocked", "message": "Your request contains personal information and was blocked." }(any(cf.llm.prompt.unsafe_topic_categories[*] in {"S1" "S10"}))
{ "error": "content_policy", "message": "That topic is outside this assistant's scope." }(cf.llm.prompt.injection_score lt 25 and cf.bot_management.score lt 10)
cf.llm.prompt.token_count > 0