Writings & Insights

Thoughts on data analytics, healthcare tech, and building AI tools for regulated environments.

AI & Healthcare February 2026 6 min read

From SQL Queries to Plain English: Building AI Tools for Medical Device Regulatory Data

If you've ever worked in medical device regulatory affairs, you know the problem. The data is all there — biocompatibility reports, chemical characterisation files, device test results — sitting in databases and document repositories. But getting to it means either writing SQL queries, navigating dashboards someone else built, or asking the data team to pull a report for you.

For a domain where decisions about patient safety depend on that data, that friction is a real problem.

Over the past year I've been working on a set of AI-powered tools for the Medtronic healthcare data platform, and I want to share what we built, what actually worked, and a few things I'd do differently.

The Problem We Were Solving

Our regulatory data lived across several PostgreSQL tables — BER (Biocompatibility Evaluation Reports), CCT (Chemical Characterisation Tests), device records, material inventories, compound libraries. The team needed to answer questions like:

"Which devices used acetal copolymer and what were their test results?"

"Show me all compounds exceeding 2000 micrograms per device"

"What materials were tested at our contract lab in the last two years?"

Each of these requires knowing which tables to join, which columns to filter on, and how to structure the query. Not something a regulatory scientist should have to worry about.

ResearchAI: Natural Language to SQL

The first tool we built was ResearchAI — a Flask application that takes a plain English question and returns SQL query results, complete with downloadable reports and basic chart visualisations.

The architecture sounds straightforward: user types a question, GPT generates SQL, we execute it against PostgreSQL. But getting it to actually work reliably on regulatory data was the real challenge.

Early versions hovered around 60% query success rate. The failures weren't random — they fell into predictable patterns. COUNT queries would return inflated numbers because GPT would write COUNT(*) instead of COUNT(DISTINCT device_id). Material searches would miss results because they'd filter on one column when the data was split across Material_Type and Material. Cross-table queries would fail because GPT didn't know which tables needed JOINs.

The fix wasn't a smarter model — it was better prompt engineering and a RAG layer. We built a Milvus vector database storing embeddings of our table and column metadata. When a query comes in, we retrieve the most relevant schema context before generating SQL. Combined with domain-specific rules baked into the system prompt — always use COUNT(DISTINCT), always search both material columns with OR logic, always validate column existence before generating — accuracy jumped from 60% to 95%+.

We also added a three-layer SQL validation pipeline before execution: syntax check, column existence check, table access control. If the generated SQL doesn't pass all three, we return an error message rather than executing something broken.

The result: queries like "show me all polymer materials used in CRM devices" now reliably return correct results in 6–12 seconds.

DocSeek: Finding Answers Inside Dense Regulatory Documents

SQL gets you structured data. But a lot of the knowledge our team needs is buried inside PDF reports — 80-page biocompatibility evaluations, chemical characterisation narratives, bridging justifications.

DocSeek is a RAG-based document retrieval system built specifically for this. We process BER and CCT documents with a multi-attribute chunking strategy: each chunk stores not just the text, but a summary, semantic tags, and metadata about which device, which test, which standard it relates to.

The interesting design decision was query routing. Simple factual questions — "what is the body contact classification for device 123?" — go to a direct retrieval pathway. Complex analytical questions — "does the Material X in model xyz have sufficient prior use data to bridge to device 123?" — go through a multi-step reasoning pipeline that retrieves context from multiple documents and synthesises an answer.

One thing we learned: approximate nearest-neighbour search (HNSW) in Milvus can quietly miss relevant documents in a regulatory context. When someone is making a bridging decision, a missed document isn't just a UX issue — it's a compliance risk. We tuned the HNSW parameters (M=48, efConstruction=500, ef=200 at search time) to ensure comprehensive retrieval, which matters more here than raw query speed.

E&L Compound Mapping: Matching Chemistry to Source Materials

The third tool addresses a specific problem in extractables and leachables analysis. When chemical compounds are detected in leachability studies, someone has to map each compound back to which material in the device it likely originated from. With datasets of 1500+ compounds, doing this manually is not feasible.

We built a batch processing system that sends compounds to a custom GPT endpoint in groups of 5, asking it to identify likely source materials with confidence ratings (HIGH/MEDIUM/LOW) and chemical reasoning. Each result is appended to an output file immediately after processing, so a crash or timeout doesn't lose completed work.

We integrated PubChem API lookups to enrich each compound with CASRN, molecular formula, and synonyms before sending it to the model. This significantly improved matching accuracy — the same compound might appear in documents under three different names, and having the canonical identifiers resolves that ambiguity. The system processes ~55 compounds per hour with built-in rate limiting and automatic retry logic for API timeouts.

What I'd Do Differently

Start with prompt engineering, not architecture. We spent time early on building elaborate retrieval systems when better-structured prompts would have solved 80% of the problems faster. The RAG layer matters, but it amplifies good prompts — it doesn't compensate for bad ones.

Domain knowledge is the actual moat. The reason these tools work for regulatory data is that we understood what the data meant before we wrote a line of code. Knowing that a biocompatibility report has a specific structure, that bridging decisions follow a particular logic, that compound mapping requires both chemical and materials knowledge — that context shaped every design decision. Generic AI tools applied to regulatory data without that understanding produce plausible-sounding but unreliable outputs.

Validation is not optional in regulated environments. In most applications, a wrong answer is an inconvenience. In a context where outputs inform regulatory submissions, wrong answers have consequences. Every one of these tools has explicit validation, error handling, and fallback behaviour. The goal isn't just to work when conditions are good — it's to fail clearly and safely when they're not.

AI Healthcare Analytics RAG SQL Medical Devices Regulatory Affairs Python