Client case study · AI Transformation · LLM System Design

The AI that
answers from the
rule.
Not from its
assumptions.

A public e-learning platform needed an AI that answers driving-theory questions from the regulatory text — not from the model's assumptions. I designed the evaluation framework, tested six models across three adaptation strategies, and produced a three-model, CPU-only architecture — answering, question generation, and quiz scoring — that turns research into a production platform.

Gemma-2-2b grounded accuracy
73.7%
Ungrounded accuracy
26.3%
Fine-tuned only
24.8%

At a
glance.

Five numbers that summarise the whole story — the rest of the page explains how they were achieved.

73.7%gemma-2-2b grounded accuracy — the most accurate AND most grounded model
5.1%hallucination rate (down from 77%)
6 → 3models screened, three production-viable roles — all on CPU
~800questions generated, validated, and reduced to 137 clean benchmark questions
CPU-onlyno GPU tier required — every model in the recommended config runs on consumer CPU

All evaluation ran on local infrastructure — a controlled environment that allows full experimentation without engaging public APIs or exposing data to external services. Production will run on provisioned servers sized from these measurements.

The
challenge.

A public e-learning platform needed an AI tutor that answers driving-theory questions from the UK Highway Code. Students ask about roundabouts, overtaking rules, and right-of-way — the system must answer only from the regulatory text, not from the model's assumptions. Public platform = thousands of concurrent users, real revenue, real liability. Three questions: Which model? How reliable is it? What infrastructure does it need?

The grounding problem is brutal. UK drives on left, rest of world on right. LLMs trained on right-hand-traffic data carry conflicting prior knowledge. When student asks about roundabouts, model might answer with right-hand-traffic logic. Model's intelligence is a liability. System must answer only from regulatory text.

Infrastructure problem: public platform = real servers, RAM, token throughput, cost model. 0.5B model needs fraction of hardware of 7B model, but can it be reliable? Answer determines server spec, hosting budget, unit economics.

Before — assumptions

The guessing game

Pick a model, deploy it, see what happens. No benchmark, no protocol, no infrastructure plan.

75% hallucination. Right-hand-traffic answers for a left-hand-traffic code.
Ungrounded accuracy26%
Hallucination rate75%
After — measured design

The grounded system

Measured model selection. Grounding protocol. Infrastructure spec derived from real throughput.

Hallucination cut to 5%. The system answers from the rule, not from assumptions.
Grounded accuracy (gemma)73.7%
Hallucination rate5%

This was not a model experiment. It was the design phase of a production AI system — the same methodology I'd apply to any regulated, document-grounded domain.

The
methodology.

The knowledge base is the UK Highway Code — a single, well-defined regulatory document. I built a domain benchmark from the Code itself: over 800 questions were generated by the candidate models, validated by two independent LLM judges and a human audit, and reduced to 137 clean benchmark questions. Six models were screened. Three survived on measured grounds. The surviving three were tested across four adaptation strategies: ungrounded, grounded, fine-tuned, and fine-tuned + grounded. All evaluation ran on local consumer hardware — a controlled, reproducible test environment.

Highway Code
6-model screening
~800 questions generated
Dual-LLM + human validation
137 clean questions × 3 models × 4 strategies
Three-model architecture + infrastructure specs

Evaluation design

  • 6 open-weight models (0.5B – 7B) screened on a pilot set
  • ~800 questions generated by the candidate models themselves
  • Two independent LLM judges + 30-question human audit (87.9% agreement)
  • 137 clean benchmark questions (after validation and filtering)
  • 4 adaptation strategies per model: ungrounded, grounded (RAG), fine-tuned, fine-tuned + grounded
  • Local inference = controlled, reproducible test environment

Validation protocol

Strict prompting: "Answer ONLY from the provided text. If the answer is not in the text, say I DON'T KNOW." This is what drives hallucination below 10%. Without it, even the grounded models drift. The prompt is the safety mechanism.

The
findings.

04.1 — Model Selection: Six In, Three Roles

Six models were screened on a pilot set. Three were eliminated on measured grounds: one was too slow for the latency budget, one produced structurally broken output, one had the weakest answer quality. All three survivors run on consumer CPU — there is no GPU/CPU fork in this deployment. The result is a role split across the three models: gemma answers, phi generates questions, and fine-tuned Qwen2-0.5B scores quizzes.

