SQL in the Age of AI

Course

Run the Pipeline

A hands-on 15-lesson advanced SQL course. Build, test, operate, and safely improve a pipeline with your AI coding agent.

You know how to write a query. Now make it safe to run every day.

  • Turn a saved query into a pipeline with explicit dependencies, checks, tests, and evidence.
  • Choose update strategies that tell when an order happened, when it reached the system, and which dates need repair.
  • Give an agent a limited environment, rules it cannot bypass, and enough logs to investigate a failure.
  • Ship a governed retail pipeline whose outputs can be reviewed, repaired, and rerun without trusting a confident answer.

How it works

Your coding agent teaches the course. It reads the project, teaches one lesson at a time, asks the quiz questions, and reviews the task after you finish it. These pages are a companion you can use alongside that conversation.

1. Paste this setup prompt into your agent in an empty folder.

AI Prompt

You are going to set up and then teach me an interactive SQL course. Do this in order, and show me each command before you run it:

  1. Check that Git and Bruin are installed (git --version, bruin version). If Bruin is missing, install it with curl -LsSf https://getbruin.com/install/cli | sh, then check the version again.
  2. From the empty folder where I want the project to live, run bruin init --in-place academy-sql-advanced.
  3. Run bruin validate academy-sql-advanced/pipeline. Then generate the sample data with bruin run academy-sql-advanced/pipeline. The shipped project intentionally fails only on mart.churn_risk; stop if any other asset fails or if validation fails. After the expected failure, confirm orders has 1,212 rows and order_items has 2,895 rows.
  4. Read academy-sql-advanced/AGENTS.md and academy-sql-advanced/course/README.md so you know how to run the course.
  5. Greet me, show me the 15-lesson syllabus, and tell me to say "next lesson" to begin and "review my work" whenever I finish a task.

After setup, stay in the project root containing .bruin.yml; lesson paths such as pipeline and queries/... are relative to that directory. Do not teach lesson one yet - get set up and hand me the controls. If any command fails unexpectedly, stop and show me the error instead of trying something else.

The default environment is local DuckDB and needs no token. MotherDuck is optional. No lesson requires the cloud path.

2. Say next lesson. The agent teaches the next incomplete lesson, asks its questions one at a time, and gives you the task.

3. Do the task and say review my work. The agent reads the artifact or answer, runs the required checks, and grades it against the lesson rubric.

What you will build

The template is a repeatable retail pipeline with generated input data, staging tables, shared models, and reporting tables. Bruin calls the last group marts. The project is intentionally not clean: validation passes, while the first run fails only at mart.churn_risk so you can investigate a real defect in an earlier table later.

By the capstone, you will have a dependency graph, checks that stop bad output, unit tests, update rules that touch only the dates that changed, a customer history table that keeps old versions, late-data evidence, a dev run, a logging plan, and a written capstone defence. The target is a pipeline whose failures are visible, limited, and explainable.

The four phases

  1. Build the pipeline - classify operational risk and read the dependency graph.
  2. Make failure loud - turn audit questions into checks, tests, and controlled failure drills.
  3. Run it repeatedly - make reruns safe, handle late data, compare filters, and use a separate dev database.
  4. Operate with an agent - place guardrails at the right layer, investigate the shipped failure, read evidence, and ship the capstone.

Before you start

Take Design the Model first if you have not worked with model contracts, grain, joins, and data quality. This course assumes you can review SQL and focuses on the operational consequences of running it repeatedly.

Before you start

  • The intermediate course, Design the Model, or equivalent experience with SQL modeling, joins, grain, and data quality.
  • Git, a terminal, an AI coding agent, and a code editor. The setup prompt creates a local DuckDB project with no cloud credentials required.

15 steps

Course outline

Start course

Build the pipeline

Turn a query into a reliable graph and classify the risk of each operation.

  1. 1Query to pipelineMake a recurring pipeline safe to repeat, check, repair, and stop when output is wrong.
  2. 2SQL changes and approvalDecide which database changes an agent may run and which need review first.
  3. 3Dependencies and the graphRead the pipeline graph and separate run order from quality checks.

Make failure loud

Turn audit questions into checks, tests, and controlled failure drills.

  1. 4Checks as automated auditTurn grain and reconciliation questions into blocking checks.
  2. 5Unit-test the logicTest SQL transformations with controlled inputs and exact expected rows.
  3. 6Break it on purposePredict, trigger, and repair controlled failures without losing the evidence.

Run it repeatedly

Make reruns safe, handle late data, compare filters, and use a separate dev database.

  1. 7Incremental updates and historyUpdate only changed dates, prove reruns are safe, and keep old customer versions.
  2. 8Late data and backfillsTell when an order happened from when it arrived, then design a limited repair.
  3. 9Date filters and query costCompare date filters and learn what local scan evidence can tell you about cost.
  4. 10Dev environmentsGive agent experiments an isolated destination and understand its limits.

Operate with an agent

Investigate failures, preserve evidence, and ship a governed pipeline.

  1. 11GuardrailsPlace pipeline rules at the layer that can actually enforce them.
  2. 12Investigate a failureTrace the broken churn-risk asset to the smallest safe fix.
  3. 13Logs, history, and the billUse structured run evidence and distinguish local logs from warehouse cost history.
  4. 14Capstone: ship itMake both reporting tables safe to update, test, document, and rerun.
  5. 15Recap and next stepsKeep the evidence, tests, timestamps, and boundaries that make agent work safe.

Get help & contribute

Sign up to our newsletter

Practical updates on open-source data pipelines, AI analysts, governance, and what we are shipping at Bruin.

The signup form is hosted by Brevo. Allow marketing cookies to load it.