Production RAG chatbot for a regulated domain
Ship a citation-enforcing RAG chatbot for a regulated domain with role and jurisdiction filters, layered guardrails, a golden set, a red team, cost tracking and drift monitoring.
The capstone and what it builds on
- 1Production RAG Chatbot for a Regulated VerticalThe capstone brief
- 2Advanced RAG (Chunking, Reranking, Hybrid Search)Phase 11: LLM engineering and RAG
- 3Prompt Caching and Context CachingPhase 11: LLM engineering and RAG
- 4Guardrails, Safety & Content FilteringPhase 11: LLM engineering and RAG
- 5LLM Evaluation - RAGAS, DeepEval, G-EvalPhase 5: Natural language processing
- 6LLM Observability Stack SelectionPhase 17: Infrastructure and production
- 7Prompt Caching and Semantic Caching EconomicsPhase 17: Infrastructure and production
- 8Red-Team Tooling - Garak, Llama Guard, PyRITPhase 18: Ethics, safety and alignment
- 9Moderation Systems - OpenAI, Perspective, Llama GuardPhase 18: Ethics, safety and alignment
What You'll Build
A chatbot over a corpus from a regulated domain (legal, clinical or insurance) that answers only with verifiable citations, respects role and jurisdiction labels, runs layered guardrails, and is graded on a golden set and a red-team suite. You also track cache hit rate, cost and latency per query, and watch retrieval quality drift as the corpus changes.
Requirements
- Ingestion: parse documents (docling, Unstructured or pypdf) into chunks with a short summary, a role label and a jurisdiction tag (for example GDPR, HIPAA).
- Index: dense embeddings plus BM25, with role and jurisdiction as filterable metadata.
- Retrieval: filter by role and jurisdiction first, run dense and BM25 in parallel, merge with reciprocal rank fusion, rerank the top 20 to 5.
- Synthesis with a stable prefix order (system prompt and policies first, retrieved context next, question last). Measure cache hit rate: provider prompt caching if your endpoint supports it, otherwise your own prefix or semantic cache.
- Guardrails: input safety classifier, off-domain and policy rails, output PII scrub (Presidio or equivalent), citation enforcement post-filter, and an abstain response when reranker scores are below a threshold.
- Golden set of at least 50 questions with expected answers and citations. Score faithfulness, answer relevance and context precision (RAGAS or an equivalent LLM judge), exact citation match and correctness.
- Red-team set of at least 30 prompts: jailbreaks, PII extraction, off-domain requests and cross-jurisdiction leaks. Record pass or fail and severity for each.
- Cross-jurisdiction probe: a test proving a user scoped to one jurisdiction never receives chunks from another.
- Drift monitoring: at least two corpus snapshots (for example after updating or removing documents) with retrieval quality tracked over time and an alert rule that fires on a 5% drop. Phoenix, Langfuse or a small custom dashboard is fine.
- Cost and latency report: tokens per query, $ per query by stage (or an estimate from your endpoint's pricing) and p95 latency.
Constraints
- Model-agnostic: any OpenAI-compatible endpoint (including the KatalockAi API) or a local model (for example via Ollama, llama.cpp or vLLM) may be used. No named commercial model is required; record which model you used in the README.
- Hardware: a laptop is enough with a small embedder, a small cross-encoder and a remote or local LLM. Use a small open safety classifier or moderation model for the guard layer.
- Substitution: the lesson targets 1,000 to 10,000 documents, a 200-question expert-labelled golden set and 50 red-team prompts. Here 100 or more public documents, 50 or more golden questions written by you (state that you are not a domain expert if you are not) and 30 or more red-team prompts are accepted.
- Use public material only (published regulations, sample policies, public trial protocols). Do not ingest real personal data.
- Do not commit harmful completions from the red team; store prompts and pass or fail outcomes, redacting outputs where needed.
Stretch Goals
- Add a second jurisdiction slice and a 20-question cross-leak probe.
- Add multi-turn memory with a summary buffer and measure faithfulness as conversations grow.
- Measure false-confidence reduction from the abstain mode.
How to Submit
- Public GitHub repo with
ingest/,retrieval/,guards/,app/(API or chat UI),eval/(golden set, red team, results),monitoring/andREADME.md. - README: domain and corpus sources, architecture, how to run the bot and the evals, results tables, cost and latency report, drift setup and limitations.
- Paste golden-set scores, red-team summary, the cross-jurisdiction test output and the cost and latency report.
How It's Reviewed
Professor Katalock reads your repository and the evidence you paste, and scores each criterion out of 100. You pass with a weighted total of 70 or more and no criterion below 40. A copied or padded submission is flagged and fails.
Submit
Push your work to a public GitHub repository with a README that explains how to run it, then paste the evidence below. Up to 3 reviews a day, free.
- Golden-set score summary (faithfulness, relevance, context precision, citation match, correctness)
- Red-team summary table with severity counts
- Cross-jurisdiction probe test output
- Cost and latency report (cache hit rate, tokens and $ per query, p95)
- Drift dashboard screenshot description or alert log across snapshots
Reviews are done by AI against the rubric above. They check the evidence in your repository; they are not a substitute for a human code review, and a review can be wrong. If you think it is, improve the README so the evidence is unmistakable and resubmit.