- “This query needs deterministic ordering before
LIMIT.” - “Move this model into the agreed area and layer.”
- “Final models cannot depend on another area’s private intermediate models.”
- “This incremental output needs a declared grain, an enforced contract, and a focused test.”
- “External sources must enter through staging.”
What Rules are for
Start with built-in Rules, then add custom Rules for requirements specific to your project.- Built-in Rules are opinionated, reusable checks for areas such as SQL safety, contracts, and dependency boundaries. Select or ignore each Rule individually.
- Custom Rules encode local decisions such as directory structure, architectural boundaries, public interfaces, or the contract and test coverage required for a particular kind of model.
SELECT * in staging while requiring
contracted outputs in final models, or allowing cross-area dependencies only through an interface
model.
How Rules work
Usesqb rules show to understand a Rule before enabling it:
Enabled by default means the Rule is included when a matching family is selected. Configurable
Rules do not run unless select contains an exact code or matching family.
Select Rules in sqlbuild_project.toml. This example enables the complete built-in SQL family:
SQBRSQL004 selects one Rule. A family code such as SQBRSQL selects every
Rule in that family. An empty select disables configurable Rules, but mandatory compiler
correctness still applies.
Now consider a model that returns an arbitrary row because its LIMIT has no ordering:
sqb compile before treating the whole
project as valid.
Where SQL linting went
SQL linting is part of the Rules system rather than a separate command. TheSQBRSQL built-in family covers deterministic SQL diagnostics such as:
- unsafe
NULLcomparisons; - implicit cartesian joins;
- unordered
LIMITandOFFSET; - unused CTEs;
- duplicate aliases;
- unstable window ordering;
- risky set-operation shapes;
- selected SQL structure and convention requirements.
sqb lint
lifecycle. If an SQL requirement affects whether the project is acceptable, the compiler enforces
it with the rest of the configured Rules.
Not every traditional lint concern should become a diagnostic. SQLBuild separates three kinds of
SQL responsibility:
Rules never rewrite source.
sqb format rewrites source and does not decide whether a project
passes its configured Rules. This keeps diagnostics and source mutation separate.
Built-in and custom Rules
SQLBuild maintains native built-in Rules for reusable requirements. Their codes begin withSQBR,
for example SQBRSQL004 and SQBRGRAPH101.
Projects can define custom Python Rules under rules/**/*.py. Their codes begin with XSQBR, for
example XSQBRARCH001. Custom Rules use the same selection, findings, exceptions, execution order,
and cache system as built-ins.
Author custom Rules
Define typed model or project checks over compiler-owned facts with
@rule, RuleContext, and
Finding.One definition of project validity
sqb compile is authoritative. SQLBuild evaluates a project in this order:
Rules compared with tests, audits, and contracts
Rules do not replace every form of validation:
Use a Rule when the answer can be determined from source and compiler facts. Use a test when you
need to execute SQL against controlled data. Use an audit when the answer depends on warehouse data.
Findings and intentional exceptions
A finding contains a stable code, project-relative path, line, column, explanation, and remediation. This makes the same requirement usable in a terminal, JSON output, CI annotation, or agent workflow. Intentional departures remain explicit. Exact exceptions and path- or resource-scoped ignores require a reason; exact exceptions are stale-checked so obsolete suppressions do not silently accumulate. Mandatory compiler correctness cannot be suppressed. See Findings and exceptions for configuration examples.Performance is part of the design
Model Rules are evaluated and cached per model. Editing one model invalidates affected subjects rather than every invocation. Project Rules run once over the complete project view and are the explicit choice for genuinely project-wide requirements, with broader invalidation. SQLBuild tracks the inputs each Rule depends on so cached findings are reused only while those inputs remain valid. In required CI, 20 custom Rules over a production-shaped 5,000-model project complete their first compile in just over 10 seconds and an unchanged compile in under six. A 100-Rule stress profile completes an unchanged compile in just over seven seconds. See Benchmarks for the complete workload, methodology, and results, and Execution and caching for the Rules lifecycle.Continue
Configuration and selection
Select exact Rules or families and configure project-owned options.
Findings and exceptions
Understand diagnostics, exact exceptions, path ignores, and stale checks.
Execution and caching
Learn evaluation order, focused execution, and dependency-aware reuse.
Rules CLI
List, inspect, run, and generate guidance for configured Rules.

