How a LangGraph SQL Agent lets anyone chat with your database for free
Learn how a LangGraph SQL agent works under the hood — and how you can connect your PostgreSQL database and start querying it in plain English today, no SQL knowledge required.
How a LangGraph SQL agent lets anyone chat with their PostgreSQL database for free
You have data sitting in a database. Your team has questions. But every time someone needs an answer, they either write SQL themselves — or they wait for someone who can.
A LangGraph SQL agent breaks that bottleneck. It understands plain English questions, writes the SQL, runs it against your database, and explains the result — all automatically. No query writing. No waiting. No cost.
What is a LangGraph SQL agent?
LangGraph is a framework for building stateful, multi-step AI workflows as graphs. Each step is a node. Each decision is an edge. When applied to SQL, the result is a LangGraph SQL agent — a pipeline that takes a natural language question and turns it into a verified, executed database query.
A typical langgraph sql agent flow looks like this:
- Classify intent — is this a database question or casual conversation?
- Discover tables — what tables exist in the connected database?
- Fetch schema — what columns and types are relevant to this question?
- Generate SQL — write a syntactically correct query for this dialect
- Validate — check for hallucinated tables, blocked statements, syntax errors
- Execute — run the query against your real database
- Answer — convert the raw result into a plain English response
Each node has one job. If SQL generation fails, the agent retries automatically — passing the error back to the LLM so it can self-correct. Users never see the failure. They just get the answer.
Why LangGraph specifically?
Most simple text-to-SQL demos use a single LLM call: question in, SQL out. That works for toy examples. It breaks on real databases with dozens of tables, ambiguous column names, or complex joins.
LangGraph solves this with a stateful graph. The agent carries context across every step — which tables it found, what schema it retrieved, whether the last query errored and why. When something goes wrong, it doesn't start over from scratch. It knows exactly where it failed and retries intelligently.
This is why production-grade agente SQL LangGraph implementations use the graph approach over a single-shot prompt. The retry loop alone recovers from the majority of SQL generation failures without any user intervention.
What databases does it support?
Right now, QueryDB supports PostgreSQL — the most widely used open-source relational database in production. Whether you're running on Supabase, Railway, Render, AWS RDS, or a self-hosted instance, if it speaks PostgreSQL, you can connect it.
A well-built agen SQL LangGraph implementation is fully dialect-aware, generating PostgreSQL-native syntax including:
ILIKEfor case-insensitive searchDATE_TRUNCandEXTRACTfor time-series queriesJSONBoperators for semi-structured dataLIMIT / OFFSETfor paginationCTEs(WITHclauses) for readable complex queries
Support for MySQL, SQLite, and other dialects is on the roadmap. For now, PostgreSQL users get a first-class, deeply tested experience.
How the validation layer protects your data
One concern with any AI-generated SQL is safety. A LangGraph SQL agent built for production should never execute destructive statements. Here is what a robust validation node checks before any query runs:
Blocked statement types:
INSERT,UPDATE,DELETE— data modificationDROP,ALTER,TRUNCATE— schema destruction- Multi-statement queries — e.g.
SELECT ...; DROP TABLE ...;
Hallucination detection:
The agent parses the generated SQL with a library like sqlglot and compares every table name against the list of real tables in your database. If the LLM invented a table that doesn't exist, the query is rejected and regenerated — not executed.
Read-only by design: The database connection itself is created with a read-only user. Even if a blocked statement somehow passed validation, the database would reject it at the permission level. Two independent safety layers.
Try it free — bring your own API key
QueryDB is built on a LangGraph SQL agent architecture and is free to use. You connect your own database and bring your own LLM API key — OpenAI, Anthropic, Mistral, or any OpenAI-compatible endpoint including local models via Ollama.
Because you supply the key, your data never touches our infrastructure on the way to the LLM. The query is generated and executed entirely in your session.
To get started:
- Sign up free →
- Connect your PostgreSQL database
- Paste your API key
- Ask your first question in plain English
No credit card. No query limits on the free tier. No schema stored on our servers.
What kinds of questions can it answer?
Anything expressible as a SQL SELECT. Some examples from real users:
- "How many new users signed up last week broken down by day?"
- "What are the top 10 products by revenue this quarter?"
- "Which customers have made more than 3 purchases but haven't ordered in 90 days?"
- "Show me the average response time per endpoint for the last 24 hours"
- "What percentage of invoices are overdue by more than 30 days?"
The agent figures out which tables to join, writes the aggregation, handles PostgreSQL date arithmetic, and returns both the answer and the SQL it used — so you can verify, copy, or extend it.
The bottom line
A LangGraph SQL agent is the right architecture for reliable text-to-SQL because it separates concerns, handles retries gracefully, and validates before it executes. It's not a single prompt — it's a pipeline with guardrails at every step.
QueryDB brings that architecture to anyone with a PostgreSQL database and an API key. Your team stops waiting for SQL. Your data stays in your infrastructure. And the first query is free.