Testing a Safety-Critical Matching Component of an LLM-Based Simulated Patient: Blind Test Sets, Overfitted Cut-offs and a Cascade: what it means for business leaders
A case study of a safety-critical matcher in a simulated psychiatric patient shows that test sets written blind to the code expose overfitted cut-offs, and that a cascade into the application's own model recovers most of the missed risk questions.
1. What the method is
The paper is a case study in testing one meaning-level component of an LLM application: the matcher in Rapport, an open-source spoken simulated psychiatric patient, which decides in code which of the patient's memories a student's question is about. The advance is a testing procedure, not a new model. The authors build a blind test set from the specification instead of the code: a writer model that sees only what each memory means produces 512 doctor questions over four cases, split by CRC-32 checksum into a tuning half and a test half, and two writers from other model families produce further sets. Against that oracle they measure the deployed hybrid of keyword tags and a 33-million-parameter sentence encoder, BM25, five small encoders, the application's own 4-billion-parameter model used as a zero-shot classifier, and a cascade of the hybrid and that model.
2. Why the method was developed
The matcher was the simulator's main source of faults: of 8 bugs logged during its evaluation, 4 were matching faults, including all 3 rated major. Questions such as 'wishing you wouldn't wake up' missed the memory they asked about, and one miss let the patient deny a passive death wish it should have disclosed. Each fix added keywords and a regression test for one wording, which cannot keep up, because there is no end to the ways a question can be phrased. Correct behaviour is defined by meaning, so no specification lists the inputs; any cut-off tuned on test data stops that data from measuring anything; and a test set from one source may not predict the next. The component also carries hard constraints: it runs locally on every spoken turn, must never leak locked memory text, and its two kinds of error cost different things.
3. Who should care
This matters to anyone who owns a product in which code decides what a language model may say on the strength of a semantic match: intent routers, escalation triggers, retrieval gates and policy classifiers. Engineering leads should read it as evidence that one regression test per reported wording, plus thresholds tuned on a reused development set, gives a falsely comfortable picture. Evaluation and QA teams get a concrete recipe for building an oracle without access to the implementation, and for checking it against a second and third author. Product and risk owners in health, safety and customer-care settings should note the asymmetric cost, since a missed match here became a missed disclosure. Infrastructure teams should note the latency trade: a few milliseconds on the processor against roughly 400 milliseconds of graphics-processor time per question. For us, it applies wherever we gate model behaviour with an embedding threshold.
4. How the method works
The deployed matcher works in layers. Keyword tags score 2 for each matching phrase and 1 for each matching word after crude stemming. The encoder, bge-small-en-v1.5, embeds each memory's example questions once when a case loads, and a question's similarity to a memory is its highest cosine to those examples. A memory matches on a keyword hit, a similarity of at least 0.83 (0.78 for risk memories), or being the best match by 0.02 and above 0.76. Trust locks are applied after matching, so locked text never enters the prompt, and only a stricter 'clearly asked' level can force a disclosure. The zero-shot alternative gives Gemma 4 E4B the case's memories with ids and returns at most three ids through a JSON schema at temperature 0. In the cascade the hybrid screens every question and only those whose best risk score reaches a floor, set on the tuning half, go to the model.
5. How it was evaluated
The benchmark has 512 lines, 38 of which ask about nothing and 249 of which the writer marked hard; the test half holds 77 risk pairs. The measures are risk recall, the share of non-risk questions wrongly matched to a risk memory, and threshold-free AUROC and AUPRC with 95% intervals from 1,000 bootstrap resamples. Each scored method gets an operating point matched to the deployed hybrid's 12.7% false-hit rate on the tuning half. Two further test sets, written by Qwen3.5-4B and Gemma 4 E2B with about one line in four in code-mixed Hindi-English, were used once with cut-offs unchanged. The full pipeline was also run with each test-half risk question as the second turn of a conversation, over three seeds. Everything ran on one laptop through llama.cpp at 4-bit. All questions were written by language models, and the labels were not checked by a person.
6. How it performed
On the test half, keyword tags found 35.1% of risk questions and the deployed hybrid 72.7% (95% interval 62.3–81.8%) with 15.2% wrong risk matches. Five encoders and BM25 ranked similarly (risk AUROC 0.86–0.91), so the cut-off, not the encoder, was the limit. The zero-shot model found 94.8% with 4.8% wrong matches at a median of 416 ms, and the cascade kept 93.5% while sending 63% of questions to the model. On the two new writers' sets the deployed rules fell to 58.9% and 47.5%, against 87.7% and 91.5% for the model. In conversations, 69.8% of unmatched risk questions went undisclosed, against 24.4% of matched ones. The authors' limits: every question was model-written, labels were unchecked by a person, and each half holds about 75 risk pairs. Our call: pilot the blind, multi-writer test procedure and the cascade on our own semantic gates. (Source: arXiv 2612.05991, 2026)
← Back to dossier index