Clinical-Grade Patient Education Agent with LangGraph and LangSmith

lubu_labs · Healthcare · 2026 · source Agentic: yes · promotional bias: med · source-backed · extracted with prompt 0.5.5 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Clinical patient-education agents for regulated healthcare

Lubu Labs needed a patient-education agent that could explain camera-based health scan results in plain language while avoiding unsafe diagnosis, hallucination, missing audit trails, and unreviewed low-confidence answers.

Constraints:

Architecture

The agent uses LangGraph as an explicit state machine carrying medical findings, confidence scores, review flags, and thread IDs; RAG over an approved version-controlled medical knowledge base returns content and evidence-quality confidence; threshold routing sends low-confidence or clinically risky cases to human review; LangSmith traces every LLM call, retrieval result, confidence score, route, and metadata; PostgreSQL checkpointing makes patient sessions resumable.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  patient-conversation-ui["patient conversation UI"] --> langgraph-state-machine["LangGraph state machine"]
  camera-health-scan-results["camera health scan results"] --> langgraph-state-machine
  langgraph-state-machine --> medical-rag-retriever["medical RAG retriever"]
  medical-knowledge-base["medical knowledge base"] --> medical-rag-retriever
  medical-rag-retriever --> confidence-router["confidence router"]
  confidence-router --> llm-education-responder["LLM education responder"]
  confidence-router --> human-clinician-review["human clinician review"]
  llm-education-responder --> patient-conversation-ui
  human-clinician-review --> patient-conversation-ui
  langgraph-state-machine --> postgresql-checkpoint-store["PostgreSQL checkpoint store"]
  langgraph-state-machine --> langsmith-tracing["LangSmith tracing"]
  llm-education-responder --> langsmith-tracing
  langsmith-tracing --> evaluation-dataset["evaluation dataset"]
  langsmith-tracing --> audit-export["audit export"]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
patient conversation UI Collects patient questions and displays educational explanations or review handoff. LangGraph state machine
camera health scan results Patient test results from smartphone-camera health scans. LangGraph state machine
LangGraph state machine Controls explicit nodes, routing, state, and checkpointing for the conversation. patient conversation UI, camera health scan results, medical RAG retriever, confidence router, PostgreSQL checkpoint store, LangSmith tracing
medical knowledge base Approved, version-controlled clinical explanations and patient-education materials. medical RAG retriever
medical RAG retriever Retrieves grounded medical content and evidence-quality confidence scores. LangGraph state machine, medical knowledge base, confidence router, LLM education responder
confidence router Explicit threshold logic that sends low-confidence or review-required cases to clinicians. medical RAG retriever, LLM education responder, human clinician review
LLM education responder Produces plain-language educational explanations from high-confidence approved context. medical RAG retriever, patient conversation UI, LangSmith tracing
human clinician review Receives uncertain, low-confidence, symptom, medication, or diagnosis-related cases. confidence router, patient conversation UI
LangSmith tracing Audit-grade trace store for model calls, retrievals, confidence, routing, and metadata. LangGraph state machine, LLM education responder, evaluation dataset, audit export
PostgreSQL checkpoint store Persists conversation state so patients can leave and resume later. LangGraph state machine
evaluation dataset Known-unknown and clinical accuracy tests for pre-deployment and continuous monitoring. LangSmith tracing
audit export Compliance reconstruction of what happened, why, and with which versions. LangSmith tracing

Data flow

A patient asks about scan results; LangGraph state carries findings and session metadata; the system retrieves approved medical explanations with confidence scores; high-confidence educational answers go to the LLM response node, while confidence below threshold or review triggers go to a clinician-review node; LangSmith records retrievals, model calls, routing, metadata, and audit trail for later compliance and evaluation.

3 supporting quotes
“Each stage is a node, and the conversation state carries medical findings, confidence scores, and routing decisions forward.”article, stated
“Every retrieval returned not just content, but a confidence score based on evidence quality. What this looked like in practice: * Knowledge base entries tagged by source type (peer-reviewed, clinical guidelines, patient education materials) * Retrieval”article, stated
“LangSmith tracing gave us an end-to-end timeline for every conversation”article, stated

Why this architecture

Lubu chose explicit control flow and audit-grade observability because healthcare needs safe routing, grounded answers, resumability, and reconstructable decisions; prompts alone cannot enforce the education-vs-diagnosis boundary or prove what knowledge the AI used.

3 supporting quotes
“The difference between a healthcare demo and a shippable system wasn't "better prompts or model", it was explicit control flow and audit-grade observability.”article, stated
“"""Route to clinician review if confidence too low. This is NOT an LLM decision - it's explicit threshold-based routing to ensure safety boundaries are enforced in code, not prompts. """ if state["confidence_score"] < 0.7 or state["requires_review"]: return "human_review" return”article, stated
“Make boundaries code, not prompts. Use explicit routing logic—don't rely on "the model will understand." If you do only one thing: make clinical accuracy measurable (via LangSmith evaluations), then”article, stated

Models used: LLM patient education responder · retrieval confidence scoring model or heuristic

Scale

Alternatives considered (roads not taken)

Rely on better prompts or model choice

Rejected because: The article says shippability came from explicit control flow and audit observability, not just better prompts or model.

“wasn't "better prompts or model", it was explicit control flow and audit-grade observability. ## Problem The system needed to do several things: * Interpret dermatology test results from camera-based health scans * Provide plain-language summaries”article, stated

Let the LLM decide when to route to a clinician

Rejected because: The route is explicitly threshold-based, not an LLM decision, because uncertainty handling is safety-critical.

“checkpointing and audit trail def should_route_to_human(state: PatientEducationState) -> str: """Route to clinician review if confidence too low. This is NOT an LLM decision - it's explicit threshold-based routing to ensure safety boundaries are enforced in code, not”article, stated
“"""Route to clinician review if confidence too low. This is NOT an LLM decision - it's explicit threshold-based routing to ensure safety boundaries are enforced in code, not prompts. """ if state["confidence_score"] < 0.7 or state["requires_review"]: return "human_review" return”article, stated

Let the model fill weak retrieval gaps from training data

Rejected because: Testing found the model bridged weak retrieval with training data, which is unsafe in healthcare.

“the model response didn't reflect that uncertainty. Instead, it "bridged the gap" with training data rather than our approved knowledge.”article, stated

Log only final messages

Rejected because: Final-message logs could not reconstruct what was retrieved, routed, or scored three weeks earlier.

“Early logging captured final messages but not the full reasoning chain (what was retrieved, routing decisions, confidence scores).”article, stated
“gap: no audit trail Symptom: During a test audit, we couldn't reconstruct what the AI told a patient three weeks earlier. Root cause: Early logging captured final messages but not the full reasoning chain (what was retrieved, routing decisions, confidence scores). **Why this was”article, stated

Patterns

rag-retrieval (grounding)

The agent retrieves from an approved, version-controlled medical knowledge base and passes only high-confidence documents to the model.

“We used RAG over an approved, version-controlled knowledge base of clinical explanations.”article, stated
“Only pass high-confidence documents to the LLM context." We also built a [LangSmith evaluation dataset](https://docs.”article, stated

confidence-thresholding (routing)

Combined confidence determines whether the agent proceeds or routes to clinician review.

“Every answer scored on combined confidence (retrieval quality + LLM certainty)”article, stated
“Threshold-based routing (< 0.7 → human review, ≥ 0.7 → proceed)”article, stated

human-in-the-loop-gate (safety)

Low-confidence, symptom, medication, diagnosis, and review-triggered conversations route to human clinicians instead of forcing an answer.

“Specific triggers for review (patient asks about symptoms, medication, diagnosis)”article, stated
“clinical guidelines, patient education materials) * Retrieval scores combined semantic similarity + source quality * Low-confidence retrievals triggered automatic human review Advice: Treat your medical knowledge base like production code: version control, change tracking, and rollback”article, stated

observability-tracing (compliance)

LangSmith traces capture model calls, retrievals, confidence, routing, metadata, and version tags for audit and debugging.

“What did the AI say, when, based on what? This must be answerable months later for regulatory audits.”article, stated
“environment, patient_id (hashed), session_id, knowledge base version, model version.”article, stated

durable-execution (state-management)

LangGraph checkpointing with PostgreSQL persists conversation state so patients can resume sessions hours or days later.

“LangGraph checkpointing for session resumability (patients can leave and return)”article, stated
“Checkpointing with PostgreSQL persistence allowed session resumability”article, stated

eval-driven-development (clinical-quality)

