fan-in & fan-out (2)
Rule: max_upstream_dependencies
Manifest Rule
max_upstream_dependencies details
This rule limits fan-in. It checks how many
{{ ref() }} and {{ source() }} calls a single model has. Models that select from too many places should be broken into smaller, more focused models.By default, dbt test objects are excluded from the count. This is configurable via exclude_types.
Configuration
- type: Must be
max_upstream_dependencies. - max_upstream: (optional) Maximum number of
ref()andsource()calls a model is allowed to have. Defaults to5. - exclude_types: (optional) List of object types to ignore when counting upstream dependencies. For example,
["tests"]means dbt tests configured on a model won’t count towards its upstream limit.- Default:
["tests"] - Options:
models,seeds,sources,snapshots,tests,macros,exposures
- Default:
- applies_to: (optional) List of dbt object types this rule checks.
- Default:
["models", "snapshots"] - Options:
models,seeds,snapshots,sources
- Default:
Common Rule Config
- name: Human-readable name of the rule.
- severity:
"error"(fail) or"warning"(warn only).- (optional, defaults to
"error"if not specified)
- (optional, defaults to
- description: Human-readable explanation of the rule.
- category: Override the default rule category. Included in structured output (JSON, CSV, NDJSON) but not in the CLI table. Each rule has a built-in default (e.g.
documentation,naming,testing,governance,structure,performance).- (optional, defaults to the rule type's built-in category)
- includes: List of patterns to explicitly include for this rule. See Includes & Excludes for pattern syntax and examples.
- excludes: List of patterns to explicitly exclude from this rule. See Includes & Excludes for pattern syntax and examples.
- model_materializations: Filter models by materialization type. Only applies when
applies_toincludesmodels.- (optional, if not specified all materializations are included)
- Built-in types:
table,view,incremental,ephemeral,materialized_view. Custom materializations are also supported. - Example:
["table", "incremental"]
Example Config
manifest_tests:
- name: "limit_upstream_deps"
type: "max_upstream_dependencies"
max_upstream: 5
description: "Models should not select from more than 5 ref() and source() calls"
# exclude_types: ["tests"] (optional, default)
# severity: "warning" (optional)
# applies_to: ['models', 'snapshots'] (optional)
# includes: ["models/marts/*"]
# excludes: ["models/staging/*"]
# Stricter limit for staging models
- name: "staging_limited_deps"
type: "max_upstream_dependencies"
max_upstream: 2
includes: ["models/staging"]
exclude_types: ["tests", "macros"]
severity: "error"[[manifest_tests]]
name = "limit_upstream_deps"
type = "max_upstream_dependencies"
max_upstream = 5
description = "Models should not select from more than 5 ref() and source() calls"
# exclude_types = ["tests"] # (optional, default)
# severity = "warning" # (optional)
# applies_to = ["models", "snapshots"] # (optional)
# includes = ["models/marts/*"]
# excludes = ["models/staging/*"]
# Stricter limit for staging models
[[manifest_tests]]
name = "staging_limited_deps"
type = "max_upstream_dependencies"
max_upstream = 2
includes = ["models/staging"]
exclude_types = ["tests", "macros"]
severity = "error"[[tool.dbtective.manifest_tests]]
name = "limit_upstream_deps"
type = "max_upstream_dependencies"
max_upstream = 5
description = "Models should not select from more than 5 ref() and source() calls"
# exclude_types = ["tests"] # (optional, default)
# severity = "warning" # (optional)
# applies_to = ["models", "snapshots"] # (optional)
# includes = ["models/marts/*"]
# excludes = ["models/staging/*"]
# Stricter limit for staging models
[[tool.dbtective.manifest_tests]]
name = "staging_limited_deps"
type = "max_upstream_dependencies"
max_upstream = 2
includes = ["models/staging"]
exclude_types = ["tests", "macros"]
severity = "error"Example parent_map
The rule inspects the parent_map from manifest.json. For example:
"parent_map": {
"model.project.orders": [
"model.project.stg_orders",
"model.project.stg_payments",
"model.project.stg_customers",
"model.project.stg_products",
"model.project.stg_shipping",
"model.project.dim_dates"
]
}With max_upstream: 5, the orders model would fail because it selects from 6 other models (i.e. 6 upstream dependencies, which exceeds the limit of 5).
Rule: max_downstream_dependencies
Manifest Rule
max_downstream_dependencies details
This rule limits fan-out. It checks how many other models reference a single model via
{{ ref() }}. For example, sources should be consumed by only one downsteam model.By default, dbt test objects are excluded from the count. This is configurable via exclude_types.
Configuration
- type: Must be
max_downstream_dependencies. - max_downstream: (optional) Maximum number of other models that are allowed to
ref()this model. Defaults to5. - exclude_types: (optional) List of object types to ignore when counting downstream dependents. For example,
["tests"]means dbt tests configured on a model won’t count towards its downstream limit.- Default:
["tests"] - Options:
models,seeds,sources,snapshots,tests,macros,exposures
- Default:
- applies_to: (optional) List of dbt object types this rule checks.
- Default:
["models", "snapshots"] - Options:
models,seeds,snapshots,sources
- Default:
Common Rule Config
- name: Human-readable name of the rule.
- severity:
"error"(fail) or"warning"(warn only).- (optional, defaults to
"error"if not specified)
- (optional, defaults to
- description: Human-readable explanation of the rule.
- category: Override the default rule category. Included in structured output (JSON, CSV, NDJSON) but not in the CLI table. Each rule has a built-in default (e.g.
documentation,naming,testing,governance,structure,performance).- (optional, defaults to the rule type's built-in category)
- includes: List of patterns to explicitly include for this rule. See Includes & Excludes for pattern syntax and examples.
- excludes: List of patterns to explicitly exclude from this rule. See Includes & Excludes for pattern syntax and examples.
- model_materializations: Filter models by materialization type. Only applies when
applies_toincludesmodels.- (optional, if not specified all materializations are included)
- Built-in types:
table,view,incremental,ephemeral,materialized_view. Custom materializations are also supported. - Example:
["table", "incremental"]
Example Config
manifest_tests:
- name: "limit_downstream_deps"
type: "max_downstream_dependencies"
max_downstream: 5
description: "Reduce model fanout complexity"
applies_to: ["models"]
# exclude_types: ["tests"] (optional, default)
# severity: "warning" (optional)
# includes: ["models/staging/*"]
# excludes: ["models/marts/*"]
# Sources should only be consumed by a single staging model
- name: "source_max_downstream_dependencies"
type: "max_downstream_dependencies"
max_downstream: 1
description: "Sources should not be referenced by more than 1 model (use a staging model)"
applies_to: ["sources"][[manifest_tests]]
name = "limit_downstream_deps"
type = "max_downstream_dependencies"
max_downstream = 5
description = "Reduce model fanout complexity"
applies_to = ["models"]
# exclude_types = ["tests"] # (optional, default)
# severity = "warning" # (optional)
# includes = ["models/staging/*"]
# excludes = ["models/marts/*"]
# Sources should only be consumed by a single staging model
[[manifest_tests]]
name = "source_max_downstream_dependencies"
type = "max_downstream_dependencies"
max_downstream = 1
description = "Sources should not be referenced by more than 1 model (use a staging model)"
applies_to = ["sources"][[tool.dbtective.manifest_tests]]
name = "limit_downstream_deps"
type = "max_downstream_dependencies"
max_downstream = 5
description = "Reduce model fanout complexity"
applies_to = ["models"]
# exclude_types = ["tests"] # (optional, default)
# severity = "warning" # (optional)
# includes = ["models/staging/*"]
# excludes = ["models/marts/*"]
# Sources should only be consumed by a single staging model
[[tool.dbtective.manifest_tests]]
name = "source_max_downstream_dependencies"
type = "max_downstream_dependencies"
max_downstream = 1
description = "Sources should not be referenced by more than 1 model (use a staging model)"
applies_to = ["sources"]Example child_map
The rule inspects the child_map from manifest.json. For example:
"child_map": {
"model.project.stg_customers": [
"model.project.orders",
"model.project.customers",
"model.project.marketing_report",
"test.project.not_null_stg_customers_id"
]
}With max_downstream: 5 and exclude_types: ["tests"], the stg_customers model is referenced by 3 other models (the test is excluded from the count), so it would pass.