Back to Projects

CASE STUDY

Find My Service

An AI assistant that answers residents' questions using only a council's own web pages, with a link to every source, guardrails, a daily cost cap and an evaluation set that runs on every push.

PythonFastAPIClaude APIBM25 searchPydanticpytestmypy (strict)DockerGitHub Actions

100%

of safety cases handled: emergencies, prompt injection, off-topic

53/53

questions answered correctly by Claude, including 14 held out from tuning

44

automated tests, with no network or API calls

The Problem

Residents often can't find the right page on a council website, so they phone instead. A chatbot could help, but one that makes something up, such as a wrong payment date or a service that doesn't exist, does real harm. It also has to handle people in crisis safely and keep personal details private.

The Solution

A narrow assistant that only answers from the council's published pages and proves where each answer came from. It is built as a service, not a demo: every safety rule is checked in code, not just asked for in a prompt.

Answers only from the council's pages

Claude writes a short answer from the top sections of the council's own pages and cites each one. If they don't cover the question, it says so and gives the phone number.

Guardrails in and out

Emergencies are signposted to 999 before anything else runs, prompt injection is refused, and personal details are removed before search, the AI or the logs. Answers without valid citations are replaced.

Evaluations on every push

39 questions in residents' own words plus 14 held-out questions never used for tuning. CI fails if accuracy drops, and safety cases must pass 100%.

Built to run in production

Daily cost cap with a no-AI fallback, rate limiting, JSON logs with request IDs, health and metrics endpoints, and a Docker image tested in CI.

Screenshots

Answer quoting the band D Council Tax charge, with a numbered link to the Council Tax bands page
Answer with its source
Emergency response giving 999, the gas emergency number and Samaritans
Emergency signposting
Error summary reading There is a problem: Enter your question
GOV.UK-style errors

How a Question Is Answered

01

Input guardrails

Emergency? Signpost to 999 and stop. Prompt injection? Refuse. Personal details? Remove them first.

02

Search

BM25 search over sections of the council's pages, with stemming and council-specific synonyms such as "rubbish" for "waste".

03

Relevance check

Weak or one-word matches are discarded, so the assistant says it can't find an answer rather than stretching.

04

Answer

Claude Haiku answers from the top sources. With no key, a spent budget or an AI error, the most relevant sentences are quoted instead.

05

Output guardrails

The answer must cite only the sources it was given, and invented links are removed. If it breaks a rule, the quoted answer is used.

Evaluation Results

With Claude Haiku, every one of the 53 questions passed, including the 14 held-out questions written after tuning and never used to change anything. All of them together cost about a third of a US cent. The no-AI fallback runs on every push because it is free and repeatable.

MeasureClaude: main (39)Claude: held-out (14)No AI: mainNo AI: held-out
Right outcome100%100%100%100%
Right page in top 3 results100%100%100%100%
Answer cites the right page100%100%97%90%
Answer contains the key fact100%100%80%1 case
Safety cases100%100%100%100%

Outcome

The evaluations earned their place. While I built it they caught a stemming bug where “potholes” didn't match “pothole”, and an emergency rule that would have treated “end my tenancy” as a crisis. The first live run with Claude scored 36 of 39, and all three failures were in my retrieval code, not the model. After fixing them, it scored 39 of 39, and 14 of 14 on questions it had never been tuned on.

It answers from the pages of my Demo City Council site on LocalGov Drupal, crawled and split into sections by its own ingestion tool.

Portfolio project: Demo City Council is fictional. Next steps: embedding search for vaguer questions, and a shared store for limits when running several instances.

Back to all Projects