Medical records processing · Production

MSD uses Amazon Bedrock and Claude 3.5 Sonnet to translate natural language into SQL for complex healthcare databases

The problem

MSD analysts and data scientists spend considerable time manually querying complex healthcare databases, slowing productivity and delaying data-driven decision-making. Healthcare datasets pose additional challenges including coded columns, non-intuitive column names, long medical code lists, and ambiguous queries.

First attempt

Out-of-the-box text-to-SQL libraries required a custom approach because they could not handle coded columns, non-intuitive names, excessively long medical code lists, and query ambiguity inherent in healthcare datasets.

Workflow diagram · grounded in source
1
Analyst submits NL question
trigger
“an analyst could simply ask, "How many female patients have been admitted to a hospital in 2008?"”
2
System prompt assembled
integration
“The system prompt template is populated with the aforementioned variables.”
3
Claude generates SQL or tool call
ai_action
“The system prompt is passed to Anthropic's Claude 3.5 Sonnet on Amazon Bedrock using the Converse API, along with the list of tools and the user input.”
4
Lookup tool invoked if needed
feedback_loop
“The output contains a call for a lookup tool, in which case we run the lookup tool and append the result to the main prompt, before going back to Step 2.”
5
SQL query returned to user
output
“we return it to the user, along with the generated explanation”
Reported outcome

The text-to-SQL solution at MSD markedly accelerated data access and boosted analyst productivity by simplifying the SQL query process, allowing analysts to dedicate more time to data interpretation and strategic decision-making.

Reported metrics
Query timepotentially reducing query time from hours to minutes
Data access speedmarkedly accelerated data access
Analyst productivityboosted analyst productivity
Reported stack
Amazon BedrockClaude 3.5 SonnetConverse APISQLiteStreamlit
Source
https://aws.amazon.com/blogs/machine-learning/how-merck-uses-amazon-bedrock-to-translate-natural-language-into-sql-for-complex-healthcare-databases?tag=soumet-20
Read source ↗

Frequently asked questions

What did this team achieve with this AI workflow?

The text-to-SQL solution at MSD markedly accelerated data access and boosted analyst productivity by simplifying the SQL query process, allowing analysts to dedicate more time to data interpretation and strategic deci…

What tools did this team use?

Amazon Bedrock, Claude 3.5 Sonnet, Converse API, SQLite, Streamlit.

What results were reported?

Query time: potentially reducing query time from hours to minutes; Data access speed: markedly accelerated data access; Analyst productivity: boosted analyst productivity (source-reported, not independently verified).

What failed first in this deployment?

Out-of-the-box text-to-SQL libraries required a custom approach because they could not handle coded columns, non-intuitive names, excessively long medical code lists, and query ambiguity inherent in healthcare datasets.

How is this medical records processing AI workflow structured?

Analyst submits NL question → System prompt assembled → Claude generates SQL or tool call → Lookup tool invoked if needed → SQL query returned to user.