Designed and built
LLM System Reliability
A question-answering system that cites its sources, says it does not know when the evidence is too thin, and is tested against questions designed to trick it.
Documented a break-and-harden cycle and passed 8 golden plus 10 adversarial cases in the current audit. The result is an inspectable prototype, not a validated safety benchmark.
Case study at a glance
The problem, the decision, and the work.
- Problem
- A RAG system can answer confidently when its retrieved text only partially supports a question. In regulated settings, that failure needs an explicit, testable response.
- Product decision
- The product decision is when to answer, abstain, or ask for more evidence. Building and breaking the gate made that tradeoff concrete rather than leaving it to a model prompt.
- What I built
- A Python RAG reliability toolkit with BM25 retrieval, rule-based abstention, extractive cited answers, lexical faithfulness checks, and regression tests. Core modules use no ML framework.
I built a small, auditable RAG pipeline to study a practical reliability question: when should a system answer from retrieved evidence, and when should it refuse? The current implementation ranks a curated document corpus with BM25, combines retrieval strength and query coverage into a rule-based answerability score, and hard-abstains when distinctive query terms are unsupported. Answers are extractive and cited; a lexical faithfulness check provides another gate. Golden and adversarial cases record where the rules fail and guide revisions.
- 1.Grounded Retrieval: Use BM25 to rank a curated document corpus and require a relevant evidence floor before generation.
- 2.Evidence-Based Abstention: Combine top-hit strength, score margin, term coverage, IDF-weighted coverage, and evidence density. Hard-abstain when distinctive query terms are missing.
- 3.Cited, Extractive Answers: Build answers from retrieved sentences and retain source IDs so each answer can be checked against its evidence.
- 4.Faithfulness and Regression Checks: Flag unsupported answer tokens with a lexical faithfulness metric, then run golden and adversarial cases after changes.
- ◆Modular Pipeline: Separate retrieval, abstention, generation, and evaluation so each stage can be tested and replaced independently.
- ◆Break, Then Harden: An adversarial audit found that partial matches on common terms could trigger answers to unsupported questions. IDF-weighted coverage and hard gates now catch those cases.
- ◆Test Both Error Directions: The suites check that unsupported questions abstain and that legitimate in-corpus questions still receive answers. The audit records 8 golden and 10 adversarial cases passing after hardening.
- ◆State the Limits: The score is a hand-tuned retrieval heuristic, not a calibrated probability. Lexical overlap is not semantic entailment; a larger, held-out evaluation is a next step.
A query about Basel capital requirements initially produced an answer from Bank Secrecy Act material because common words such as banks overlapped. The fix was to treat missing distinctive terms as a hard reason to abstain, rather than a small penalty in an average score. Follow-up checks also caught over-refusal on legitimate queries.
BM25 ranks the source documents. The abstention module evaluates retrieval strength, score separation, term coverage, IDF-weighted coverage, and evidence density. If the evidence clears the gates, the generator assembles cited sentences from the retrieved text. A lexical faithfulness check can reject the answer after generation. Golden and adversarial suites exercise the full path.