What If You Could Just... Ask Your Data a Question? 🤔
Most people who need insights from a data file are blocked by one simple thing: they don't know SQL. Even technically strong users often don't want to stop, inspect schema manually, write queries, debug syntax, and format results just to answer a quick question like "Which category has the highest revenue?" or "Show me null rates by column."
This project removes that friction entirely. Upload your file, type your question in plain English, and let a Gemma 4-powered agentic backend inspect the schema, generate DuckDB SQL, execute it, and return the results — right inside a clean chat interface. 🎯
👉 Try it live here: https://databro.dev/backend/ai-data-chat/
🛠️ The Full Stack at a Glance
Before diving deep, here's the architecture that powers this tool:
| Layer | Technology |
|---|---|
| Frontend | Next.js (Portfolio App) |
| Edge Middleware | Supabase Edge Functions |
| Backend API | FastAPI on Google Cloud Run |
| AI Agents | CrewAI |
| SQL Engine | DuckDB |
| LLM | Gemma 4 via Hugging Face Inference API |
| File Formats | CSV, XLSX, Parquet, JSON, Arrow IPC |
🌟 Meet the Gemma 4 Model Family
Gemma 4 is Google DeepMind's latest family of open models — and they are genuinely exciting for agentic builders. Unlike earlier iterations, Gemma 4 is built with logic-heavy, reasoning-oriented workflows in mind, which makes it a natural fit for tasks like natural-language-to-SQL generation.
Here's a builder-friendly overview of the lineup:
| Model | Context Window | Why It's Interesting |
|---|---|---|
| Gemma 4 E2B | 128K tokens | Smallest effective-size model — ultra-deployable, great for edge and lightweight inference |
| Gemma 4 E4B | 128K tokens | Stronger capability with multimodal notes — a sweet middle ground for multi-step tasks |
| Gemma 4 26B A4B | 256K tokens | Mixture-of-Experts architecture — advanced reasoning with long context, perfect for agentic workflows |
| Gemma 4 31B | 256K tokens | Largest dense instruct-tuned model — maximum open-model capability for complex tasks |
The AI Data Chat tool exposes google/gemma-4-31B-it and google/gemma-4-26B-A4B-it via Hugging Face endpoints. Once you see these models turn a fuzzy natural-language question into a working DuckDB query over your own uploaded file, it becomes very hard not to imagine ten more use cases. 🔥
🤖 A Brief Foundation on CrewAI
CrewAI is an open-source framework for orchestrating autonomous AI agents in structured multi-agent workflows. Instead of a single giant prompt doing everything, CrewAI lets you break a problem into specialized, coordinated responsibilities.
Three building blocks to understand:
🧑💼 Agents
Specialized workers, each with a defined role. Think of them as employees on your AI team — one might be a "Schema Inspector," another a "SQL Writer," another a "Result Formatter."
📋 Tasks
Units of work assigned to agents. A task has a clear description, expected output, and the agent responsible for it. Examples:
- "Analyze the uploaded file and return its schema"
- "Given this schema and user intent, write a valid DuckDB SQL query"
- "Execute the SQL and format the result for the user"
🔧 Tools
Capabilities agents can invoke to act on the world — file inspection utilities, DuckDB query executors, schema extractors, etc.
This model is powerful because it creates transparent, inspectable pipelines instead of black-box AI magic. Every step has a purpose, and every output is traceable.
🏗️ How the Tool Is Built — End to End
Step 1 — The Next.js Frontend
The portfolio app at databro.dev/backend/ai-data-chat/ provides a split-panel chat UI:
- Left panel: File upload zone (drag & drop), attached file display with name and size, LLM Settings panel with Provider + Model selectors
- Right panel: Chat interface with starter prompt buttons, conversation history with SQL panels and output tables
The user picks a file, selects a Gemma 4 model via Hugging Face, and types a natural-language question. The frontend packages everything into FormData (file + user intent + provider + model) and sends it to a Supabase Edge Function.
Step 2 — Supabase Edge Function
A lean TypeScript Edge Function validates the multipart request and proxies it to the Google Cloud Run backend. This keeps the frontend thin, avoids exposing Cloud Run endpoints directly to the browser, and centralizes auth concerns at the edge.
Step 3 — FastAPI on Google Cloud Run
The Cloud Run backend receives the uploaded file and user intent. It:
- Stores the file in a temporary directory
- Detects file type (CSV, Parquet, Arrow, JSON, XLSX)
- Loads the data into DuckDB as a
datatable - Runs
DESCRIBE datato extract the full schema - Counts total rows
- Passes schema context + row count + user intent to the CrewAI agent pipeline
Step 4 — CrewAI Agent Pipeline
The agentic pipeline runs two coordinated tasks:
Task 1 — Schema Analysis
An agent uses a DuckDB tool to introspect the uploaded file and returns column names, types, and a row count. This grounding step is critical — the LLM sees real column names before generating SQL, which dramatically reduces hallucination.
Task 2 — SQL Generation + Execution
The schema and user intent are passed to the Gemma 4 model via Hugging Face. The LLM returns a valid DuckDB SQL query. The agent then executes that SQL against the uploaded file and serializes the results.
Step 5 — Response Back to the UI
The backend returns a structured JSON response containing:
-
model— the resolved model used -
sql— the exact DuckDB SQL that was generated and run -
schema— column definitions -
total_rows— row count of the uploaded file -
result— the query output rows
The frontend renders the SQL in a dark code panel and the results in a scrollable table. Transparency is built in — you always see exactly what query was run.
🎬 Live Demo — Real Queries, Real Results
I tested the tool with a real e-commerce sales CSV (49 rows, 18 columns covering orders, customers, products, categories, regions, sales, profit, discounts, and returns). Here's what Gemma 4 + CrewAI + DuckDB produced for 6 progressively complex natural language questions.
✅ Test Setup — File Uploaded, Gemma 4 31B Selected
The file sample_test_file.csv is attached (8.7 KB). Provider set to Hugging Face, model set to Gemma 4 31B Instruct. The chat interface is ready with starter prompts visible.







Top comments (0)