NMAI Core, NHS Clinical CUI, UK Model Handoff
Chapters 10 – 35 — The complete technical build route: components, API, decision states, stack, project structure, rules, CUI, LibreOffice, vLLM, Docker, model selection, and pilot.
Download the complete NHS Sovereign AI Replacement Architecture master record. The web pages provide section summaries; the PDF contains the full technical architecture.
This page summarises the technical implementation route for the NHS Sovereign AI Replacement Architecture.
The purpose is not to build another chatbot. The purpose is to prove a controlled route:
The architecture is designed so the NHS can pilot, test, audit, stop, replace, and scale the system without surrendering the workflow to a model-first dependency chain.
The technical stack separates the workflow into distinct layers:
| Layer | Function |
|---|---|
| NHS Clinical CUI | Controlled workflow interface for task selection, input capture, marker display, warnings, blocked states, and review states |
| NMAI Core | Deterministic input-conditioning kernel that controls whether model access is permitted |
| Ruleset layer | NHS-approved marker rules, blocked states, warning states, review triggers, and escalation logic |
| Audit layer | Records decision state, model-access outcome, ruleset version, and audit reference |
| UK-controlled model endpoint | Optional post-conditioning execution module for permitted drafting, summarising, rewriting, restructuring, or formatting |
| Human review layer | Keeps output draft, reviewable, correctable, and subject to NHS approval |
| Emergency stop and fallback | Allows generation to be disabled while condition-only or manual workflow continues |
The implementation route uses a lightweight local or hosted API layer. Core endpoints:
| Endpoint | Purpose | Model call |
|---|---|---|
POST /condition | Input conditioning only | No |
POST /markers | Marker detection only | No |
POST /route | Routing decision only | No |
POST /condition-and-generate | Controlled route with optional generation | Conditional |
GET /health | Service health | No |
GET /audit | Restricted audit summary | No |
NMAI Core creates a decision state before model handoff:
| Decision | Meaning | Model access |
|---|---|---|
| Permit | Task may proceed to approved model route | Allowed |
| Block | Input must not reach the model | Denied |
| Warn | Caution markers detected | Conditional |
| Review | Human review required before model access | Paused |
| Escalate | Task must move to specialist process | Denied unless authorised |
| Fail closed | Control failure occurred | Denied |
The system is designed to stop safely. A failure must not fall back to an external model.
The prototype and pilot stack uses open-source or inspectable components:
| Component | Route |
|---|---|
| API framework | FastAPI |
| API server | Uvicorn |
| Ruleset format | JSON |
| Audit format | JSONL append-only logs |
| Model serving | vLLM |
| Reverse proxy | Nginx |
| Container route | Docker / Docker Compose |
| Office-layer integration | LibreOffice plugin route |
| Pilot interface | NHS Clinical CUI first |
The preferred pilot path is CUI-first. LibreOffice integration can operate as an office-layer replacement route, but the NHS Clinical CUI is the cleaner first pilot path because it avoids being blocked by locked desktop estates.
nhs-sovereign-ai/ |-- nmai/ | |-- engine.py (NMAI Core deterministic conditioning) | |-- markers.py (Marker detection module) | |-- rules.py (Ruleset loader and validator) | |-- audit.py (Audit trail writer) | +-- config.py (Configuration loader) |-- rules/ | +-- nhs-rules.json (NHS marker rules) |-- api/ | +-- main.py (FastAPI service) |-- audit/ | +-- logs/ (JSONL append-only audit logs) |-- model-gateway/ | +-- handoff.py (UK model endpoint handoff) |-- vllm-server/ | +-- Dockerfile |-- nginx/ | +-- nginx.conf (Reverse proxy configuration) |-- libreoffice/ | +-- plugin/ (LibreOffice extension files) |-- docker-compose.yml |-- requirements.txt |-- Dockerfile +-- README.md
The rules file defines the deterministic boundary for all NHS AI workflow:
| Rule Category | Detection |
|---|---|
| Blocked identifiers | NHS numbers, dates of birth, postcodes, names, addresses |
| Clinical high-risk terms | Diagnosis, medication, treatment plans |
| Safeguarding markers | Adult/child safeguarding, vulnerable person indicators |
| Legal / complaint markers | Litigation, complaint, negligence, coroner |
| Governance markers | Caldicott, IG breach, data subject request |
| Review-required markers | Triggers mandatory human review |
| Decision states | Permit, block, warn, review, escalate, fail closed |
The NHS Clinical CUI is a controlled workflow interface — not a gimmick chatbot.
Its functions:
- Input capture: Receives NHS workflow input in structured form
- Task selection: Presents approved task categories (rewrite, summarise, restructure, format, draft)
- Marker display: Shows detected markers to the user
- Warning display: Surfaces caution markers with explanation
- Blocked state: Clearly prevents blocked tasks from proceeding
- Human review state: Holds output for clinical review before release
- Escalation route: Routes specialist tasks to appropriate teams
- Output state: Displays conditioned output with audit reference
- Audit reference display: Shows unique audit ID for every transaction
The CUI preserves context throughout the workflow. It does not allow open-ended chat that could drift off-domain.
The LibreOffice plugin provides office-layer integration:
- Document check before export: Validates content against NHS rules
- Document check before AI assistance: Routes content through NMAI Core conditioning
- Python-UNO route: Uses LibreOffice's native Python bridge
- Local API call: Communicates with NMAI Core service on local network
- Blocked-state display: Clear warnings when content is blocked
- Warning-state display: Surfaces caution markers with required actions
- Output handling: Returns conditioned output back into the document
- Local-only configuration: No external network required
Plugin workflow: User selects text or whole document → clicks plugin action → document text sent to NMAI → NMAI checks input → returns blocked, warning, review, or approved state → output returned to LibreOffice with audit reference.
vLLM serves as the post-conditioning execution module — not the primary system.
| Aspect | Requirement |
|---|---|
| Deployment | UK-hosted only, internal-only endpoint |
| Input | Conditioned input package from NMAI Core only |
| Output handling | Returned as draft, subject to human review |
| Failure handling | Safe failure, no fallback to external model |
| Security | No direct access, reverse-proxy controlled |
| API compatibility | OpenAI-compatible API for model serving |
Permitted model tasks:
Rewriting approved text, summarising permitted administrative content, restructuring meeting notes, formatting internal policy text, converting structured notes into draft documents, producing plain-English wording from approved source material.
Blocked/restricted tasks:
Direct clinical diagnosis, patient-specific medical advice, medication recommendations, unsupervised treatment planning, any task bypassing NMAI conditioning.
The full NHS stack deploys as a Docker Compose multi-container system:
| Container | Role |
|---|---|
| NMAI service | Deterministic conditioning, rules, audit, API |
| vLLM server | Post-conditioning model execution (GPU required) |
| Nginx | Reverse proxy, internal routing, access restriction |
Key commands:
# Build and start all containers
docker-compose up --build -d
# Check running services
docker-compose ps
# View logs
docker-compose logs -f nmai
# Test NMAI conditioning endpoint
curl -X POST http://localhost:8000/condition \\
-H "Content-Type: application/json" \\
-d '{"text": "Summarise this meeting agenda"}'
# Stop stack
docker-compose down
The model is not selected to replace ChatGPT. The model is selected only to execute bounded permitted tasks.
| Requirement | Standard |
|---|---|
| Task-fit | Model capability matches approved task list |
| Version-controlled | Exact model version recorded and auditable |
| UK-hostable | Deployable inside approved UK environment |
| Open-source / open-weight | Full weight inspectability, no API dependency |
| Auditable | Model name and version in every audit record |
| Replaceable | Swappable without redesigning the system |
| Input-controlled | Cannot receive raw input by default |
Model selection checklist: Licence review → NHS use approval → No external API calls → Version lock → Capability boundary → Safety limits → NMAI Core compatibility → Hardware envelope check → Replacement and exit route confirmed.
The pilot measures the full route, not model speed alone.
| Measured Field | Purpose |
|---|---|
| Baseline manual task time | Control measurement |
| NMAI conditioning time | Overhead assessment |
| Blocked-task count | Safety effectiveness |
| Warning-task count | Risk detection rate |
| Review-task count | Human oversight burden |
| Permitted model handoff count | Appropriate usage |
| Avoided model calls | Privacy protection |
| Model runtime | Actual generation time |
| Human review time | Governance overhead |
| Correction time | Output quality measure |
| Final accepted/rejected outcome | Overall effectiveness |
| Stage | Purpose |
|---|---|
| Local prototype | Prove NMAI conditioning, ruleset logic, audit, and safe failure |
| Department pilot | Test bounded workflow tasks using synthetic or approved non-identifying data |
| Trust pilot | Test controlled operational deployment with governance oversight |
| Regional deployment | Test interoperability and wider operational scaling |
| National deployment | Deploy only after evidence, governance, cyber, procurement, and exit controls are approved |