Skip to content

Pre-speech gating

Improvised answers (see Encounter lifecycle) can be checked by a fast decision model before they are spoken (app/gating.py). Background and model comparison: Pre-speech gating models.

How a turn is gated

  1. Route first. Permitted negatives and earlier pinned answers are served from case text deterministically; they never reach generation.
  2. Lexicon first. A generated sentence must pass the improviser's validator (numbers, medicines, tests, diagnoses, positive symptoms, Roman-Hinglish symptom words).
  3. Decision model. The gate then asks a System One-style model one choice (permitted negative, everyday detail, don't know, new clinical fact) and noul flags (positive symptom, number, medicine, diagnosis, test or result). Either signal blocks.
  4. Fail closed. If the model times out or the circuit breaker is open, enforce mode answers "पता नहीं"; it never speaks unchecked text.

The decision (mode, model, flags, confidence, latency, would-block) is stored on the event, and the evaluation report summarises decisions, would-block counts, unavailability, gate latency and how often the shadow router agreed with the interpreter.

Modes and models

Setting Values
GATE_MODE off, shadow (record, never block), enforce. Defaults to shadow when CLOUDFLARE_AI_TOKEN is set, else off. Run shadow for two weeks before enforcing.
GATE_MODEL clef (default), clef-flash, jev, muril, lexicon
GATE_TIMEOUT_S Per-call timeout (default 0.8 s; 0.3 s for MuRIL)
Model Configuration Notes
Clef / Clef-flash CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_AI_TOKEN Workers AI REST, open weights. Clef-flash is faster but weak on out-of-scope detection.
Jev TYPESAFE_API_URL, TYPESAFE_API_KEY, optional TYPESAFE_MODEL Endpoint is not in TypeSafe's public docs, so it must be configured explicitly. US-hosted; for offline comparison.
MuRIL MURIL_GATE_URL, optional MURIL_GATE_TOKEN Self-hosted classifier serving the same schema; the recommended long-term gate (documented romanised-Hindi coverage).
Lexicon none Deterministic; used in tests and as the fallback.

In shadow mode the router also classifies each trainee question (authored, permitted negative, everyday, unknown) so it can be compared with the interpreter.

Gemini Live

Gemini Live cannot be made to speak verbatim text. With LIVE_VERBATIM_TTS=on, an improvised Live turn is synthesized by Gemini 3.8 TTS (gemini-3.8-flash-tts, verbatim, Hindi supported), using the case's Gemini voice name, with Sarvam as the fallback; the browser plays it and Live is told the line as context. Otherwise Live is handed the approved sentence and the spoken transcript is checked afterwards. Voice continuity between Live and TTS needs a listening check.

Evaluation

python3 -m app.gating_eval --model lexicon|clef|clef-flash|jev|muril evaluates a gate on a labelled set: 1,976 synthetic items (Devanagari Hindi, romanised Hinglish, code-mixed, Bengali, Tamil), including negated permitted terms, implicature ("thoda sa"), number words, household drug names and "sugar/BP" as tests. It reports recall on new clinical facts, precision, leaks, false blocks and latency per language, against targets of recall ≥ 0.99 and precision ≥ 0.90.

Lexicon baseline: 0 leaks overall; Hindi, romanised and code-mixed at recall and precision 1.0; Bengali and Tamil are blocked entirely (the lexicon cannot read those scripts), so those patients fall back to "don't know". These figures are optimistic: the synthetic items were written alongside the lexicon. A clinician-labelled set (≥1,500 items, two annotators, Cohen's κ) is still needed, and model gates must be measured on it, from India, before GATE_MODE=enforce.