Compiling Written Clinical Protocols into Checkers for Privacy-Preserving Depth Sensors

Hospitals already use depth cameras to watch care without recording faces. These sensors measure distance instead of color, so they capture body shape and motion but not identity. Systems built on them detect single actions well: a hand at a sanitizer dispenser, a patient getting out of bed. They cannot tell whether a sequence of actions followed the unit's written protocol, such as "perform hand hygiene before assisting a patient out of bed, with two staff present for high-fall-risk patients." That question is posed in prose. It differs from unit to unit, and today it is answered by human auditors or by rules that an engineer hand-codes for each protocol.

We propose to split the problem in two. A large language model reads the protocol text and compiles it into an explicit, executable checker. This checker is a small graph of temporal and spatial conditions over the events and 3D geometry the depth system produces. Running the checker is then fully deterministic. The language model returns only for cases the checker flags as ambiguous. In those cases it acts as a judge that decides whether an apparent violation is a real lapse in care or an error by the upstream detector. The bet is that language models are more reliable writing a checker than judging the evidence directly. Each piece of the compiled checker can be inspected and corrected, while a judge that reads the evidence directly tends to drift toward leniency and invent premises.

Core Claim

The claim has three parts. First, for protocol-compliance auditing over depth-sensor output, an LLM that compiles protocol text into a structured checker will match hand-written expert checkers at detecting violations and will transfer to new protocol text without new code. Second, it will clearly beat an LLM judge that reads the event log and protocol together and gives a verdict. Third, the most useful thing the language model can do at check time is attribution: deciding whether a missing step reflects a missing action or a missed detection. We expect this to cut false alarms well beyond what any amount of rule-writing can.

Several published findings motivate the design. On the sensing side, Towards Vision-Based Smart Hospitals audits hand hygiene from depth silhouettes. It reaches 75% compliance accuracy, against 63% for one covert human observer and 72% for a team of three. Its compliance logic, however, is a fixed proximity rule for one protocol. A computer vision system for deep learning-based detection of patient mobilization activities in the ICU detects four mobilization activities with an AUC of 0.938. Its personnel counts are much weaker: 68.8% accuracy overall, dropping as more clinicians crowd the bed. 3D Point Cloud-Based Visual Prediction of ICU Mobility Care Activities shows that reasoning on 3D point sets beats 2D depth images (54% versus 45% mAP), which justifies emitting geometric predicates rather than image labels. None of these systems connects its detections to protocol text.

On the evaluation side, AgentEval represents multi-step software-agent runs as dependency graphs and judges each step. Failure-detection recall rises from 0.41 for whole-trace judging to 0.89. It also finds that 63% of step failures propagate from upstream errors. We reuse its idea of judging step by step and assigning root causes, and we apply it to physical events in which "upstream" includes the sensor itself. MLLM-as-a-Judge supplies the constraint that shapes our design. Multimodal judges cluster their scores high. Chain-of-thought reasoning can lower their accuracy because they invent visual premises. They also judge better from text descriptions than from raw pixels. We take this as evidence that the judge should never look at raw depth frames. It should see a symbolic world state, and preferably only for the cases a deterministic checker cannot settle.

Research Program

The system has three stages.

The first stage is the event and geometry vocabulary. This is a fixed set of predicates computed from depth streams. It includes detector outputs with confidences: dispenser use, bed exit, chair entry, and person count near the bed. It also includes metric geometric predicates computed from 3D point clouds, such as a person's distance to the bed, dwell time inside a zone, or a trajectory crossing the doorway plane. Following TIMo, we remove the static background by geometric distance thresholding. Every predicate carries a confidence and a record of which detector produced it.

The second stage is protocol compilation. The language model receives the protocol text and the vocabulary schema and emits a checker. The checker is a directed acyclic graph whose nodes are required events and whose edges are ordering and time-window constraints. Spatial phrases become metric thresholds over the geometric predicates.

Domain-specific embeddings enter at one narrow point: aligning protocol phrases to predicate names. Clinical writing uses abbreviations, local jargon, and synonyms, such as "HH," "foam in," and "sanitize," for a single predicate. We test clinical word embeddings trained on in-domain notes, as in Brundlefly at SemEval-2016 Task 12, and ontology-initialized concept vectors, as in Detection of medical text semantic similarity based on convolutional neural network. They serve as a retrieval step that proposes candidate predicates to the compiler. The latter paper also reports that ontology embeddings fail on spatial and directional anatomical language. We take that limitation seriously. Spatial phrases are deliberately routed away from embedding lookup and toward metric predicates, and we test whether this routing matters.

The third stage is checking and attribution. The compiled graph runs deterministically over each care episode. When a required node is missing or low-confidence, the episode goes to an LLM judge. The judge sees the compiled graph, the predicate log, the known error profile of each detector, and the surrounding geometric evidence. For example, it may learn that the trajectory passed within 30 cm of the dispenser for two seconds even though the dispenser classifier fired at low confidence. It must label the episode as a behavioral violation, a likely sensing miss, or indeterminate. This is AgentEval's root-cause assignment with the sensor treated as one of the possible causes.

Data is the main practical obstacle, and we plan for it plainly. The ICU datasets above come from specific hospital deployments, and the file does not establish that they are released. TIMo is public. It has 1,588 anomaly sequences, including falls and abandoned objects, and 243 person-detection sequences with 3D boxes, recorded with an Azure Kinect from top-down and tilted views.

