sources.yml file allows you to centralize table references, enabling cleaner code, testing, and documentation.
What is sources.yml?
Thesources.yml file is where you define the external data tables that your dbt models will transform. This file centralizes information about your raw data sources, making it easier to:
- Reference raw tables consistently throughout your project
- Test source data for quality and freshness
- Document your data pipeline from beginning to end
- Create clear lineage visualization in dbt docs
Basic Structure
A basicsources.yml file follows this structure:
jaffle_shop with two tables: orders and customers.
Required and Optional Fields
Detailed Source Configuration
Here’s a more complete example with additional configurations:Referencing Sources in Models
Once defined, you can reference sources in your models using thesource() function:
source() function takes two arguments:
- The source name (defined as
nameinsources.yml) - The table name (defined under
tablesinsources.yml)
Testing Sources
You can apply tests to your source tables just like you would with models:Source Freshness
One of the most powerful features of sources is the ability to check data freshness - ensuring your source data is up-to-date.Configuring Freshness Checks
To set up freshness checks, you need:- A column in your source table that indicates when a record was last updated (
loaded_at_field) - Freshness threshold configurations
Valid Time Periods for Freshness ChecksWhen configuring source freshness thresholds, you must specify both a count and a time period. The time period can be:
minute- For data that updates very frequently (e.g., real-time systems)hour- For data that updates throughout the day (e.g., transaction systems)day- For data that updates daily or less frequently (e.g., batch uploads)
warn_after: {count: 6, period: hour} would warn if data is more than 6 hours old.Running Freshness Checks
Execute freshness checks with:Advanced Source Configurations
Dynamic Schema Resolution
You can use Jinja in your source definitions to handle environments:Quoting Configuration
Control identifier quoting:External Tables
For data sources like S3 or GCS:Best Practices for Source Configuration
Organizing source.yml Files
There are several approaches to organizing your source definitions:Single File Approach
Good for smaller projects:Source-by-Source Approach
Better for larger projects:Alongside Related Models
Place source definitions with the models that use them:Automating Source Generation with DinoAIWith DinoAI (Paradime’s AI Agent), you can automatically generate source definitions with appropriate freshness configurations. See step by step instructions for more details.