Text-to-SQL Agent
View Live ProjectDESCRIPTION
A natural-language interface for querying NY State mortgage records. Given a plain English prompt, the agent returns a SQL query, a chart, and the answer.
TOOLS
TIMELINE
May 2026
Public mortgage data is rich but at times hard to use. This app is an agentic avenue for quickly querying data and performing cursory analyses.
Using 2025 HMDA data, I built a Streamlit app over a DuckDB database of 430,000 New York State mortgage applications. The agent converts plain-English questions into executable SQL via a Claude API. The app executes the query against the local database, and renders the result as both a chart and a table.
Rather than parsing free-form text from the model, the agent returns a structured response through a defined schema: a SQL query, an optional explanation, and an optional chart spec. This keeps the integration predictable and makes it easy to extend. Adding the chart spec was a single field added to the schema from my end instead of a whole new layer of parsing logic.
A self-correcting retry loop feeds execution errors back to the model on failure, and an automated evaluation harness scores correctness across 15 benchmark questions covering aggregations, joins, demographics, and out-of-scope inputs. The results highlight something the system makes explicit: the generated SQL is always visible to the user, so the agent can be trusted not because it's perfect but because its reasoning is verifiable.
