Moraldeep Sachdeo

Moraldeep Sachdeo

Product Manager
Engineering Program Manager

Mountain View, CA
moraldeepsingh@berkeley.edu


← Back to Vibe-Coding

Ask Your DB — Natural Language to SQL Agent

An interactive text-to-SQL system that translates plain-English analytics questions into executable SQL, validates safety, and measures quality with a rigorous evaluation harness.

Natural Language Analytics Agent
Ask a data question in English, get executable SQL and grounded answers in seconds
The system introspects live database schema, generates SQL with open-source models on Fireworks AI, executes the query, and retries once with error feedback when execution fails. It also includes SQL guardrails and benchmark scripts to track correctness, latency, and cost.

Overview

Ask Your DB is built around a practical product question: can a text-to-SQL agent be accurate enough for real analytics workflows while staying fast and cost-efficient? Instead of optimizing for demo output, the project emphasizes executability, safety, and measurable quality across both known and unseen schemas.

What The Product Does

Implementation Details

Database Description

The primary database is Chinook, a digital music store schema in SQLite with 11 related tables including Artist, Album, Track, Customer, Invoice, and InvoiceLine. This gives the agent realistic join paths for customer behavior, revenue, and catalog analytics. To test generalization beyond a familiar benchmark, the project also generates a second synthetic GitLab analytics schema with 7 tables and a larger templated question set.

In practice, the agent starts by reading schema metadata and sample rows from the active database. That context is injected into the prompt so SQL generation is grounded in actual table and column names rather than guessed structure.

Example Query Walkthrough

One representative flow from the CLI looks like this:

Question: Which 5 customers spent the most in total?

Generated SQL:

SELECT
  c.CustomerId,
  c.FirstName || ' ' || c.LastName AS CustomerName,
  ROUND(SUM(i.Total), 2) AS TotalSpent
FROM Customer c
JOIN Invoice i ON i.CustomerId = c.CustomerId
GROUP BY c.CustomerId, c.FirstName, c.LastName
ORDER BY TotalSpent DESC
LIMIT 5;

The agent executes this SQL directly and returns the top rows in the terminal, for example customer name and lifetime spend. If execution fails due to a dialect mismatch or naming issue, the error is fed back once and the query is auto-repaired before returning a final answer.

Why It Matters

This project focuses on the gap between demo-grade and production-minded AI analytics. The value is not only that it produces SQL, but that it reports whether results are truly correct, stays within practical latency and cost ranges, and fails safely when a query is unsafe.

Key Outcomes

Role and Focus

Role: Solo builder focused on agent architecture, evaluation design, reliability hardening, and cost-performance tradeoffs.

Tech Stack: Python, SQLite, Fireworks AI, OpenAI-compatible SDK, CLI tooling, JSON-based eval pipelines.

Category: Text-to-SQL, agentic analytics, LLM evaluation, trustworthy AI systems.

Positioning: Think "terminal-native BI copilot," designed for measurability and safe execution rather than prompt demos.

Project Repository

View source on GitHub