Model A · Qwen2-0.5B
0.5B parameters
✓ Quiz-scoring model
Fine-tuned: 82.5% on constrained MCQ (vs 60% base) — cheapest to run, ~27 tok/s on CPU
Model B · Phi-3.5-mini
3.8B parameters
✓ Question-generation model
Strongest CPU-capable generator (8/10 valid MCQs) — CPU-viable (~13 tok/s). Not the primary answerer.
Model C · Gemma-2-2b
2B parameters
✓ Primary answering model
Best accuracy AND best hallucination (5.1%) — ~17 tok/s on CPU, faster than Model B. Also a capable generator (7-8/10).
Model D
3B parameters
✗ Eliminated
Weakest answer quality
Model E
1B parameters
✗ Eliminated
Structural failures
Model F
7B parameters
✗ Eliminated
Too slow for latency budget
Insight: All three surviving models run on consumer CPU — there is no GPU/CPU fork in this deployment. Both gemma-2-2b and phi-3.5-mini are capable in both roles — answering and generating questions — which makes this a genuine optimisation, not a case of one model being unusable outside its assigned job. Gemma is the stronger, safer answerer (highest accuracy, lowest hallucination, faster on CPU despite fewer parameters); phi is the marginally stronger question generator (8/10 vs gemma's 7-8/10 across two test rounds). Splitting the roles between them — rather than picking one model to do both jobs — gets the best result from each, while Qwen2-0.5B, fine-tuned, handles the lightweight quiz-scoring role neither larger model needs to be wasted on. Crucially, gemma's safety is free: it reaches the low hallucination rate with RAG alone, whereas phi only matches it by adding fine-tuning that costs accuracy — so gemma is the stronger answerer not because its numbers are marginally better, but because its safety costs nothing.

04.2 — The Grounding Effect: The Core Finding

The single most important finding: grounding the model in the source text is what makes it work. Without grounding, accuracy is 12–26% and hallucination is 75–77%. With grounding, accuracy jumps to 34–75% and hallucination drops to 5–35%. The model's general knowledge is not the asset. The regulatory text is.

Model A 0.5B parameters
Ungrounded
12%
Grounded
34%
Model B 3.8B parameters
Ungrounded
26%
Grounded
75%
Model C 2B parameters
Ungrounded
23%
Grounded
74%
UngroundedGrounded (RAG)
Insight: Grounding is not an optimization — it's the difference between a system that's unusable and a system that's reliable. For all three models, supplying the source passage more than doubles accuracy and cuts hallucination by more than half. This is the design principle for any document-grounded AI system.

04.3 — Hallucination & Domain Drift: The Safety Problem

In a driving-theory context, hallucination isn't a quality metric — it's a safety risk. A model that confidently tells a student 'you can overtake on either side' is not a UX bug. It's a potential harm. And there's a subtler risk: domain drift. The model's general knowledge (right-hand traffic) silently overwrites the regulatory text (left-hand traffic) — not because the model is broken, but because the general prior is stronger than the retrieved passage unless explicitly suppressed.

Model A · Qwen2-0.5B
0.5B parameters
35%
Baseline · ungrounded77%
Grounded · RAG (risk)35%
+FT27%
Model B · Phi-3.5-mini
3.8B parameters
13%
Baseline · ungrounded76%
Grounded · RAG (risk)13%
+FT4%
Model C · Gemma-2-2b
2B parameters
5.1%
Baseline · ungrounded77%
Grounded · RAG (risk)5.1%
+FT8%
The red wedge (grounded · RAG hallucination) sits on the same ring as the rest — enlarged and highlighted, not moved off it. It shrinks A → B → C: the smaller the wedge, the safer the system.
Key callout: The strict prompting protocol — "Answer ONLY from the provided text. If the answer is not in the text, say I DON'T KNOW" — is what drives hallucination below 10%. Without it, even the grounded models drift. The prompt is the safety mechanism.
The hidden cost of chasing lower hallucination: Phi can match gemma's low hallucination rate — but only by adding fine-tuning on top of RAG, which drops its accuracy from 74.5% to 54.0%. Gemma reaches the same safety level for free, with RAG alone. For gemma, fine-tuning doesn't help at all — it actually makes hallucination worse (5.1% → 8.0%). This is the strategic reason gemma is the stronger choice: its safety doesn't cost anything beyond the base grounding strategy.
No model overwrote the UK-specific retrieved text with pre-trained right-hand-traffic knowledge when the strict protocol was applied. The drift risk is real but manageable — it's a protocol problem, not a model problem.

04.4 — Infrastructure Planning: The Cost Question

The platform is public. That means real servers, real costs, real latency budgets. Each model has a specific footprint: RAM, token throughput, latency per answer. Every measured number is a CPU figure — no GPU is required for the recommended configuration.

Primary answering model

Gemma-2-2b

2B parameters
~3 GB RAM · ~17 tok/s on CPU · no GPU required
✓ Best grounded accuracy in the study (73.7%)
✓ Best hallucination rate (5.1%)
Deploy as: the model that answers student questions, grounded via strict RAG.
Question-generation model

Phi-3.5-mini

3.8B parameters
~13 tok/s on CPU (also CPU-viable, no GPU required)
✓ Strongest CPU-capable generator (8/10 valid MCQs)
✓ gemma is a close second (7-8/10) — fallback generator
Deploy as: an offline/batch model that builds and expands the question bank — not part of the live answering path.
Quiz-answering model

Qwen2-0.5B (fine-tuned)

0.5B parameters
~27 tok/s on CPU · cheapest to run
✓ 82.5% on constrained MCQ answering after fine-tuning (vs 60% base)
Deploy as: the lightweight model answering multiple-choice quiz questions.
Model D (3B), Model E (1B), Model F (7B) — screened out. Weakest answer quality, structural failures, and too slow for the latency budget respectively. None survive into the production architecture.
Insight: This is a three-model production architecture, not a single model with a GPU/CPU choice. Every component runs on CPU, which simplifies hosting considerably — no GPU server tier is required at all for the recommended configuration, though GPU hosting would further speed up gemma if available.
Cost framing: This is where the research meets the business. A CPU-only production stack means one hosting tier instead of two — no GPU server budget line at all for the recommended configuration. The architecture is sized from measured RAM and throughput, not from a vendor's default SKU.

Business
impact.

A CPU-only production architecture

All three recommended models run on consumer CPU. No GPU hosting tier is required — a meaningful cost simplification for the hosting budget.

5% hallucination, not 75%

The grounding protocol + strict prompting cuts hallucination from 75% to 5%. For a public platform where wrong answers create liability, that's the difference between a product and a lawsuit.

Roles, not trade-offs

The system doesn't force a choice between accuracy and cost. Two of the three models are competent at both answering and generating questions — the architecture isn't about working around a weak model's limits, it's about assigning each model to the job it's marginally best at. Three small models, each doing the job it's actually best at — answering, question generation, and quiz scoring — outperform any single model doing all three.

A methodology, not a one-off

The same evaluation framework applies to any document-grounded, regulated domain: legal, medical, compliance, insurance. The driving-theory platform is the proof of concept.

My
role.

AI System Design · Model Evaluation · LLM Strategy · Infrastructure Planning

  • Defined the evaluation framework: 6 models × 4 strategies × 137 questions
  • Screened 6 open-weight models: eliminated 3 on measured grounds
  • Built the domain benchmark: from the UK Highway Code with dual-LLM + human validation
  • Designed the strict-prompt grounding protocol: drives hallucination below 5%
  • Measured RAM and throughput: produces the CPU infrastructure spec
  • Validated LLM judges: 30-question human audit (87.9% agreement)
  • Delivered the three-model architecture: answering, question-generation, and quiz-scoring roles — all CPU
  • Maintained full data confidentiality: via local evaluation throughout

What I
learned.

  • The model's intelligence is not the asset. The document is. For document-grounded domains, the model's general knowledge is a liability, not an advantage. The system must answer from the text, not from the weights.
  • Hallucination is a protocol problem, not a model problem. The same model hallucinates 77% without a strict protocol and 5% with one. The prompt is the safety mechanism. Design the protocol before you pick the model.
  • The minimum viable model is a cost decision, not a technical preference. Two models cleared the reliability bar — the choice between them is a business decision, derived from data and driven by hardware budget and the tighter constraint (accuracy vs safety).
  • Always validate your judges. A parser bug initially showed the smallest model (0.5B) as the best performer — 92.5% accuracy. After fixing the bug, the ranking inverted: 36.1%. The smallest model was not the best. A human audit caught it. In any LLM system, the evaluation pipeline is as important as the model itself.

Recommendations
for the client.

Based on the findings, here are the specific recommendations for the production platform:

  1. Deploy a three-model architecture, not a single model. gemma-2-2b answers student questions via strict RAG — it's both the most accurate and the most grounded model in the study, and it runs comfortably on CPU. Phi-3.5-mini runs offline to generate and expand the question bank — it's the strongest CPU-capable generator, marginally ahead of gemma (which is capable of the same job as a fallback), but not the model students interact with directly. A fine-tuned Qwen2-0.5B handles quiz scoring, where it reaches 82.5% accuracy at minimal cost. No GPU hosting tier is required for this configuration. Choose gemma as the answerer because its safety is free — RAG alone gets it to the 5.1% hallucination rate, whereas phi only matches that level by adding fine-tuning that sacrifices accuracy (74.5% → 54.0%).
  2. Implement the strict-prompt protocol as a non-negotiable safety mechanism. "Answer ONLY from the provided text. If the answer is not in the text, say I DON'T KNOW." This is what drives hallucination below 5%. Without it, even the grounded models drift.
  3. Build a question-generation pipeline using a larger model (3.8B+). The smallest model (0.5B) cannot reliably generate multiple-choice questions — it produces ambiguous or overlapping options. A 3.8B model generates valid MCQs (8/10 pass rate). Use it for offline question bank building.
  4. Consider fine-tuning for the constrained quiz task. Fine-tuning on 194 open-form QA pairs did not improve accuracy. But fine-tuning on 40 multiple-choice pairs lifted the smallest model from 60% to 82.5% — a statistically significant improvement. If the platform uses MCQs, fine-tuning the smallest model for that specific task is cost-effective.
  5. Plan the infrastructure from the measured numbers. gemma-2-2b needs ~3 GB RAM and runs on CPU at ~17 tok/s. Phi-3.5-mini is also CPU-viable (~13 tok/s). The fine-tuned Qwen2-0.5B is the cheapest to run (~27 tok/s). All three map to a single CPU server spec — not a guess, and no GPU tier is required. GPU hosting would further speed up gemma if available, but it is not needed for the recommended configuration.
  6. Validate the evaluation pipeline before trusting the results. A parser bug initially inverted the entire model ranking. Always validate LLM judges against a human audit. In this project, the 30-question human audit (87.9% agreement) confirmed the ranking was stable.

Consultant
perspective.

How I would approach designing an LLM system for any document-grounded, regulated domain:

  1. Audit the sourceIdentify the authoritative text, its structure, and where the model's general knowledge conflicts with it.
  2. Build the benchmarkCreate domain questions from the source. Validate with dual judges + human audit.
  3. Screen the modelsTest candidate models on a pilot set. Eliminate on measured grounds: accuracy, hallucination, throughput.
  4. Design the protocolStrict grounding, abstention rules, safety filters. The prompt is the product.
  5. Measure the infrastructureRAM, tok/s, latency. The model choice is a cost decision.
  6. Deploy & validateProduction on provisioned servers. Continuous monitoring. Periodic human audit.

And this is where I work best — at the intersection of business needs and data-driven evidence.

Technology
stack.

Benchmark & Validation

UK Highway Code (17th ed.) · ~800 questions generated · 137 clean benchmark questions · Dual LLM judges · 30-question human audit (87.9% agreement)

Model & Strategy

QLoRA fine-tuning · RAG (retrieval-augmented generation) · Strict-prompt protocol · Sentence-transformer embeddings · 3 models × 4 strategies

Infrastructure

Measured RAM per model · Token throughput benchmarks · CPU scenario specs · Production-ready infrastructure plans

Final
results.

73.7%gemma-2-2b grounded accuracy — the most accurate AND most grounded model
5.1%lowest hallucination rate
0.5B · 2B · 3.8Bthree models, three roles — all on CPU
6 → 3models screened, three production-viable roles

A generic AI that hallucinates 75% of the time, designed into a grounded, three-model system that hallucinates 5% — with a CPU-only production architecture, specific server specs, and a specific cost model for each role. The research is done. The platform is ready to build.

Discuss your LLM system

Let's make
it real.

Have a process, a problem or an idea worth analysing? Write to me and we will turn it into a concrete next step.

Client confidentiality: client identity and commercially sensitive information have been anonymised. Model names are shown as generic references (Model A/B/C). All evaluation performed on local infrastructure for controlled, reproducible testing.