From zero to a production AI agent that speaks natural language, generates SQL, self-corrects errors, and answers questions over your data — all inside VS Code.
A fully operational RAG SQL Agent system — the same architecture used in enterprise data intelligence tools.
Every tool is pinned to an exact version. No "latest" — that breaks production systems.
Understand the blueprint before you build. Every prompt in Phase 3 maps to one of these layers.
How a question becomes an answer — 7 steps every query travels.
22 files across 5 modules. Each prompt in the Build phase creates one module completely.
Copy each prompt, paste it into VS Code (Cursor, Windsurf, or Claude Code), and let AI build each layer. Complete each phase to unlock the next.
rag_sql_agent/ folder with 5 subfolders, requirements.txt, .env.example, and all packages installed. The folder structure should match the architecture diagram exactly.conn.register("table_name", df). Always drop the view first: conn.execute("DROP VIEW IF EXISTS table_name")sales_data and the columns are region and sale_amount. RAG retrieves this schema context without stuffing the entire schema into every LLM call — it only retrieves the relevant parts.SessionState class. No direct st.session_state["key"] in app.py. This prevents state corruption across reruns.If the browser opens and you can upload a file and ask a question — you built a production RAG SQL Agent from scratch using AI-powered prompts.
Every prompt in one place — organized by build layer. Use these to rebuild any component or extend the system.
After the agent is running, use these prompts to add advanced features.
When things break — and they will — use these targeted prompts to diagnose and fix.
Test your understanding of RAG SQL Agent architecture. 5 questions, 50 XP available.
sql_generator.repair() with the broken SQL and the DuckDB error message. What is the maximum number of repair attempts before the agent gives up?conn.execute("DROP VIEW IF EXISTS table_name") BEFORE every conn.register()?sentence-transformers library is used for embeddings instead of the OpenRouter API. What is the main reason for this design choice?IntentClassifier returns META_QUESTION instead of DATA_QUERY for "hello" and "what can you do?". Why is intent classification important for production agents?Your agent is live. Here's how to use it, test it, and take it further.
Common DuckDB SQL patterns — share this with the LLM in your prompts if it generates wrong dialect.
| Model | Model ID | Best For | Cost |
|---|---|---|---|
| GPT-4o Mini | openai/gpt-4o-mini | Fast SQL, high volume queries | Very Low |
| GPT-4o | openai/gpt-4o | Complex multi-table SQL, joins | Medium |
| Claude 3.5 Sonnet | anthropic/claude-3.5-sonnet | Best reasoning, complex data analysis | Medium |
| Claude 3 Haiku | anthropic/claude-3-haiku | Ultra-fast responses, simple queries | Very Low |
| Gemini Flash 1.5 | google/gemini-flash-1.5 | Fast, large context window | Low |
| Llama 3.1 70B | meta-llama/llama-3.1-70b-instruct | Open weights, private/sensitive data | Low |
You understand RAG, SQL agents, vector embeddings, self-repair loops, and Streamlit interfaces — from first principles, by building each layer yourself.