Nodes
A clinical question enters intent analysis, then SQL generation when answerable. The generator performs basic syntax checks and repair; execution and result comparison happen in the evaluator.
Team project · Imperial College London
Answered 17 of 20 questions correctly in the team’s project evaluation.
Role: Planner-agent design, LangGraph integration and failure-case evaluation.
Translate clinical questions into schema-grounded SQL over MIMIC-IV, with validation, repair and safe abstention.
System representation
Hospital records are spread across tables. The team's assistant turns a question into SQL—the instructions used to retrieve records. My work focused on stepwise planning, LangGraph integration and failure-case testing.
How many patients were admitted in 2018?
The intent step identifies the kind of question. It can stop with no query when the request is not answerable from the database.
Gemini 2.5 Pro receives the question, its intent and the available schema: the names and structure of the tables.
Basic syntax checks catch malformed queries. The generator can retry after an error; unresolved failures return no SQL.
↺ Repair happens inside the generator
A request for treatment advice is different from a request to retrieve a recorded fact. The system can return null instead of SQL.
The evaluator executes generated and reference SQL in SQLite and compares the returned results. Passing syntax checks alone does not establish that the question was answered correctly.
The supplied notebook has two LangGraph nodes: intent_analyzer and generator. The generator makes at most two attempts in total. Checks cover basic SELECT structure, parentheses and incomplete clauses; table-name checks provide warnings rather than blocking output. SQL execution is part of the separate diagnostic evaluator. These checks do not certify clinical correctness.
A clinical question enters intent analysis, then SQL generation when answerable. The generator performs basic syntax checks and repair; execution and result comparison happen in the evaluator.
LangGraph coordinates shared state, nodes and transitions.
Answerable intents route to the generator; unanswerable intents end the graph. Syntax repair and retries take place inside the generator before output is returned.
The system abstains when it cannot produce a safe answer.
Core Ideas / Concept Primer
SQL expresses a query over relational tables. Text-to-SQL translates a natural-language question into that query; a syntactically valid query can still answer the wrong question.
The planner decomposes a question into cohort, time window, admissions and aggregation. Making these choices explicit helps separate interpretation of the question from query construction over MIMIC-IV.
State carries information through a run. The supplied implementation has intent-analysis and generation nodes, with a conditional route to generate or end. The repair loop is internal to generation.
Basic syntax checks can trigger another generation attempt. Table-name checks are advisory, while execution is tested separately. Neither a parseable query nor a matching response format guarantees the correct answer.
Natural-language request
Intent analysis and stepwise decomposition
Schema-grounded query construction
Syntax, schema and execution checks with repair
Execute valid queries; abstain when unresolved
Designed stepwise planner logic; integrated LangGraph state, nodes and transitions.
Performed failure-case testing within the team evaluation, which answered 17 of 20 questions correctly.
Imperial College London team project using MIMIC-IV.