has_refs

Rule: has_refs

Manifest Rule

has_refs details
This rule ensures that dbt objects have at least one upstream reference. An upstream reference is created using ref() or source() in your dbt model. This rule checks the dependency graph (depends_on.nodes) in the manifest.

This may indicate that you’re using hardcoded SQL to reference data directly from the warehouse instead of leveraging dbt’s dependency management. Or that an object is simply not being used.

Also check out code_contains_refs, which inspects the raw SQL text directly for ref() / source(). It differs since has_refs also checks the depends_on config.


Configuration

  • type: Must be has_refs.
  • applies_to: (optional) List of dbt object types to include.
    • Default: ["models", "snapshots", "analyses"]
    • Options: models, seeds, snapshots , analyses, semantics_models
Common Rule Config
  • name: Human-readable name of the rule.
  • severity: "error" (fail) or "warning" (warn only).
    • (optional, defaults to "error" if not specified)
  • 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_to includes models.
    • (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: "references_must_exist"
    type: "has_refs"
    description: "All dbt objects must reference at least one source or model."
    # severity: "warning"  (optional)
    # applies_to: ['models', 'seeds']  (optional)
    # includes: ["models/staging/*"]
    # excludes: ["models/base/*"]
[[manifest_tests]]
name = "references_must_exist"
type = "has_refs"
description = "All dbt objects must reference at least one source or model."
# severity = "warning"  # (optional)
# applies_to = ["models", "seeds"]  # (optional)
# includes = ["models/staging/*"]
# excludes = ["models/base/*"]
[[tool.dbtective.manifest_tests]]
name = "references_must_exist"
type = "has_refs"
description = "All dbt objects must reference at least one source or model."
# severity = "warning"  # (optional)
# applies_to = ["models", "seeds"]  # (optional)
# includes = ["models/staging/*"]
# excludes = ["models/base/*"]
Relevant dbt code
-- Valid model with references
select
    customer_id,
    first_name,
    last_name
from {{ source('raw', 'customers') }}
-- Valid model referencing another model
select
    customer_id,
    order_count
from {{ ref('stg_customers') }}