The team used LangSmith evaluation datasets, known-unknown tests, weekly audit sampling, and continuous monitoring for clinical accuracy.

“built a LangSmith evaluation dataset with "known unknowns"”article, stated
“make clinical accuracy measurable (via LangSmith evaluations), then monitor it continuously (via production traces).”article, stated

Tradeoffs

Route low-confidence cases to clinicians.

Chose Safety-first human review at confidence thresholds over Maximizing automated answer rate.

Rationale: In healthcare, a safe refusal or review is better than a confident but unsupported answer.

“cases](https://www.lubulabs.com/images/blog/healthcare-ai-patient-education/dataset-view.png) Key lesson: In healthcare, "I don't know" is a feature, not a bug. Build explicit guardrails so the model can't bridge low-confidence gaps. ### The compliance gap: no audit trail Symptom:”article, stated
“The goal is safe answers, not all answers. * Audit trail = liability protection. Tag every [LangSmith trace](https:”article, stated

Tune the review threshold from 0.8 to 0.7.

Chose A lower threshold after clinician feedback over Keeping the initial more conservative threshold.

Rationale: Tuning reduced unnecessary reviews while maintaining appropriate routing based on feedback loops.

“False positive rate (unnecessary reviews) decreased 40% after threshold tuning from initial 0.8 → 0.7”article, stated
“Of those, ~80% were appropriately routed (validated via clinician feedback loops)”article, stated

Use trace-level redaction plus full audit export.

Chose Redacted monitoring traces and full audit retention over Either exposing PII in monitoring or losing audit detail.

Rationale: The system needs privacy-preserving observability and regulatory reconstructability at the same time.

“PII redaction at trace level (redact for monitoring, keep full for audit export)”article, stated

Gotchas (what bit them)

The model can confidently bridge weak retrieval gaps with training data.

Root cause: Low-confidence retrieval was not reflected in the generated answer, so the model filled missing approved knowledge with latent training information.

Resolution: Return a safe refusal and route to human review when retrieval confidence is below threshold; only pass high-confidence documents to context.

“During testing, the AI confidently explained a condition not in our knowledge base.”article, stated
“Only pass high-confidence documents to the LLM context." We also built a [LangSmith evaluation dataset](https://docs.”article, stated

A missing audit trail blocks regulated deployment.

Root cause: Early logs captured final messages but not the full retrieval, routing, confidence, and reasoning chain.

Resolution: Tag every LangSmith trace with compliance metadata, version information, redaction, and audit export support.

“Healthcare regulations require immutable audit trails. "The AI said X" isn't enough.”article, stated
“Comprehensive LangSmith metadata tagging (session_id, kb_version, model_version)”article, stated

Prompt-only boundaries are unsafe in clinical settings.

Root cause: The agent must distinguish education from diagnosis and know when not to answer, which cannot be left to a model's judgment alone.

Resolution: Enforce routing and boundaries in LangGraph code.

“The agent can't cross into clinical decision-making. It's educational support only, and that distinction must be enforced in code, not just prompts.”article, stated
“Use explicit routing logic—don't rely on "the model will understand."”article, stated

Evaluation

Lubu evaluates clinical safety through confidence-routing metrics, clinician feedback loops, LangSmith known-unknown datasets, weekly audit sampling, and continuous trace monitoring.

Metrics: 15% conversations triggering human review · 80% appropriate routing validated by clinicians · 40% false-positive review reduction · very low inappropriate clinical advice rate · weekly audit sampling · retrieval confidence thresholds · known-unknown evaluation cases

3 supporting quotes
“~15% of conversations triggered human review (mostly edge cases or off-topic questions)”article, stated
“Very low rate of inappropriate clinical advice in production (validated via weekly audit sampling)”article, stated
“We also built a LangSmith evaluation dataset with "known unknowns"”article, stated

Outcomes

The deployment handles patient education for scans measuring 30+ vital signs, uses 0.6 and 0.7 confidence thresholds, routes about 15% of conversations to review, and reports 80% appropriate routing with 40% fewer false-positive reviews after tuning.

3 supporting quotes
“We're shipping to production a system for a digital health platform”article, stated
“Key results included approximately 15% of conversations appropriately triggering human review”summary, stated
“very low rates of inappropriate clinical advice in production validated through weekly audits.”summary, stated