Proactive skill for validating dbt models against coding conventions. Auto-activates when creating, reviewing, or refactoring dbt models in staging, integration, or warehouse layers...
This skill automatically activates when working with dbt models to ensure adherence to coding conventions and best practices. It provides validation and recommendations for model structure, naming, SQL style, testing, and documentation.
This skill should activate when users:
Keywords to watch for:
Activate BEFORE creating or modifying dbt SQL when:
Example internal triggers:
Priority Order (2-tier system):
Project-specific conventions (highest priority)
.dbt-conventions.md in project rootdbt_coding_conventions.md in project rootdocs/dbt_conventions.md in projectPKM user conventions (fallback)
/Users/olivierdupois/dev/PKM/4. š ļø Craft/Tools/dbt/dbt-conventions.md/Users/olivierdupois/dev/PKM/4. š ļø Craft/Tools/dbt/dbt-testing.mdNote: The skill's supporting files (conventions-reference.md, testing-reference.md, examples/) are embedded reference documentation that guide validation logic, not convention sources.
Detection:
Glob to search for convention files in project rootRead to load project conventionsWhen working with a dbt model, determine:
Model Type:
stg_): First transformation layer, selects from sourcesint_): Combines multiple sources, enriches entitiesint__<object>__<action>): Subcomponent of integration_dim): Mutable, noun-based entities_fct): Immutable, verb-based eventsContext Information:
How to identify:
ref() and source() callsCheck the following:
File and Model Naming:
user not users)stg_<source>__<object>.sql (e.g., stg_salesforce__user.sql)int__<object>.sql (e.g., int__user.sql)int__<object>__<action>.sql (e.g., int__user__unioned.sql)<object>_dim.sql or <warehouse>_<object>_dim.sqluser_dim.sql)finance_revenue_dim.sql)<object>_fct.sql or <warehouse>_<object>_fct.sqlDirectory Structure:
models/
āāā staging/
ā āāā <source_name>/
ā āāā stg_<source>.yml
ā āāā stg_<source>__<object>.sql
āāā integration/
ā āāā intermediate/
ā ā āāā intermediate.yml
ā ā āāā int__<object>__<action>.sql
ā āāā int__<object>.sql
ā āāā integration.yml
āāā warehouse/
āāā <warehouse_name>/
āāā <warehouse>.yml
āāā <object>_dim.sql
āāā <object>_fct.sql
Violations to Flag:
Required Structure:
with
s_source_table as (
select * from {{ ref('source_model') }}
),
s_another_source as (
select * from {{ ref('another_model') }}
),
CTE Naming:
s_ for CTEs that select from refs/sourcesfiltered_events, aggregated_metrics)Final CTE Pattern:
final as (
select
-- fields here
from s_source_table
-- joins and where clauses
)
select * from final
{{
config(
materialized = 'table',
sort = 'id',
dist = 'id'
)
}}
Style Requirements:
as keyword for aliasesunion all to union distinctinner join, left join, never just join)customer, not c)Violations to Flag:
ref() or source() calls outside of top CTEsField Naming Conventions:
Primary Keys:
<object>_pk (e.g., user_pk, transaction_pk)dbt_utils.surrogate_key()Foreign Keys:
<referenced_object>_fk (e.g., user_fk, transaction_fk)dbt_utils.surrogate_key()Natural Keys:
<descriptive_name>_natural_keysalesforce_user_natural_key, stripe_customer_natural_keyTimestamps:
<event>_ts (e.g., created_ts, updated_ts, order_placed_ts)created_ts_ct, created_ts_ptBooleans:
is_ or has_ (e.g., is_active, has_subscription)Prices/Revenue:
price_in_centsCommon Fields:
customer_name, carrier_name, not just name)General Rules:
snake_caseField Ordering (Staging/Base Models):
Within each category, sort alphabetically.
Violations to Flag:
Configuration Rules:
Warehouse Models:
tableOther Layers:
view or ephemeral (CTE) materializationtable only if performance requires itConfiguration Placement:
dbt_project.ymlExample:
{{
config(
materialized = 'table',
sort = 'user_pk',
dist = 'user_pk'
)
}}
Violations to Flag:
Minimum Testing Requirements:
Every Model:
schema.yml fileunique and not_null testsdbt_utils.unique_combination_of_columnsSchema.yml Location:
.yml filestg_salesforce.yml, integration.yml)Example:
version: 2
models:
- name: stg_salesforce__user
description: Salesforce user records
columns:
- name: user_pk
description: Unique identifier for user
tests:
- unique
- not_null
- name: email
description: User email address
tests:
- not_null
Additional Tests:
relationships tests for foreign keysaccepted_values for enums/status fieldsnot_null_where for conditional requirementstests/ directory for KPI validationViolations to Flag:
Documentation Requirements:
Staging Models:
Warehouse Models:
Integration/Intermediate:
Doc Blocks:
{% docs %} blocks for shared documentationmodels/docs/ directoryExample:
version: 2
models:
- name: user_dim
description: |
User dimension containing customer profile information.
Updated nightly from Salesforce and Stripe sources.
columns:
- name: user_pk
description: "{{ doc('user_pk') }}"
Violations to Flag:
Check for sqlfluff:
which sqlfluff
If available:
.sqlfluff config in project rootsqlfluff lint <model_file> --dialect <dialect>If not available:
Structure your validation feedback as:
## dbt Model Validation Report
**Model:** `<model_name>.sql`
**Type:** <staging/integration/warehouse-dim/warehouse-fct>
**Convention Source:** <project-specific / RA defaults>
### Summary
- ā X checks passed
- ā ļø Y issues found (N critical, M important, P nice-to-have)
### Naming Conventions
[ā/ā ļø] **File naming:** <details>
[ā/ā ļø] **Field naming:** <details>
### SQL Structure
[ā/ā ļø] **CTE structure:** <details>
[ā/ā ļø] **Style compliance:** <details>
[ā/ā ļø] **Field ordering:** <details>
### Configuration
[ā/ā ļø] **Materialization:** <details>
[ā/ā ļø] **Performance settings:** <details>
### Testing
[ā/ā ļø] **Schema.yml exists:** <details>
[ā/ā ļø] **Primary key tests:** <details>
[ā/ā ļø] **Foreign key tests:** <details>
### Documentation
[ā/ā ļø] **Model description:** <details>
[ā/ā ļø] **Column descriptions:** <details>
### sqlfluff
[ā/ā ļø/N/A] **Linter results:** <details>
---
## Recommendations
### Critical Issues (must fix)
1. <issue description>
- **Location:** <file:line or section>
- **Current:** `<current code>`
- **Should be:** `<correct pattern>`
- **Reason:** <why this matters>
### Important Issues (should fix)
<same format>
### Nice-to-have Improvements
<same format>
---
## Examples
See `skills/dbt-development/examples/` for reference implementations:
- `staging-model-example.sql` - Compliant staging model
- `integration-model-example.sql` - Compliant integration model
- `warehouse-model-example.sql` - Compliant warehouse model
- `schema-example.yml` - Proper testing setup
When creating a new dbt model from scratch:
Step-by-step Process:
Determine Model Type
Generate File Structure
Build SQL Structure
Apply Field Conventions
Create/Update schema.yml
Validate Against Conventions
In This Skill Directory:
conventions-reference.md - Quick reference for naming, style, structuretesting-reference.md - Test requirements and transformation layersexamples/staging-model-example.sql - Staging model templateexamples/integration-model-example.sql - Integration model templateexamples/warehouse-model-example.sql - Warehouse model templateexamples/schema-example.yml - Testing and documentation exampleConvention Sources (2-tier system):
.dbt-conventions.md (if exists in project)/Users/olivierdupois/dev/PKM/4. š ļø Craft/Tools/dbt/dbt-conventions.md and dbt-testing.mdAlways Validate When:
Validation Mode (Not Auto-fix):
Project Awareness:
Priority Levels:
Example 1: Creating a Staging Model
User: "Create a staging model for Hubspot contacts"
Actions:
1. Activate dbt Development skill
2. Load convention source (project or RA defaults)
3. Determine: staging model, Hubspot source, contact object
4. Generate: stg_hubspot__contact.sql with proper structure
5. Create schema.yml entry with tests
6. Validate against all conventions
7. Present model for review
Example 2: Reviewing Existing Model
User: "Review this dbt model" [provides file]
Actions:
1. Activate dbt Development skill
2. Load convention source
3. Identify model type from filename/content
4. Run through validation checklist (naming, structure, fields, tests, docs)
5. Check sqlfluff if available
6. Generate validation report with recommendations
Example 3: Refactoring
User: "This integration model needs refactoring to match conventions"
Actions:
1. Activate dbt Development skill
2. Load conventions
3. Analyze current model structure
4. Identify violations
5. Provide detailed refactoring plan with before/after examples
6. Offer to apply changes section by section with user approval
Do NOT activate this skill when: