sqb compile
Compiles all discovered models, seeds, audits, and tests. Resolves references, expands macros, validates SQL, checks column contracts, computes column lineage, and writes compiled artifacts totarget/. The compile command is fully offline - it does not connect to the warehouse.
Usage
Flags
| Flag | Description |
|---|---|
--no-sql-validation | Skip compile-time SQL syntax validation |
--defer-to | Resolve unselected model references against another target |
--json | Output the full compile report as JSON |
--manifest | Generate target/manifest.json with project metadata |
--lineage-mode | Column lineage mode: fast (default), rich (slower, more detail), or none |
What compile does
- Discovery - finds
sqlbuild_project.toml, scans for models, sources, seeds, functions, audits, tests, and macros - Graph resolution - resolves
ref()andsource()calls, expands macros, orders models by dependency - SQL validation - validates SQL syntax (when SQL analysis is enabled)
- Column lineage - analyzes column-level dependencies across models (fast mode by default)
- Contract validation - checks declared column contracts against inferred query output
- Artifact write - writes compiled SQL to
target/compiled/
Static analysis
When SQL analysis is enabled (default), compile performs static analysis on your models without connecting to the warehouse:- Column inference: Infers output columns from each model’s SQL, including through CTEs, subqueries, and JOINs
- Column contract validation: If a model declares columns in its
MODEL()header, compile checks that every declared column exists in the query output. If a column declares a type andtype_enforcementis enabled, compile also verifies the inferred type matches the declared type - Column lineage: Traces which source columns flow into each output column, including transform classification. See Column Lineage for details
Contract diagnostics
When a contract violation is found, compile reports it with source-annotated diagnostics:| Code | Meaning |
|---|---|
K001 | A declared column is missing from the model’s query output |
K002 | A column’s inferred type does not match the declared type |
K003 | A column’s type could not be proven (with type_enforcement enabled) |
1 when any error-severity diagnostic is found, making it suitable for CI checks.
Output
Text output (default)
JSON output
summary- model, seed, function, audit, test, error, and warning countsresources- per-model details including column count, dependencies, lineage summary, and compiled SQLdiagnostics- all contract violations with source locationscompile_timings- timing breakdown for discovery, graph, lineage, contracts, and write phaseslineage_mode- which lineage mode was usedartifacts- paths to written files
Column lineage modes
The--lineage-mode flag controls how column lineage is computed during compile:
| Mode | Description |
|---|---|
fast | Default. Lightweight column extraction using SQL model metadata. |
rich | Full SQL analysis with transform classification and deeper tracing. Slower on large projects. |
none | Skip column lineage entirely. |
lineage field. See Column Lineage for details on analysis modes and transform types.

