Project | AI & LLM

Quality Gate for a RAG Chatbot

A help-desk chatbot for a fictional climbing gym behind a FastAPI API, with staff-only secrets and a planted prompt injection in its knowledge base. Weekly, real local models answer and judge through Ollama in CI, and the run records where the model invents and where the judges disagree.

On 26 Nov 2026 the quality gate passed on main: all 22 checks within their limits; pytest 174 passed, with 10 known misses as strict expected failures. Four real-model runs on the same day are in the README.

Evidence checked 26 Nov 2026 | CI run on main

GitHub Actions workflow badge
On this page
  1. Problem and purpose
  2. Architecture
  3. Technology and tools
  4. Engineering decisions and approach
  5. Test scope and execution approach
  6. Results with dated evidence
  7. Evidence explorer
  8. Local setup and execution
  9. Workflow and reports
  10. Known limitations

Problem and purpose

The assistant is Belay, the help desk of a fictional climbing gym. It answers from 16 public help sections and cites them. The knowledge base also holds 3 staff-only sections with a door code and members' phone numbers, and a forum post with a prompt injection, so there is something real to protect.

The gate is honest about what it measures. Core questions written from the help articles pass at 100 %, which only shows the system does what it was built for. Reworded questions are the real number: 7 of 14 get "I don't have that information" and 2 get a confident wrong answer, but every answer stays grounded in its citation. Those cases run as strict expected failures, so the list cannot go stale.

Architecture

POST /chat ─► input guard ─► retrieve (public sections only) ─► enough evidence? ─► generator ─► output guard ─► reply
               refused                                           not found             masks e-mail, phone, codes;
                                                                                       drops invented citations

case files ─► pytest + DeepEval · retrieval eval · Ragas · Promptfoo ─► reports/*.json ─► quality gate (configs/*.toml)

Technology and tools

AreaTools
ApplicationPython 3.13, FastAPI: /chat, /chat/stream (Server-Sent Events), /health; input and output guards, rate limit, a redacted trace per request
RetrievalBM25 and vector similarity merged with reciprocal rank fusion; TF-IDF vectors offline, nomic-embed-text in the model run
Evaluationpytest with httpx and jsonschema, DeepEval (custom metrics), Ragas, Promptfoo (HTTP provider and red team)
Models (weekly)llama3.2:3b answers, qwen2.5:7b judges, nomic-embed-text vectors, all local through Ollama on the CI runner
CIGitHub Actions: the offline gate on every push and pull request; the real-model run weekly with its own gate

Engineering decisions and approach

  • The required gate uses an extractive generator that cannot invent, so it tests the system around the model and is repeatable
  • One set of case files and graders feeds DeepEval, Ragas and Promptfoo through adapters
  • Known misses are strict expected failures with the measured reason: the build turns red when one starts to pass
  • Limits for the reworded questions sit just below today's values: they stop it getting worse, not say it is good enough
  • A red-team fail counts only when a second grade agrees, because the judge model itself varies

Test scope and execution approach

Project-specific checks and execution details documented in the repository:

  • 8 layers in one gate: HTTP contract, retrieval, answers, attacks, Ragas reference metrics, Promptfoo black box, latency, unit tests
  • Every grader and guard shown failing on a planted bad answer
  • Weekly real-model run: DeepEval Faithfulness, Answer Relevancy and G-Eval, Ragas metrics, stability over 5 repeats, and a red-team scan
  • What the model runs found: the model invents a fee rule, the judges score the same answer 1.0 and 0.33, and temperature 0 is not determinism
  • Generated manual test case list, checked by a test so it cannot go out of date

Results with dated evidence

Historical repository or workflow evidence

CI run on main

On 26 Nov 2026 the quality gate passed on main: all 22 checks within their limits; pytest 174 passed, with 10 known misses as strict expected failures. Four real-model runs on the same day are in the README.

Evidence checked: | Open dated evidence

Evidence explorer

Static screenshots are labelled as images; dated workflow links identify the execution evidence and its check date.

Test report screenshot. A real call to POST /chat on 26 Nov 2026: the answer cites help section M2, with its trace id and a latency of 0.47 ms. Static image; capture date is not recorded in the portfolio data.
A real call to POST /chat: an answer citing section M2

Test report screenshot. A real call to POST /chat on 26 Nov 2026: the answer cites help section M2, with its trace id and a latency of 0.47 ms. Static image; capture date is not recorded in the portfolio data.

Gate on 26 Nov 2026: core questions 1.000 on status, facts, citation and grounding; reworded questions status 0.500, grounded 1.000, retrieval MRR 0.857; attacks: nothing leaked in 16; Promptfoo 44 of 44; p95 latency 0.28 ms in the server. In the four real-model runs the same day, nothing leaked either, and the judges disagreed with themselves: one answer got Faithfulness 1.0, 0.67, 1.0 and 0.33.

Static material from the public repository. The linked verification record was checked 2026-11-26; that date is not a screenshot capture date.

Dated workflow record

Evidence checked 2026-11-26. Open CI run on main

Local setup and execution

python -m venv .venv && .venv\Scripts\activate
pip install -e ".[dev]" && npm ci
python -m qa.check_all              :: every suite against a real server, then the gate
python -m qa.check_all --model      :: the weekly run, with Ollama and the three models

Workflow and reports

View workflow definition.

Known limitations

  • 44 cases and 19 sections are a lab, not a production knowledge base
  • The required gate's 100 % on core questions says nothing about a model; the weekly small-model run on a CPU runner is an indication, not a measurement
  • The guards are word lists; a determined attacker can rephrase. Latency is measured in the server, not under load
  • A lab: 44 cases and 19 sections; the required gate uses a generator that cannot invent, and the weekly small-model run is an indication, not a measurement.

Back to Projects