Medical coding translates free-text clinical terms into standardized dictionaries such as MedDRA and WHODrug; it is safety-critical because a coding error can send an adverse event to the wrong safety signal, yet it is mostly repetitive work. The solution uses AWS Step Functions to own sequencing and audit trail, while an Amazon Bedrock AgentCore harness provides bounded agentic reasoning within a single step. The workflow escalates cheapest-first: a safety block-list, exact matching, then an AI agent only for terms needing judgment, with a confidence gate routing low-confidence results to a human. Amazon Aurora PostgreSQL with pgvector serves as a single store for reference data and embeddings, and the agent logs explanations for its decisions. The pattern fits when the execution path must be reviewable independently of model reasoning, most of the workload is deterministic, and human escalation is a first-class outcome.
Context
Medical coding translates free-text clinical terms into standardized dictionaries such as MedDRA and WHODrug. It is safety-critical because a coding error can send an adverse event to the wrong safety signal, yet it is mostly repetitive work. The solution combines deterministic orchestration with bounded agentic reasoning using AWS Step Functions and Amazon Bedrock AgentCore, escalating cheapest-first and routing ambiguous terms to humans.
Approach / What changed
Use AWS Step Functions to orchestrate a medical coding workflow with three escalation stages: a safety block-list, exact matching, and an AI agent for ambiguous terms. The agent runs within a bounded step using Amazon Bedrock AgentCore harness, and its confidence score determines whether to auto-code or route to a human. Amazon Aurora PostgreSQL with pgvector stores reference data and embeddings.
Takeaways
1
The workflow engine (Step Functions) owns sequencing and audit trail, not the model, making the execution path reviewable independently of model reasoning.
2
More than a third of the workload in the sample never reaches the agent because deterministic steps (block-list and exact match) resolve them first.
3
Retrieval quality constrains the agent; if a term is not surfaced by vector search, the agent cannot choose it, so hybrid retrieval and threshold calibration are recommended for production.
FAQ
How does the workflow ensure auditability?
The workflow uses AWS Step Functions, which provides exactly-once execution and a queryable history per term. The state machine definition shows the execution path independent of the model's reasoning, and the agent logs a one-sentence explanation for its decision, enabling teams to trace why a term was coded a certain way.
What happens when the agent's confidence is low?
The workflow routes terms below the confidence gate to a human coder. The confidence threshold is a safety margin, and in the sample, terms like 'flutters in my chest sometimes' that the agent codes with low confidence are sent for human review.
Why is a safety block-list used before any model call?
The safety block-list contains terms too broad to auto-assign, such as 'HAEMORRHAGE', where the code depends on location. Placing this check before any model call ensures it cannot be prompted away and costs nothing to enforce.
A layered architecture for a car-seat ride service: eligibility gates, seat hardware, driver installation training, and caregiver verification. See where checks catch problems before a child rides.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.