KatalockAi AcademyBack to KatalockAi
Build track, required for the Phase 18 certificate

Build a layered LLM safety gate

Build a three-checkpoint safety gate: a jailbreak taxonomy, a measured injection detector, refusal evals, output classifiers, a constitutional rules engine and a streaming filter, with an audit trace per request.

about 22 h 6 guided steps Reviewed against a 6-point rubric
Submit your project Get coached by Professor Katalock

Build it step by step

  1. 1Jailbreak TaxonomyPhase 19: Capstone projects
  2. 2Prompt Injection DetectorPhase 19: Capstone projects
  3. 3Refusal EvaluationPhase 19: Capstone projects
  4. 4Content Classifier IntegrationPhase 19: Capstone projects
  5. 5Constitutional Rules EnginePhase 19: Capstone projects
  6. 6End-to-End Safety GatePhase 19: Capstone projects

What You'll Build

A safety gate for an LLM product you name (for example a customer support bot or a coding assistant). It runs at three checkpoints: an input-side injection detector before generation, a streaming filter during generation, and output classifiers plus a constitutional rules engine after generation. A deterministic aggregation table turns their signals into block, redact, warn or allow, and every request leaves a structured trace. Each layer is measured with precision, recall or refusal rates against a labelled attack taxonomy and a benign set, and you report the numbers honestly, including what gets through.

Requirements

  1. Taxonomy. The six categories (role-play, instruction-override, context-smuggling, multi-turn-ramp, encoding-trick, prefix-injection), at least 7 fixtures each with id, category, subtype, prompt, target_behavior and severity 1 to 5, at least half written by you for your product. A validator that hard-fails on empty prompts, missing categories, bad severities or duplicate ids, trigram-cosine match, and taxonomy.json.
  2. Detector. A normalise pass (zero-width and bidi removal, base64, rot13, hex and leet decoding) followed by substring and regex rules stored as data. Per-category precision, recall and F1 over the taxonomy plus a benign set of at least 20 prompts that includes hard cases such as legitimate creative role-play, written to detector_report.json.
  3. Refusal evaluation. A labelled safe and unsafe prompt set, the three scripted mock policies (strict, over-cautious, leaky), a refusal-phrase classifier, under-refusal and over-refusal rates, accuracy, ECE from stated confidence and per-category under-refusal. The report must show over-cautious with the highest over-refusal and leaky with the highest under-refusal.
  4. Output classifiers. Toxicity with a negation window, PII (email, phone, SSN-shaped, card-shaped, IP) and instruction leakage by trigram overlap with your system prompt, each with its own redactor. A router maps max severity to block, redact, warn or log, and each verb fires on at least one fixture.
  5. Rules engine. A YAML or JSON constitution with atomic predicates, all_of, any_of, not_, applies_when (reported as not_applicable when it does not apply), severities, explanations, fixer operations and a structured diff between draft and revised output. Include at least two rules specific to your product.
  6. Gate. Pre-gen detector, a during-gen filter that buffers two chunks of a streaming mock LLM and terminates early on forbidden continuations, post-gen classifiers and rules, and the lesson 87 aggregation table. A RequestTrace per request with prompt, each checkpoint's verdict, final action, final output and latency. Run every taxonomy fixture plus at least 10 benign prompts, write gate_trace.json, print counts of blocks, redacts, warns, allows and early terminations with a per-category breakdown, and exit 0.
  7. Honest results. Report attack block rate, benign false-block rate and the categories that leak through, with one trace example of a miss.

Constraints

  • Python standard library plus numpy (PyYAML optional, with a JSON fallback). CPU only, no network; the mock LLM keeps the run deterministic.
  • A real model is optional through any OpenAI-compatible endpoint (the KatalockAi API or a local model), behind the same interface and a --mock flag for the graded run.
  • Fixtures describe attack techniques and must use placeholders such as [restricted procedure] for the harmful payload. Never put real operational harmful content in the repo or in your outputs.
  • Rule-based classifiers are teaching tools, not production moderation. Say so in the README.

Stretch Goals

  • Replace the deterministic aggregator with a weighted score and sweep the threshold to plot precision against recall on the taxonomy.
  • Add a seventh category for indirect prompt injection through retrieved documents, with ten fixtures.
  • Run the during-gen filter in a thread and show the added latency stays within a 50 ms budget.

How to Submit

Public repo with safety/ (taxonomy, detector, refusaleval, classifiers, rules, gate, mockllm), fixtures/, rules.yml, main.py, tests/ and results/ (taxonomy.json, detectorreport.json, refusalevalreport.json, classifierreport.json, rulesreport.json, gatetrace.json). The README must name the product you are protecting, give run commands, explain the trust boundary each category abuses, show your detector and refusal metrics, explain the aggregation table and any change you made to it, and give an honest account of what the gate misses and what you would add next.

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.

CriterionWeightHow it's checked
End-to-end gate and traces25Pasted `python main.py` output shows every fixture plus 10 or more benign prompts processed, action counts with per-category breakdown, at least one early termination, gate_trace.json written with full RequestTrace fields, exit 0.
Detector and measurement20detector_report.json has per-category precision, recall, F1 and raw counts over the taxonomy and a 20+ prompt benign set; tests show base64, rot13, leet and zero-width normalisation exposing hidden tokens.
Output-side layers15Classifier report shows block, redact, warn and log each firing with redacted output; rules report shows violations, a not_applicable case, a fixer diff and two learner-written product rules.
Refusal evaluation10Report compares the three mock policies with under-refusal, over-refusal, accuracy, ECE and per-category breakdown in the expected order.
Code quality10Rules and patterns live in data files, each layer has a narrow interface the gate composes, fixtures use placeholders, pytest suite passes.
README and honest analysis20README names the product, explains categories and the aggregation table, reports block rate, benign false-block rate and leaking categories with a real missed trace, and lists next steps.

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.

  • Full output of `python main.py` with the summary table
  • Per-category metrics from detector_report.json
  • The three-policy comparison from the refusal evaluation
  • One complete RequestTrace for a blocked request and one for a missed attack
  • Output of `python -m pytest -q`
  • A paragraph on which category leaks most and why

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.