Inspiration

Before this hackathon, I worked auditing Medicaid claims. Claims data tells the story of a patient's care one billing line at a time, and one pattern kept showing up: a specialist visit, followed by the very tests that should have been done before it, followed by a second specialist visit. Each of those is a separate claim. The care wasn't wrong, just out of order, and the patient paid for it in weeks of waiting.

A specialist referral is supposed to be a handoff. Too often it's a dead end. A patient waits weeks for an appointment, and the specialist's first question is about a test nobody ordered: an HbA1c before an endocrinology visit, an ECG before cardiology, a urine albumin test before nephrology. The visit gets spent ordering the test, and the patient waits again. Unproductive, unoptimized specialist consultation blocks drain an estimated $100 billion annually from the U.S. healthcare system.

The information needed to catch this is already in the chart, in a standard format. Health records in the US increasingly speak HL7 FHIR: certified EHRs are required to offer FHIR APIs. So we asked: could an AI agent read the record, look up what the specialist will expect, and close the gaps before the referral goes out, in a way a clinician can actually trust?

What it does

SynapseFHIR takes a patient's FHIR record and the referral order inside it, and produces a referral that arrives ready:

  • Finds the missing workup. It retrieves the specialty's guidelines live and audits the chart against them: which labs and imaging are satisfied, missing or outdated.
  • Writes a referral memo where every sentence is cited. Each claim links to the exact FHIR resource behind it (e.g. obs-glucose-521). In the app you can hover a claim to light up its record, or hover a record to light up every claim that uses it.
  • Drafts the missing orders, and after clinician sign-off writes them back as real FHIR ServiceRequest resources.
  • Checks guidelines and insurers. Two parallel Tavily searches pull medical society guidelines (KDIGO, ACC/AHA, ADA, …) and insurer coverage policies (Aetna, UnitedHealthcare, Cigna, Anthem, CMS). Items an insurer requires are tagged.
  • Notices when the chart changes under it. If a lab result is filed while the agent is working, it detects the change, re-plans over just the new data, and cancels exactly the order that would have duplicated it.

We demo it on three synthetic patients (nephrology, cardiology, endocrinology) with no specialty-specific rules in the prompts.

How we built it

SynapseFHIR is a LangGraph state machine running on Nebius Token Factory, with a Streamlit front end:

  1. Ingest and hash. Read the FHIR bundle and fingerprint it: a SHA-256 hash of the whole bundle plus one per resource, so any later change can be traced to the exact resource that changed.
  2. Triage: NVIDIA Nemotron 3 Nano (30B-A3B). The small, cheap model reads the entire raw record, extracts the relevant conditions, labs and medications, takes the specialty from the referral order, and writes two search queries.
  3. Guideline retrieval: Tavily. A society-guideline search and a payer-policy search run in parallel, each limited to an allowlist of trusted domains.
  4. Synthesis: NVIDIA Nemotron 3 Ultra (550B-A55B). The large reasoning model sees a compact summary rather than the raw record. It writes the cited memo, audits the workup, flags safety issues, and drafts orders.
  5. Citation validation, deterministic code. Every cited ID is checked against the record. Invalid IDs are stripped and flagged, and a "satisfied" item whose evidence doesn't exist is downgraded.
  6. Trajectory governance, deterministic code. Before acting, the governor re-hashes the live record. If it changed, the graph loops to a reconcile step, where Ultra decides KEEP or CANCEL for each order looking only at the changed resources. A cancel is accepted only if it cites a resource that actually changed.
  7. Commit gate. On approval, the record is re-hashed one final time before any ServiceRequest is written.

Every model reply is validated against a Pydantic schema, with an automatic retry if it doesn't match. Telemetry records tokens, latency and cost per step at each model's own price. For a run with steps $i$:

$$ \text{cost} = \sum_i \frac{p_i \, c^{\text{in}}{m_i} + q_i \, c^{\text{out}}{m_i}}{10^6}, \qquad \text{saving} = 1 - \frac{\text{cost}}{\text{cost}_{\text{Ultra only}}} $$

where $p_i$ and $q_i$ are prompt and completion tokens, and $c_m$ is model $m$'s price per million tokens.

Measured on live runs:

