AI Water Compliance Assistant
Conversational Analytics for Drinking-Water & Wastewater Utilities
My Role
- Reasoning router plus four services, not one LLM
- LLM explains; SQL computes every compliance number
- Per-user prompt tuning from categorised negative feedback
Approach at a Glance
Details- 1Reasoning-First Request Router
- 2The LLM Writes, SQL Computes
- 3Anti-Injection Guardrails
- 4Entity Matching to Live Records
- 5Regulation Q&A over a Domain Knowledge Base
- 6Predictive Trend Analytics
- 7Feedback-Driven Prompt Tuning
Executive Summary
An AI assistant built into a water-quality compliance SaaS platform used by drinking-water and wastewater utilities. Compliance staff ask questions in plain language and get answers built from their own monitoring data and from the regulations that apply to them. Typical questions are "Which parameters exceeded Safe Drinking Water Act limits?", "What's the monthly-average trend at this location over the last nine months?" and "What's the maximum allowed lead level in California?". The assistant can also forecast when a parameter is likely to reach its critical limit, and it can draft correspondence about the results.
I joined the project in August 2024, when it was moving from a prototype to production, and took over its architecture. I rebuilt the core around four specialized AI services behind a reasoning-first request router. In that design the LLM interprets and explains, while SQL computes every compliance number. I also built two things myself: anti-injection guardrails for the database layer, and a feedback loop that automatically tunes each user's prompts. The assistant went into production, resolving 85% of queries without escalation, with an average response time under 5 seconds.
Client Profile
The client is a SaaS provider of water-quality compliance software. Its customers are drinking-water and wastewater utilities, and each utility is a separate tenant with its own water systems, facilities, sampling locations and measured parameters.
Compliance work in this field is unforgiving. Regulatory limits vary by rule and by state. Calculations such as daily maximums, monthly averages, single-result evaluations and industrial-pretreatment surcharges have exact definitions. The cost of a wrong number is regulatory risk, not just an awkward answer. Even so, the staff responsible for compliance are usually not data specialists.
The platform had three problems to solve:
- Compliance status was hard to read: working out which parameters break which limits took expertise.
- The data was locked in dashboards: a simple question meant many clicks, or a SQL query nobody on staff could write.
- Regulation lookups were slow: limits had to be looked up rule by rule.
Any AI layer also had to keep each utility's data strictly isolated and earn the trust of non-technical users.
Technical Approach
-
Reasoning-First Request Router – I replaced the original single-LLM design with an LLM classifier. It reasons about each request, using the conversation history so that follow-up questions work naturally, and only then routes it to one of four specialized services: compliance evaluation, sample results, trend analysis or regulation Q&A. Because the classifier reasons explicitly before routing, misrouted requests became traceable and fixable. That mattered, because telling a compliance question from a sample-results or trend question was one of the hardest parts of the project.
-
The LLM Writes, SQL Computes – No compliance figure is generated by the language model. The LLM rephrases and parses the user's request into a structured form that is safe to run as a direct query against the client's MSSQL database. The numbers come from deterministic queries that implement the exact regulatory calculations, and the LLM only turns the results into a clear explanation with charts and suggested follow-up actions. Every query is tenant-scoped, so each utility sees only its own data.
-
Anti-Injection Guardrails – Because natural language is turned into database queries, I designed dedicated guardrails against prompt and query injection. They make sure a user's message cannot change the query's intent, reach other tenants' data, or step outside the allowed operations.
-
Entity Matching to Live Records – Users rarely type location or parameter names exactly as they appear in the database. A matching layer combines character n-gram similarity with LLM disambiguation to resolve names such as a site or a contaminant to the correct record before any query runs.
-
Regulation Q&A over a Domain Knowledge Base – Regulatory and methodology questions go to a RAG pipeline over more than 10,000 indexed domain documents, stored in Qdrant with open-source sentence-transformer embeddings. This grounds answers about rules, limits and calculation definitions, including US Safe Drinking Water Act requirements, in the source text.
-
Predictive Trend Analytics – A scheduled job recalculates trends every 30 minutes. It uses Prophet forecasts to estimate whether, and in how many days, a parameter will reach its critical limit, and statistical anomaly detection to flag unusual readings. The assistant presents these results in plain language, so staff can see a violation coming before it happens.
-
Feedback-Driven Prompt Tuning – Each answer can be rated. Negative ratings must name one of 9 structured feedback categories, which turns vague dissatisfaction into something the system can act on. Every 30 minutes, an LLM summarizes each user's negative feedback into concrete improvement points and rewrites that user's system prompt. The result is per-user personalization with no model training. The hard part was making answers improve steadily without the prompts drifting or breaking existing behavior.
The service runs on FastAPI with async SQLAlchemy over MSSQL. It uses Azure OpenAI and is deployed to Azure Kubernetes Service through Azure DevOps pipelines, with OpenTelemetry tracing and a comprehensive unit-test suite.
Business Outcome
The assistant went into production inside the client's compliance platform. It resolves 85% of queries without escalation, measured from user feedback and support escalation logs. It responds in under 5 seconds on average according to production tracing, in multi-turn conversations. Utility staff can now get compliance answers that used to take a specialist or a SQL query, and see where each parameter is heading before it breaches its limit.
The architecture let the client offer AI in a domain where numbers must be exact. The language model handles understanding and explanation, while every regulated figure comes from deterministic, tenant-scoped, injection-guarded queries. Feedback-driven prompt tuning kept improving answers for each user without any model retraining.
Technologies
Planning something similar?
Tell me about it on a short call. New projects can start within 2 weeks