What Are Tags?
Tags are simple text labels you can assign to models, sources, snapshots, and other dbt resources. They help you organize, categorize, and select specific subsets of your project for execution or documentation. By leveraging tags, you can:- Group models logically – Categorize models based on refresh schedule, function, or ownership
- Control execution – Run or exclude specific sets of models
- Optimize CI/CD pipelines – Target models for incremental builds and tests
- Improve project maintainability – Standardize workflows across teams
How to Apply Tags
Tags can be applied in two primary ways: directly in model files or in your project configuration file.1. Defining Tags in a Model File
Tags can be assigned directly within SQL models using theconfig() function:
2. Defining Tags in dbt_project.yml
Tags can also be applied at the project level, affecting entire folders or groups of models:
Tag Inheritance
Models inside a folder inherit the parent folder’s tags unless overridden. This creates a hierarchical tagging system that is easy to maintain. Example:Applying Tags to Different Resource Types
Tags can be applied to various dbt resource types:Snapshots
Seeds
Sources
Using Tags for Selection
Once tags are defined, you can use them with dbt commands to select specific resources.Selection Examples
Tag Selection Patterns
Best Practices for Using Tags
Use Consistent Naming Conventions
Standardized naming improves clarity and prevents confusion.Document Your Tagging Strategy
Clearly define tag meanings in your project’s documentation.Use Granular Tags
Avoid broad, generic tags. Instead, use precise labels for better control.Tag Models by Layer
Use tags to represent data modeling layers in your project.Common Use Cases for Tags
Refresh Scheduling
Define tags based on refresh frequency for better execution control:Data Classification
Differentiate datasets based on sensitivity or access level:Testing Strategy
Prioritize critical models in testing workflows:Troubleshooting Tag Issues
If dbt isn’t selecting resources correctly based on tags, consider these troubleshooting steps:Tag Inheritance Issues
Verify parent folder configurations indbt_project.yml:
Selection Syntax Errors
Ensure tag names match exactly (case-sensitive):Using dbt ls to Validate Tags
Use thedbt ls command to check which models have specific tags: