Here's the thing about database queries: they're cognitive overhead.
When you need to answer "what's the highest-paid department?" you have to:
- Remember the schema
- Figure out which tables to join
- Write (or hunt for) the right SQL
- Run it
- Interpret results
If your database is large enough, you also have to think about indexes, query plans, and whether you've accidentally created an N+1 problem.
For a simple query, that's fine. But when you're doing exploratory analysis — hopping between databases, trying different angles on the data — the cognitive load adds up fast.

What if you could just ask the database a question in English?
The Problem We Solved
I've been building Pilotbase — a universal database GUI for SQL, NoSQL, and vector databases. Early on, the question came up: what if we added an AI agent that could understand your schema and write queries for you?
The catch: making it actually useful, not just a neat demo.
A query-writing AI needs to:
- Understand your schema (tables, columns, types, relationships)
- Pick the right database (if you're connected to multiple databases, which one has the data you need?)
- Translate intent to query (plain English to SQL, MongoDB aggregation, etc.)
- Warn before destructive ops (never silently execute a DROP TABLE)
- Work with local LLMs (not every team wants to send data to OpenAI)
How We Built It: LangGraph + ReAct
We used LangGraph — a framework for building agentic LLM workflows — and the ReAct (Reasoning + Acting) pattern.
The agent has a few tools:
- list_databases — shows what databases you're connected to
- describe_table — fetches schema for a specific table
- execute_query — runs SQL, aggregation pipelines, etc.
- ask_clarification — asks you if it's unsure
Here's how a real example plays out:
You ask: "Show me the top 10 customers by total spend, and break it down by product category."
The agent thinks:
- "I need to find the top customers by total spend" → list_databases + describe_table
- "I need to join customers, orders, and product categories" → more schema exploration
- "I'll write a SQL query that groups by category, sums spending"
- "Before I run this, I should ask for confirmation" → warns and asks
- You approve → it runs, returns results, explains what it did
The agent explains: "I joined customers, orders, and products on order_id and product_id, grouped by category, and ranked customers by sum(order_amount). Results show Alice spent $50K on electronics, $30K on home goods..."
Why ReAct Works
ReAct is different from simple prompt-engineering. It's:
- Iterative — the agent can think, take an action, observe the result, and adjust
- Transparent — you see its reasoning in real-time
- Safe — it can ask for confirmation before destructive operations
- Composable — you can add new tools without rewriting the whole flow
For database queries, that matters. The agent can:
- Fail gracefully if it picks the wrong table
- Go back and explore schema differently
- Ask you clarifying questions if the intent is ambiguous
Local LLMs: Not Sending Data Anywhere
By default, Pilotbase uses Ollama — a way to run open-source models locally.
You can run a model like Mistral or Gemma locally on your machine, and the agent talks to it directly. Your database schema and queries never leave your network.
If you want to use OpenAI or another hosted API instead, it's a config change. But for teams with security requirements (healthcare, finance, defense), local-only is non-negotiable.
What the AI Agent Actually Saves You
In my testing, the biggest wins are:
- Exploratory queries — "what does this data look like?" questions that would normally take multiple manual queries
- Cross-database exploration — "is this data in MongoDB or Postgres?" → the agent figures it out
- Time on simple stuff — no more hunting for that one query you wrote last month
- Onboarding new analysts — they can ask questions about the data without needing to know SQL
The biggest limitations are:
- Hallucinations — LLMs sometimes make up table names or logic that doesn't exist
- Complex queries — the more joins and subqueries, the more likely the agent gets confused
- Write operations — we're currently read-only for NoSQL (MongoDB write support is planned)
The Architecture, In 30 Seconds
Frontend (React)
↓
FastAPI backend
↓
LangGraph agent (ReAct)
↓
Database adapters (SQLAlchemy, pymongo, redis-py, etc)
↓
Your databases (Postgres, MongoDB, Redis, Qdrant, etc)
The agent is pluggable — you can swap in your own LLM, add new database adapters, or extend the tool set.
Try It
Pilotbase is fully open source (MIT), self-hosted, runs in Docker.
git clone https://github.com/icedsg/pilotbase.git
cd pilotbase
docker compose up --build
# Visit http://localhost:8000
The AI agent is live right now in v2 beta. Feedback and contributions welcome.

Top comments (0)