AI SQL Agent: Query Your Database in Plain English

NLP to SQL
Agentic Workflows
PostgreSQL
LangChain
Pydantic

How this was built: Agentic AI

SQL AI Agent

What is the AI SQL Agent?

The AI SQL Agent lets people who don't know SQL get data from a PostgreSQL or SQLite database by asking in plain English. I treated SQL generation like compiling code: the output has to pass strict checks before it runs. Pydantic validates each query against the database schema, so the agent returns SQL that actually runs instead of a guess.

Self-correcting SQL queries

If a query fails or returns no rows, the agent reads the error, adds it to its context, and tries again with a fixed query. This reflection loop works a lot like a developer debugging their own code. It makes the agent much more reliable on complex joins and aggregations, and the user doesn't need to step in.

Security, speed, and JSON output

The agent only has read-only access to the database, so it can't change or delete data. To save tokens and time, it only loads the table schemas that matter for each question. Results come back as structured JSON with both the SQL query and the data, so they are easy to plug into dashboards or reporting tools.


Tech Stack

Python logo
LangChain logo
PostgreSQL logo
OpenAI logo
Gemini logo