contracts
dbt-forge contracts generate creates dbt data contracts (v1.5+) by introspecting
column types from your warehouse. Use it to enforce schema stability on public models
without writing contract YAML by hand.
Command
Section titled “Command”dbt-forge contracts generate [MODEL] [--all-public] [--dry-run] [--yes] [--target TARGET]What it does
Section titled “What it does”The command connects to your warehouse, reads column names, data types, and nullability for each model, then updates the model’s YAML file with:
contract: { enforced: true }in the model configdata_typeon each columnnot_nulltest for non-nullable columns (if not already present)
Existing descriptions, tests, and other YAML content are preserved.
Arguments
Section titled “Arguments”Generate a contract for a specific model.
dbt-forge contracts generate ordersOptions
Section titled “Options”--all-public
Section titled “--all-public”Generate contracts for all models with access: public defined in YAML.
dbt-forge contracts generate --all-public--dry-run
Section titled “--dry-run”Preview the generated YAML without writing to disk.
dbt-forge contracts generate orders --dry-run--yes, -y
Section titled “--yes, -y”Auto-accept all generated contracts without interactive review.
dbt-forge contracts generate --all-public --yes--target
Section titled “--target”dbt profile target for the warehouse connection. Defaults to dev.
dbt-forge contracts generate orders --target prodInteractive review
Section titled “Interactive review”When run without --yes, the command presents each generated contract for review.
You can accept or skip each model, following the same pattern as docs generate.
Generated output
Section titled “Generated output”For a model orders with columns id (INTEGER, NOT NULL), amount (NUMERIC, NULL),
and created_at (TIMESTAMP, NOT NULL):
version: 2models: - name: orders config: contract: enforced: true columns: - name: id data_type: INTEGER data_tests: - not_null - name: amount data_type: NUMERIC - name: created_at data_type: TIMESTAMP data_tests: - not_nullFinding public models
Section titled “Finding public models”The --all-public flag scans all YAML files under models/ for models with
access: public (either at the top level or inside config:). This follows the
dbt Mesh convention where public models are the contract boundary between projects.
Behavior and limits
Section titled “Behavior and limits”- Must run from inside an existing dbt project (walks up to find
dbt_project.yml). - Reads connection credentials from
profiles.ymlusing theintrospectmodule. - Requires the model to exist in the warehouse (the table/view must be queryable).
- Schema is inferred from the model’s directory path (e.g.,
models/staging/uses schemastaging). - If the YAML file already exists, existing content (descriptions, tests, other models) is preserved.
- If the YAML file does not exist, a new file is created with
version: 2. - The
not_nulltest is only added for non-nullable columns and only if not already present. - Supported warehouses: all 8 adapters (BigQuery, Snowflake, PostgreSQL, DuckDB, Databricks, Redshift, Trino, Spark).