Nephrology Cardiology Endocrinology
Cost per referral \$0.0121 \$0.0136 \$0.0167
Saved vs. Ultra-only 19.0% 25.2% 19.5%
Citations valid 6/6 11/11 11/11

Re-planning over just the changed record (the "delta") instead of re-running synthesis used 79–87% fewer tokens:

$$ 1 - \frac{T_{\text{reconcile}}}{T_{\text{synthesis}}} \in [0.79,\ 0.87] $$

Challenges we ran into

  • Our first "rollback" was staged. The early version inserted the "mid-run" result before the agent even started, and cancelled every order on drift, including ones still needed. We rebuilt it: a live record store, a lab result that really arrives during the run, per-resource diffs, and order-by-order reconciliation.
  • Our cost claim didn't survive measurement. We expected about 70% savings from routing to the small model. Measured, it was 19–25% on our small sample records. We report the real number, and explain that it should grow with real records, which are much larger.
  • Inferring the specialty was fragile. Without a referral order, Nano sent a diabetes patient to cardiology because of an elevated LDL. When we added a rule to fix that, it sent the chest-pain patient to nephrology. Real EHRs carry the referral as a ServiceRequest, so we made that the source of truth.
  • Retrieved documents can mislead the model. One search returned a clinical-trial paper, and Ultra treated the trial's enrollment criteria as referral requirements. In one case it marked "creatinine clearance < 60" as satisfied by an eGFR of 96. A general prompt rule fixed it, but it taught us that our validator checks that evidence exists, not that it supports the claim.
  • Insurers rarely publish referral criteria. They publish coverage policies for specific tests and drugs. The payer search often finds related documents rather than a direct rule, and we had to exclude CMS facility-inspection reports that kept appearing.
  • Small bugs with real consequences. One audit produced three identical lipid-panel orders (one per checklist line), the opposite of what we promise. Orders for the same test are now merged.

Accomplishments that we're proud of

  • A drift-and-reconcile loop that prevents duplicate orders in live runs, and only accepts the model's decision when code can verify it.
  • Every citation valid in every live run we measured.
  • One pipeline, three specialties. Each patient got its own search queries and guideline sources, and every mid-run result cancelled exactly one order.
  • An offline test suite that drives the real LangGraph pipeline with fake model and search clients, at no cost.
  • About one to two cents per referral, with every token accounted for.

What we learned

  • Let the model reason; let code check it. Our most trustworthy features are the deterministic ones wrapped around the LLMs: citation checks, hash checks, and a cancel only accepted when backed by evidence.
  • FHIR resource IDs are what make AI auditable. Once every claim points to an ID, "is this hallucinated?" becomes a lookup.
  • Measure before you claim. Our cost, speed and routing assumptions all changed once we measured them. Nemotron Ultra on Token Factory turned out faster than Nano (about 370 vs. 260–300 tokens/s); Nano earns its place by being about 16× cheaper on input, not by being faster.
  • Retrieval quality limits answer quality. Search results vary from run to run, and the checklist follows them.

What's next for SynapseFHIR

  • A real FHIR server: HAPI FHIR loaded with large synthetic records from Synthea, which also lets us measure the savings on realistically sized records.
  • SMART on FHIR authorization, plus FHIR's own safety features: conditional create to block duplicate orders, version checks, transactions, and Provenance resources recording which model drafted each order and which clinician approved it.
  • Insurer search per proposed order (e.g. coverage criteria for a stress echo), which matches how insurers actually publish policy, flagging orders that need prior authorization.
  • Code-level value checks, using standard lab codes (LOINC) and thresholds, so "satisfied" means the value actually meets the criterion.
  • Evaluation at scale: many more patients and specialties, with expected answers to score against.

Built With

  • agentic-workflows
  • ai-safety
  • clinical-decision-support
  • cost-optimization
  • fhir-r4
  • governance
  • healthcare-ai
  • hl7-fhir
  • langgraph
  • nebius-token-factory
  • nemotron-3-nano
  • nemotron-3-ultra
  • nvidia-nemotron
  • open-source
  • pydantic
  • python
  • sha-256
  • state-machine
  • streamlit
  • tavily-search-api
Share this project:

Updates

Submission history