INTERMEDIATE · 8 MODULES · 64 LESSONS
SQL for LLMs and Agents
Let an AI agent answer questions about your database by writing SQL, without risking deletes or leaks, and validating each query before it runs.
- For you if
- You already know SQL and want a model to generate it reliably against your data.
- By the end
- You'll know how to give the model your schema, enforce read-only guardrails, and measure your assistant's accuracy.
- You need
- Intermediate SQL and Python 3.11 or later. No API key needed: model calls are simulated.

Curriculum
01Por qué SQL y LLMs, el problema text-to-SQL, presentado
02Darle el esquema al LLM
- Module 2 Introduction: Giving the LLM the Schema
- Why the LLM doesn't know your database
- Serializing the schema: DDL vs. compact form
- Column descriptions: cents and domains
- Sample rows in the context
- Extracting relationships with PRAGMA
- The token budget: what to include and exclude
- Mini-project: build a schema context for Reservo
03Promptear para SQL correcto
- Module 3 Introduction: Prompting for Correct SQL
- A SQL assistant's system prompt
- Few-shot: question→SQL examples
- Pinning the SQLite dialect
- Constraint instructions and output format
- Handling ambiguity: asking for clarification or stating the assumption
- Asking for SQL + structured explanation
- Mini-project: a SQL assistant prompt for Reservo
04Validar y ejecutar el SQL generado
- Module 4 Introduction: Validating and Executing the Generated SQL
- Never trust the generated SQL blindly
- Validating the shape: does it parse? a single statement? is it SELECT?
- Validating against the real schema: catching hallucinated tables and columns
- Executing safely: capturing errors and a sanity LIMIT
- The self-correction loop: feeding the error back to the model and retrying
- Common failure modes in generated SQL
- Mini-project: a validate-then-execute pipeline
05Guardrails y seguridad
- Module 5 Introduction: Guardrails and Safety
- The Prompt Is Not a Security Barrier, and Least Privilege
- Read-Only at the Connection: `PRAGMA query_only` and `mode=ro`
- The Statement Allowlist: Only `SELECT`/`WITH`, a Single One
- Resource Limits: Forced `LIMIT`, Timeout, and Row Cap
- Injection: Why the LLM's SQL Is an Attack Surface, and `?` Parameters
- Defense in Layers: All Together, Covering Each Other
- Mini-Project: A Read-Only, Guarded Executor
06El loop del agente SQL
- Module 6 Introduction: The SQL Agent Loop
- The Agent Loop: Question → SQL → Validate → Run → Observe → Answer
- Tool-Calling: the `run_sql` Contract and Its JSON Schema
- The `tool_use` → `tool_result` Shape of the Messages API
- Multi-Step: Exploring the Schema with a Tool, Then Querying
- When to Stop and the Iteration Cap
- Error Handling Inside the Loop: the Error as a `tool_result` the Model Corrects
- Mini-Project: a SQL Agent Loop for Reservo
07Evaluar text-to-SQL
- Module 7 Introduction: Evaluating Text-to-SQL
- Why Measure and Not Trust the Impression
- Execution Accuracy vs. Comparing the SQL's Text
- Building the Test Set: Question → gold_sql
- The Harness That Runs the Set and Reports the %
- The Failure Modes the Evaluation Reveals
- Regression: Re-Evaluating When You Change the Prompt or the Model
- Mini-Project: an Evaluation Set for the Reservo Assistant
08Proyecto, un asistente SQL seguro para Reservo (capstone)
- Module 8 Introduction: a Safe SQL Assistant for Reservo
- Layer 1: Assembling the Schema Context
- Layer 2: the System Prompt with Rules and Few-Shot
- Layer 3: the Validation Layer
- Layer 4: Guardrails and the Safe `run_sql`
- Layer 5: the Agent Loop with Self-Correction
- Layer 6: the Evaluation Set and Execution Accuracy
- Project: a Safe SQL Assistant for Reservo
Reviews
What students say
These reviews are from enrolled students who completed at least 50% of the course. We moderate reviews only on content grounds (spam, offensive language, personal data), never for being critical or negative.
No approved reviews yet.
Be the first to share your experience!