0→25/27scenarios passed with the AI model unavailable (2.0 → 2.1)
01The problem
Why it exists
Patients chat in Arabic, including Saudi dialect, or English. Mawid finds real availability, holds a slot and books it once the patient confirms. It also reschedules, cancels, answers clinic questions and hands over to staff, on the web or on WhatsApp. Version 2.0 adds the front desk around it: staff roles, reminder links, attendance and no-show tracking, leave blocks and doctors' calendar feeds. The language model is treated as untrusted: every action goes through validated tools, and the server has the final say. Version 2.1 keeps it working when the model is wrong or missing: a fallback chain ending in deterministic rules, holds grounded in what the patient actually wrote, and safety gates that fail the build. Version 2.2 works on the empty chairs: a no-show risk model scores every booking, high-risk patients get a second reminder, cancelled times go to a waitlist through signed links, and an insurance check runs against a simulated payer.
02The system
What I built
Patient chatweb and WhatsApp
Booking agentserver-validated tools
Availability engineshifts, Hijri dates
Two-phase bookinghold, then confirm
Clinic consoleroles, reminders
A tool-calling agent with seven server-validated tools and a fallback chain: two Groq models, then rules that still find, hold and confirm real times with no model at all
Safety gates in CI: a scripted adversarial model tries to self-confirm, hold unoffered times, invent patient details and obey an injected "already confirmed"; the server must refuse every one
An availability engine: split shifts, service length, doctor gender, "after 4" and «المسا» filters, Hijri dates
Two-phase booking: the agent can only hold; booking needs the patient's explicit confirmation, enforced on the server
WhatsApp booking over a signed Meta webhook: times arrive as a numbered list, and "2" and "yes" are resolved by code, not the model
A signed-in clinic console with manager, reception and doctor roles: check-in and no-show tracking, walk-ins, doctor leave that the scheduler and database both enforce, and signed reminder links where patients confirm or cancel
A private iCalendar feed per doctor that carries first names only
A no-show model (12 features, trained on fictional history; AUC 0.68 vs 0.56 for the "missed before" rule), a second reminder for the riskiest fifth, and a waitlist that refills cancelled times without ever double-booking
A held-out evaluation: 40 new scenarios written only from the clinic's facts, never used to tune the rules
03The result
What it achieved
No double-bookings by construction: 25 concurrent overlapping requests always produce exactly one booking. On a 27-scenario evaluation (English, Arabic and mixed, clean and messy) that checks outcomes in the database, version 2.0 passed 22/27 and failed a safety gate by booking from an injected "already confirmed" message; with the model unavailable it answered nothing (0/27). Version 2.1 passed 24/27 with all gates, and 25/27 on rules alone with no model. The intervals overlap at this sample size and the rules were written alongside the scenarios, so the clear gains are the closed safety gap and staying up when the model is down. 41 unit tests, $0 to run. On the 40 held-out scenarios the rules alone scored 25/40 (95% CI 47–76%), the honest estimate, with every safety scenario passing. The run found real bugs, now fixed: «عمره» (his age) matched Dr. «عمر», and a phone number in Arabic-Indic digits leaked into the patient's name.