File size: 2,847 Bytes
88a18c6
 
 
 
 
 
 
 
 
 
45a648e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
title: SaniPlus Chatbot
emoji: πŸ’Š
colorFrom: green
colorTo: blue
sdk: docker
app_port: 8100
pinned: false
---

# SaniPlus Apotheken β€” KI-Assistent (LLM-backed)

A working showcase of the scoped pharmacy chatbot, now powered by a **real large
language model (Claude)** behind a secure backend. It keeps the exact safety
design from the decision brief: a deterministic classifier gates every message
server-side, clinical and emergency questions never reach the model, and the
model answers **only** from SaniPlus's verified knowledge base.

## Architecture

```
Browser (public/index.html)
   β”‚   POST /api/chat  (conversation history + language)
   β–Ό
Node + Express backend (server.js)   ← API key lives here, never in the browser
   β”‚   1) Deterministic safety classifier (EMERGENCY / CLINICAL / PII / SAFE)
   β”‚      β€’ EMERGENCY  β†’ fixed "call 112 + Notdienst" message (no model call)
   β”‚      β€’ CLINICAL   β†’ fixed "see a pharmacist" referral (no model call)
   β”‚      β€’ PII        β†’ consent-first callback flow
   β”‚      β€’ SAFE       β†’ Claude, grounded on the knowledge base (kb.js)
   β–Ό
Claude (claude-opus-4-8) β€” streams the answer back as Server-Sent Events
```

Two safety layers (defense in depth):
1. **Server-side classifier** β€” clinical/emergency input is answered by a fixed
   template and never sent to the model.
2. **System prompt** β€” even on the SAFE path, the model is instructed to refuse
   medical advice and answer only from the supplied knowledge base.

## Run it

```powershell
# 1. install
npm install

# 2. set your Anthropic API key
$env:ANTHROPIC_API_KEY = "sk-ant-..."

# 3. start
npm start
# β†’ http://localhost:8100
```

Without a key the server still runs: the safety gate (emergency/clinical/PII)
works fully, and SAFE questions return a friendly "no key configured" message
instead of a model answer. Useful for demoing the guardrails offline.

## Files

| File | Purpose |
|------|---------|
| `server.js` | Express app, safety classifier, SSE chat endpoint, Claude call |
| `kb.js` | Verified knowledge base (6 branches + services) and the system prompt |
| `public/index.html` | Chat UI (streaming, multilingual, quick replies, classifier tags) |

## Notes for production

- Opening hours are the site's blanket "Mo–Sa 9–20" statement β€” verify per
  branch (the airport branch differs) before going live.
- Add GDPR/HWG compliance: EU data residency, DPA with the vendor, no training
  on user data, consent capture for callbacks, minimal logging.
- Consider prompt-caching the system prompt (already marked `cache_control`),
  rate limiting, and a real callback/booking integration for the PII path.
- The classifier is intentionally tuned to over-refer: a wrongly deferred safe
  question costs a click; a wrongly answered clinical one is a liability.