Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 10.9 — Playbook: RAG Security Checklist and Guards
RAG and Vector Search · Example 1 of 1

Five guard recipes and their checks

Production versions use your store's filter instead of a list comprehension and a proper HTML or Markdown escaper for your renderer. The checks stay the same.

Five small recipes to copy into any RAG project: a fail-closed access filter, an untrusted-text wrapper, a redactor, a deletion audit and a tenant-safe cache key, each with a check, plus the checklist to run before you ship.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Add output_ok(answer, sent_ids) to the recipes and print ok or FAIL for a cited answer and for the bare answer banana.

02

Write registry_complete(stores, registry) that returns the names in stores that are missing from registry, so a new store cannot be added without being added to the delete and the audit.

Explain it without notes

01

Walk through the pre-ship checklist and say what incident each line prevents.

02

Why should the access filter, the redactor and the audit live in one module that every code path uses?

03

How does row-level security improve a shared-index multi-tenant design?

04

What should a CI security test for a RAG system include?

Five guard recipes and their checks
Sign in to run this example in your browser.

Expected output

ok   acl: no groups sees nothing
ok   acl: public sees only C1
ok   wrap: a passage cannot close the tag
ok   redact: email and card removed
ok   audit: finds the cache
ok   key: tenants differ, case does not