We will build the evaluation in two layers. The first is a scripted mock-care benchmark. Actors perform multi-step routines in a depth-instrumented room, including dispenser use, bedside assistance, and patient transfers. The routines come in compliant and deliberately violating variants. They are paired with protocol documents written by clinicians in several styles, including terse unit policies and long guideline excerpts. The second layer is a controlled-noise study over symbolic event logs. Detector errors are injected at rates taken from the published systems: about 4.5% dispenser misclassification, implied by the 95.5% accuracy reported by Haque et al., and personnel-count accuracy of 68.8% from Yeung et al. Because we know which errors we injected, we can separate violation detection from attribution exactly. TIMo provides the geometric-predicate layer and a test on falls framed as safety-protocol events.

Baselines

The naive reference point is the detector-only rule used in prior deployments: flag a violation whenever the required atomic event is not detected in a fixed window. For hand hygiene this is essentially Haque et al.'s system, which reports 75% compliance accuracy on room entries and exits in Towards Vision-Based Smart Hospitals. We will rerun it on our benchmark with the same detectors. Matching it is the floor.

The strongest competitor is an expert hand-written checker. A clinician and an engineer jointly encode each protocol as a temporal graph over the same predicate vocabulary, with confidence thresholds tuned on a development split. It answers the same question with the same inputs and no language model, and it is what a careful hospital engineering team would build. No reported result was found on Lacuna for an expert rule-based checker on multi-step clinical protocols over depth data, so we will establish this number ourselves. The compiled checker beats this baseline in the sense that matters if it comes within a few points of its violation F1 on protocols it has never seen, at near-zero engineering time per protocol, and if the attribution stage then lowers its false-alarm rate at equal recall.

The strongest existing judging method is a direct LLM judge in the style of AgentEval. The same frontier model receives the protocol text and the full predicate log and returns a verdict and a root cause. We will run it in two variants: one judgment over the whole episode, and step by step over a graph that the model builds implicitly. Both use the same prompts budget, the same number of development episodes for prompt tuning, and the same model as our compiler. Beating it means higher violation recall at matched precision. Calibration means agreement with clinician labels. AgentEval reports Cohen's κ = 0.84 between its calibrated GPT-4o judge and human experts on software traces, which gives an aspirational target for our setting rather than a number we expect to inherit.

Three ablations isolate the key ingredients. Compilation without attribution measures what the check-time judge adds. Compilation with general-purpose embeddings, or with no retrieval step at all, measures whether domain embeddings matter. Spatial phrases mapped by embedding lookup instead of metric predicates tests the routing decision.

Why not just…?

Why not just hand-write the rules? For a single fixed protocol, hand-written rules may be as accurate as anything we build. That is why the expert checker is our main baseline and not a straw man. The case for compilation is cost and coverage. Every unit rewrites its protocols, and each rewrite currently means new code. The experiment that settles this is held-out protocol transfer: we fix the engineering budget, measure accuracy on protocols the rule authors have not encoded, and measure how long it takes an expert to verify a compiled checker against writing one. If compiled checkers are noticeably worse even after expert review, the proposal reduces to "LLMs as rule-drafting assistants," and we would report that.

Why not just let the LLM judge read the event log, or the depth video, directly? MLLM-as-a-Judge documents high-score bias, verbosity bias, and premises invented during chain-of-thought reasoning when judges look at raw visual input, and it finds that they do better from text descriptions (MLLM-as-a-Judge). This argues against feeding depth frames to a judge. A judge reading a symbolic log is a more serious alternative. Because AgentEval's step-level judging works well on symbolic traces, the direct-judge baseline is run in full. Our prediction is that it degrades as episodes lengthen and as detector noise rises, because it must keep ordering constraints in mind implicitly. The noise sweep tests this directly.

Why not just improve the detectors? Better detectors shrink the attribution problem but do not remove it. Personnel counting, at 68.8% accuracy, is exactly the predicate that two-person-assist protocols depend on, and occlusion makes it fundamentally hard (A computer vision system for deep learning-based detection of patient mobilization activities in the ICU). Detector improvement is also orthogonal to our contribution: any better detector plugs into the same vocabulary. The noise sweep shows at what error rate attribution stops mattering. If that rate is already met by current detectors, attribution is not worth its cost.

Why not let the LLM map protocol words to predicates by itself and skip domain embeddings? This is a real threat to the embedding component. A frontier model may resolve "foam in" to dispenser use without help. The retrieval ablation decides the question. If clinical embeddings do not improve compile accuracy on jargon-heavy protocol styles, we drop them. The rest of the proposal does not depend on them.

Proposed Experiments

The first decisive check is held-out protocol transfer on the mock-care benchmark. We compare violation precision, recall, and F1 for the compiled checker, the expert checker, the direct LLM judge, and the detector-only rule. We stratify the results by protocol style and by episode length, measured as the number of required steps.

The second check is the controlled-noise sweep. Detector error rates range from zero up to and beyond the published levels. At each level we measure violation F1 and attribution accuracy, meaning the fraction of injected sensing misses correctly labeled as sensing misses rather than lapses. The prediction is that the gap between the compiled checker with attribution and the expert checker without it widens as noise rises.

The third check is compile fidelity. Clinicians grade each compiled graph node by node against the protocol. We report the error rate per node and how many errors fall on spatial phrases, which tests the routing decision motivated by Zheng et al.

The fourth check is a TIMo-based run in which fall and aggressive-behavior events are framed as safety-protocol violations. It shows whether the geometric predicates and the compiler work on public data from a different sensor placement.

The proposal succeeds if the compiled checker comes within a small margin of the expert checker on held-out protocols, clearly beats the direct judge as episodes lengthen, and attribution lowers false alarms at matched recall under realistic detector noise. It fails, informatively, if the direct judge matches compilation. That outcome would mean the structure AgentEval found necessary for software traces is unnecessary when the trace is short and symbolic.