allowed_subfolders
Rule: allowed_subfolders
allowed_subfolders details
This rule enforces that dbt objects are organized within specific allowed subfolders of a given path. This helps maintain a consistent project structure and ensures models are properly categorized (e.g., by data source or domain).
Configuration
- type: Must be
allowed_subfolders. - allowed_subfolders: (required) List of subfolder names that are allowed within the specified path.
- Both the
path_prefixandpath_postfixcan be used to create this path{path_prefix}/{resource_type}/{path_postfix}/.- path_prefix: (optional) Path segment that appears before the resource type (e.g.,
dbtfor paths likedbt/models/...). - path_postfix: (optional) Path segment that appears after the resource type (e.g.,
bronzefor paths likemodels/bronze/...).
- path_prefix: (optional) Path segment that appears before the resource type (e.g.,
- applies_to: (optional) List of dbt object types to include.
- Default:
["models"] - Options:
models,seeds,snapshots,analyses,metrics,hook_nodes,sql_operations,saved_queries,sources,unit_tests,macros,exposures,semantic_models
- 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.
- includes: List of patterns to explicitly include for this rule.
Paths are relative to theoriginal_file_pathfrom the manifest.
Pattern syntax:*matches any characters except/(within a single directory)**matches any characters including/(across directories)^at the start anchors to the beginning of the path$at the end anchors to the end of the path- Without anchors, pattern matches if it appears anywhere in the path (contains)
Examples:^models/staging/- paths starting withmodels/staging/orders- paths containingordersanywhere.sql$- paths ending with.sql^models/*.sql$- SQL files directly inmodels/folder^models/**/*.sql$- SQL files in any subfolder ofmodels/
- excludes: List of patterns to explicitly exclude from this rule.
Uses the same pattern syntax asincludes.
Examples:^models/legacy/- exclude legacy models folder_deprecated- exclude paths containing_deprecated^tests/- exclude test files - 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: "medallion_structure"
type: "allowed_subfolders"
description: "Models must follow medallion architecture (bronze/silver/gold)."
allowed_subfolders:
- "bronze"
- "silver"
- "gold"
- name: "bronze_models_by_source"
type: "allowed_subfolders"
description: "Bronze models must be organized by source system."
path_postfix: "bronze"
allowed_subfolders:
- "salesforce"
- "postgres"
- "snowflake"[[manifest_tests]]
name = "medallion_structure"
type = "allowed_subfolders"
description = "Models must follow medallion architecture (bronze/silver/gold)."
applies_to = ["models"]
allowed_subfolders = ["bronze", "silver", "gold"]
[[manifest_tests]]
name = "bronze_models_by_source"
type = "allowed_subfolders"
description = "Bronze models must be organized by source system."
applies_to = ["models"]
path_postfix = "bronze"
allowed_subfolders = ["salesforce", "postgres", "snowflake"][[tool.dbtective.manifest_tests]]
name = "medallion_structure"
type = "allowed_subfolders"
description = "Models must follow medallion architecture (bronze/silver/gold)."
applies_to = ["models"]
allowed_subfolders = ["bronze", "silver", "gold"]
[[tool.dbtective.manifest_tests]]
name = "bronze_models_by_source"
type = "allowed_subfolders"
description = "Bronze models must be organized by source system."
applies_to = ["models"]
path_postfix = "bronze"
allowed_subfolders = ["salesforce", "postgres", "snowflake"]Relevant dbt structure
The following example shows the expected folder structure enforced by the two rules above:
- The
medallion_structurerule ensures that models are organized intobronze,silver, andgoldfolders. - The
bronze_models_by_sourcerule ensures that within thebronzefolder, models are further organized by source system (e.g.,salesforce,postgres,snowflake).
This results in the following structure: ✓ = compliant, ✗ = non-compliant
- stg_accounts.sql ✓
- stg_users.sql ✓
- stg_data.sql ✗ violates rule 2 (non-allowed subfolder)
- stg_orders.sql ✗ violates rule 2 (root)
- dim_customers.sql ✓