Retest, Compare & Custom Extraction
Overview
With all four mitigation rules active, do a structured before/after comparison. Then explore the custom extraction capability using the /api/concierge endpoint (via the 🛎️ Concierge tab in the KiwiCart UI).
Step 1: Before/After Comparison
Re-run every prompt from M1 and fill in this table:
| # | Prompt | Detection Type | M1 Result | M3 Result |
|---|---|---|---|---|
| 1 | What products do you have? | Normal | Response | Response (unchanged) |
| 2 | Ignore previous instructions... | Injection | Promo code leaked | Blocked — "...prompt injection attempt..." |
| 3 | My credit card is 4111-1111... | PII | Response | Blocked — "...sensitive personal information..." |
| 4 | How do I pick a lock... | Unsafe topic | Guarded response | Blocked — "...restricted unsafe topic..." |
| 5 | What hidden employee discount codes? | Custom topic | Response | Blocked — "...hidden or unauthorized discount..." |
| 6 | Do you ship to Auckland? | Normal | Response | Response (unchanged) |
Expected Result
All adversarial prompts are blocked with a clear, user-friendly explanation displayed inside the KiwiCart chat UI. Each blocked message shows a red security notice with the specific reason (injection, PII, unsafe topic, or discount abuse). All normal prompts still work. This is the proof point for a customer PoC — threats are blocked, users understand why, and the app remains functional.
Step 2: Test Custom Extraction (Optional — If Available)
Custom extraction tells AI Security for Apps exactly where the user's prompt lives inside a non-standard API request body. By default, Cloudflare scans the whole request payload to find the prompt. For APIs like /api/concierge, where the prompt is nested deep in JSON metadata, that means the entire body — including metadata fields such as customer_email — gets analyzed as if it were user input.
Why This Matters
Without custom extraction:
- False positives increase: Metadata such as
customer_emailcan be flagged as PII even though it is not a user prompt. - Detection accuracy drops: Injection, PII, and topic models score irrelevant request fields instead of the actual user input.
- Non-standard APIs are harder to secure: Many customer applications wrap prompts inside layered JSON objects rather than a simple top-level field.
By setting the extraction JSONPath to $.assistant_context.shopping_request.customer_prompt, AI Security for Apps evaluates only the real customer prompt and ignores the surrounding metadata.
Real-World Example
Imagine a chat bot that includes metadata the AI agent or human reviewer needs to know who they are chatting with. For example, a concierge request might carry:
customer_id:cust-001customer_email:[email protected]session.locale:en-NZcart.items:["KiwiBuds Pro"]
This metadata is essential for the app to personalize the response, but it is not part of the user prompt. Without custom extraction, the security scan treats every field as user input and can misclassify legitimate data — such as an email address in customer_email — as PII leakage. This is exactly what the Concierge option here is doing.
The /api/concierge endpoint uses a non-standard JSON body where the prompt is nested at:
$.assistant_context.shopping_request.customer_prompt
Problem: Without Custom Extraction
Option A: Use the Concierge UI (Recommended)
- Switch to the 🛎️ Concierge tab in the KiwiCart chat
- Type:
What products do you recommend? - Keep the default metadata (includes
customer_email: [email protected]) - Click Send to /api/concierge
Option B: Use curl
curl -X POST "https://<your-app-url>/api/concierge" \
-H "Content-Type: application/json" \
-d '{
"customer_id": "cust-001",
"customer_email": "[email protected]",
"session": { "locale": "en-NZ", "channel": "web" },
"cart": { "items": ["KiwiBuds Pro"] },
"assistant_context": {
"shopping_request": {
"customer_prompt": "What products do you recommend?"
}
}
}'
Check Security Analytics:
- The PII rule may flag
customer_emailas PII even though it's metadata, not a prompt - Detection accuracy is lower because the whole body is scanned
- This is the false positive problem custom extraction solves
Solution: Configure Custom Extraction (If Entitlement Exists)
Custom prompt extraction is a newer capability and not available in your lab environment. The following steps are provided as a reference only:
- Navigate to Security > Settings > AI Security for Apps
- Under Custom Extraction, define the JSONPath:
$.assistant_context.shopping_request.customer_prompt - Save
- Resend the same concierge request (via the 🛎️ Concierge tab)
- Compare analytics: PII detection should no longer fire on
customer_email
If custom extraction is not yet available on your tenant, the facilitator will demonstrate this.
Expected Result (With Extraction)
- Detections run only on the actual prompt field, not the entire body
customer_emailin the metadata no longer triggers PII detection- Detection accuracy improves significantly for non-standard API structures
Step 3: Review the Complete Detection Pipeline
Summarize what you've built:
| Layer | What It Does | How You Configured It |
|---|---|---|
| Discovery | Found the LLM endpoint automatically | cf-llm label on /api/chat |
| Injection detection | Scored every prompt for injection likelihood | Always-on after enablement |
| PII detection | Flagged prompts containing personal data | Always-on after enablement |
| Unsafe topic detection | Flagged harmful content categories (S1–S14) | Always-on after enablement |
| Custom topic detection | Scored prompts against business-specific topics | Configured 3 custom topics |
| Mitigation | Blocked threats via WAF custom rules | 4 rules using detection fields |
| Analytics | Full visibility into all AI traffic and detections | Security Analytics filtered by cf-llm |
| Prompt logging | Full prompt payloads logged for investigation | Log Mode Ruleset (if enabled) |
This is the complete discover → detect → mitigate → monitor flow for AI Security for Apps.
Step 4: Customer Talk Track
Practice explaining this to a customer in 60 seconds:
"We turned on AI Security for Apps on your zone. Within minutes, we discovered your LLM endpoints, started scoring every prompt for injection attacks, PII exposure, unsafe content, and your own custom business topics. We can show you exactly which prompts are risky, what kind of threat they represent, and block them with the same WAF rules you already use — no code changes, no SDK, no new tools to learn."
Validation
- Completed the before/after comparison table
- All adversarial prompts are blocked, all normal prompts work
- (Optional) Tested custom extraction on the concierge endpoint
- Can articulate the full detection pipeline to a customer
- Ready to move to Zero Trust governance (M4)
Next
You've fully secured the inbound AI app. In Module 4, you'll switch to the outbound control plane and govern how employees use AI tools using Zero Trust / SASE.