🩺 Klinik Dr Fang Front-Desk Assistant

Front-desk AI for clinics that can't leak patient data

MCP Toolbox Pattern SQLite (read-only) Gemini Flash (BYOK) sql.js / WebAssembly Semantic Search Python

📋 Project Overview & Problem Statement

Challenge: A single-doctor clinic wants quick answers to operational, population-level questions about its patient records — "are we seeing a lot of similar cases lately?", "who hasn't been in for a year?" — without anyone learning to write database queries. But wiring an LLM straight to patient data is exactly the risk a clinic can't take: a cleverly worded prompt could make the model dump every record or run a destructive query. For privacy-sensitive data, "it usually behaves" is not good enough.

Solution: A front-desk assistant that surfaces patterns across patient records in plain language — while being structurally incapable of leaking data or running its own SQL. The agent never touches the database. Between it and the data sits a governed tool layer (the MCP Toolbox for Databases pattern): a fixed set of pre-written, parameterized queries that are the only actions the agent can take.

The headline isn't "I built an AI agent." It's "I built one a privacy-sensitive clinic could actually trust." The differentiator is data governance over novelty.

Key Benefits

🖥️ Application Features

🔬 Symptom Clustering

Groups recent presenting complaints into clusters of similar symptoms — an early-outbreak signal that surfaces a grouping nobody explicitly searched for.

📈 Condition Trends

Shows whether a condition (e.g. suspected dengue) is becoming more common across recent months, returning the monthly shape for the agent to explain.

👥 Patient Segmentation

Segments the whole patient base by visit frequency and average spend — High-frequency, Regular, Occasional groups — at summary level only.

📞 Lapsing-Patient Recall

Lists patients not seen in over a year — a recall list returning name and last-visit date only, never clinical notes.

⚠️ Frequent Attenders & Spikes

Flags patients visiting unusually often, and the top presenting complaints in a given month to catch any unusual spike.

🗓️ No-Show & Demand Patterns

No-show rate by weekday and busiest-day analysis — operational patterns for staffing and scheduling decisions.

🤖 AI Integration & Intelligence

🧠 Reasoning, Not Querying

Gemini Flash reasons about which approved tool to call and explains the result in plain language. Its intelligence goes into understanding the question — never into writing SQL.

🔒 The No-Free-SQL Guarantee

Four governance layers: the toolset is the agent's entire universe (no execute_sql), the SQL is fixed with only values bound, toolset scoping controls access, and the database user is read-only.

🔎 Semantic Search

Vector embeddings on case notes power "find cases that resemble this one" and symptom clustering — meaning-based matching, not just keywords.

🔑 Bring-Your-Own-Key (BYOK)

The live conversational layer uses your own free Gemini key, held in your browser only. Nothing is hard-coded or committed; the data layer and guardrails cost nothing to run.

🛠️ Technical Architecture & Implementation

Agent & Tool Layer

Google Gemini Flash MCP Toolbox for Databases pattern tools.yaml (declarative) Python

Data & Semantic Search

SQLite (read-only) Vector embeddings Cosine similarity

Live Browser Demo

sql.js / WebAssembly Client-side SQL GitHub Pages (static)

System Architecture

📖 Development Setup & Installation Guide

Prerequisites

Quick Start

# Clone the repository git clone https://github.com/lyven81/ai-project.git cd ai-project/projects/klinik-dr-fang # Install dependencies pip install -r requirements.txt # Build the synthetic SQLite database python data/generate_data.py # Prove the guardrails (everything should be refused) python demo/guardrails_demo.py # Chat — deterministic mode (no LLM, zero cost) python agent/agent.py # Chat — live mode (Gemini, bring-your-own-key) python agent/agent.py --live

Bring-Your-Own-Key Configuration

# Get a free key at https://aistudio.google.com/apikey # Copy the template and paste your key (the .env file is git-ignored) cp .env.example .env # .env contents: GEMINI_API_KEY=your_key_here

🚀 Deployment

Live Demo (GitHub Pages — free, no key)

The interactive demo loads the real synthetic SQLite database in the browser via sql.js and runs the same fixed, parameterized queries client-side. No server, no key, nothing to install — it works on free static hosting.

Production Notes

📊 Key Metrics

10
Pre-Approved Tools
4
Governance Layers
0
Free-SQL Capabilities
RM 0
Cost to Run the Demo

Business Value