Skip to content
cccskills
FreePublished on GitHub

dbt-expert

Writes and reviews dbt projects targeting Snowflake: models, schema.yml metadata, sources, tests, macros, and project structure. Use when building or reviewing dbt models, generating dbt YAML, or applying dbt best practices.

The English summary is being prepared. Showing the original description.

See how to install

Files included (1)

  • SKILL.md8.8 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

dbt Expert

You are working with dbt (data build tool) targeting Snowflake. Apply production-grade patterns at every level — clean SQL, thorough YAML metadata, sensible tests, and a project structure that scales.


Model Materializations

TypeWhen to use
viewLightweight lookups, rarely-queried transformations
tableStable staging/intermediate layers queried often
incrementalLarge fact tables — only process new/changed rows
ephemeralCTEs you want to reuse across models — no physical table
snapshotSlowly changing dimensions (SCD Type 2)
dynamic_tableSnowflake-native: auto-refresh on a lag, no dbt run needed

Configure at the model level (override project defaults):

{{ config(
    materialized='incremental',
    unique_key='event_id',
    incremental_strategy='merge',
    cluster_by=['date_day', 'account_id']
) }}

Incremental Strategies on Snowflake

merge (default) — upsert by unique_key

{{ config(materialized='incremental', unique_key='id', incremental_strategy='merge') }}

select ...
from {{ source('raw', 'events') }}
{% if is_incremental() %}
  where loaded_at > (select max(loaded_at) from {{ this }})
{% endif %}

delete+insert — for partitioned tables without a reliable unique key

{{ config(
    materialized='incremental',
    unique_key=['date_day', 'account_id'],
    incremental_strategy='delete+insert',
    partition_by={'field': 'date_day', 'data_type': 'date'}
) }}

append — event logs, audit tables where duplicates are acceptable

{{ config(materialized='incremental', incremental_strategy='append') }}

insert_overwrite — replace entire partitions (Snowflake dynamic partition pruning)

On schema changes: always add on_schema_change='sync_all_columns' for production incremental models — silently ignoring schema drift causes silent data loss.


Project Structure

dbt_project/
├── dbt_project.yml          # Project config
├── profiles.yml             # Connection config (NOT in git)
├── packages.yml             # dbt-utils, dbt-expectations, etc.
├── models/
│   ├── staging/             # 1:1 with source tables, light casting only
│   │   ├── _sources.yml     # source() definitions + freshness
│   │   ├── _staging.yml     # staging model docs + tests
│   │   └── stg_*.sql
│   ├── intermediate/        # Business logic joins, not exposed
│   │   └── int_*.sql
│   ├── marts/               # Final models consumed by BI/apps
│   │   ├── core/
│   │   └── finance/
│   └── utils/               # Generic macros used across layers
├── macros/
├── seeds/                   # Small reference CSVs
├── snapshots/               # SCD Type 2 models
├── tests/                   # Singular (custom SQL) tests
└── analyses/                # Ad hoc SQL, not materialized

Naming rule: stg_<source>__<entity>, int_<entity>__<verb>, fct_<event>, dim_<entity>


Schema YAML — Complete Structure

# models/staging/_staging.yml
version: 2

models:
  - name: stg_salesforce__accounts
    description: "One row per Salesforce account, cast and renamed."
    config:
      tags: ["salesforce", "staging"]
    columns:
      - name: account_id
        description: "Natural key from Salesforce."
        data_tests:
          - not_null
          - unique
      - name: created_at
        description: "UTC timestamp of account creation."
        data_tests:
          - not_null
      - name: account_type
        data_tests:
          - accepted_values:
              values: ["Customer", "Partner", "Prospect"]
# models/staging/_sources.yml
version: 2

sources:
  - name: salesforce
    database: RAW_DB
    schema: SALESFORCE
    freshness:
      warn_after: {count: 12, period: hour}
      error_after: {count: 24, period: hour}
    loaded_at_field: _loaded_at
    tables:
      - name: account
        identifier: ACCOUNT  # actual table name if different
        description: "Raw Salesforce accounts."
        columns:
          - name: Id
            data_tests:
              - not_null
              - unique

Tests — Layered Strategy

Generic tests (in schema.yml): not_null, unique, accepted_values, relationships

dbt-utils tests (install dbt-utils):

- dbt_utils.expression_is_true:
    expression: "amount >= 0"
- dbt_utils.unique_combination_of_columns:
    combination_of_columns: ["date_day", "account_id", "metric"]
- dbt_utils.not_empty_string:
    column_name: account_name

dbt-expectations for statistical tests:

- dbt_expectations.expect_column_values_to_be_between:
    min_value: 0
    max_value: 1

Singular tests (tests/ folder) — custom SQL that returns rows on failure:

-- tests/assert_fct_orders_amount_positive.sql
select order_id
from {{ ref('fct_orders') }}
where amount < 0

Macros

Date spine:

-- macros/generate_date_spine.sql
{% macro generate_date_spine(start_date, end_date) %}
  {{ dbt_utils.date_spine(
      datepart="day",
      start_date="cast('" ~ start_date ~ "' as date)",
      end_date="cast('" ~ end_date ~ "' as date)"
  ) }}
{% endmacro %}

Surrogate key:

select
  {{ dbt_utils.generate_surrogate_key(['account_id', 'date_day']) }} as sk_account_day,
  ...

Safe divide:

{% macro safe_divide(numerator, denominator) %}
  iff({{ denominator }} = 0, null, {{ numerator }} / {{ denominator }})
{% endmacro %}

Snapshots (SCD Type 2)

-- snapshots/snp_accounts.sql
{% snapshot snp_accounts %}
  {{
    config(
      target_schema='SNAPSHOTS',
      unique_key='account_id',
      strategy='timestamp',
      updated_at='updated_at',
      invalidate_hard_deletes=True
    )
  }}
  select * from {{ source('crm', 'accounts') }}
{% endsnapshot %}

Snowflake-specific dbt Patterns

Clustering keys (for large tables queried by date range):

{{ config(cluster_by=["date_day", "account_id"]) }}

Dynamic tables (Snowflake-native, set materialized='dynamic_table'):

{{ config(
    materialized='dynamic_table',
    snowflake_warehouse='TRANSFORM_WH',
    target_lag='5 minutes'
) }}

Warehouse override for expensive models:

{{ config(snowflake_warehouse='LARGE_WH') }}

Copy grants so downstream roles keep access after table rebuild:

{{ config(materialized='table', copy_grants=True) }}

Stage-based seed loading for large reference files (avoid in-YAML seed if >10k rows):

-- Use a model that reads from a named Snowflake stage instead of dbt seed
select $1::varchar as code, $2::varchar as label
from @RAW_DB.PUBLIC.REFERENCE_STAGE/lookup.csv
(file_format => 'CSV_FORMAT')

dbt_project.yml Key Config

name: 'my_project'
version: '1.0.0'
config-version: 2

profile: 'snowflake_prod'

model-paths: ["models"]
test-paths: ["tests"]
snapshot-paths: ["snapshots"]
seed-paths: ["seeds"]
macro-paths: ["macros"]

target-path: "target"
clean-targets: ["target", "dbt_packages"]

models:
  my_project:
    staging:
      +materialized: view
      +schema: STAGING
    intermediate:
      +materialized: ephemeral
    marts:
      +materialized: table
      +schema: MARTS
      core:
        +tags: ["core", "daily"]

vars:
  start_date: "2020-01-01"

Generating dbt Projects Programmatically

When generating dbt YAML files from code (e.g., from ETL metadata), follow these rules:

  • sources.yml: one file per source system, in models/staging/
  • schema.yml: one file per subfolder (staging, marts, etc.), named _<layer>.yml
  • Always include version: 2 at the top of every YAML file
  • Columns referenced in data_tests must match the SQL output column names exactly
  • identifier field in sources is only needed when the dbt model name differs from the actual table name
  • Freshness config only belongs on sources, not models
  • ref() creates lineage — always use it instead of hardcoding table names
  • source() for raw tables — never ref() a staging model that wraps a source

Quick Diagnostics

dbt debug                          # Test connection
dbt compile --select my_model      # See rendered SQL without running
dbt run --select +my_model         # Run model + all ancestors
dbt test --select my_model         # Run tests for one model
dbt docs generate && dbt docs serve  # Browse lineage DAG
dbt source freshness               # Check source staleness
dbt list --select tag:daily        # Find all models tagged daily

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Use when long-lived agents, project memories, system prompts, or playbooks are repeatedly summarized, rewritten, or optimized and risk losing domain detail, provenance, or execution learnings.

The English summary is being prepared. Showing the original description.

mouadja02/skills10Updated Oct 21, 2026

Use this skill when the user explicitly asks to map, document, or onboard into an existing codebase. Trigger for prompts like "map this codebase", "document this architecture", "onboard me to this repo", or "create codebase docs". Do not trigger for routine feature implementation, bug fixes, or narrow code edits unless the user asks for repository-level discovery.

The English summary is being prepared. Showing the original description.

mouadja02/skills10Updated Oct 21, 2026

Adds educational comments to a code file so it becomes a learning resource, asking for the file (with a list of close matches) if none is given. Use when preparing code for learners, onboarding, or teaching.

The English summary is being prepared. Showing the original description.

mouadja02/skills10Updated Oct 21, 2026

Write, debug, and optimize Adobe Illustrator automation scripts using ExtendScript (JavaScript/JSX). Use when creating or modifying scripts that manipulate documents, layers, paths, text frames, colors, symbols, artboards, or any Illustrator DOM objects. Covers the complete JavaScript object model, coordinate system, measurement units, export workflows, and scripting best practices.

The English summary is being prepared. Showing the original description.

mouadja02/skills10Updated Oct 21, 2026

Patterns and techniques for adding governance, safety, and trust controls to AI agent systems. Use this skill when: - Building AI agents that call external tools (APIs, databases, file systems) - Implementing policy-based access controls for agent tool usage - Adding semantic intent classification to detect dangerous prompts - Creating trust scoring systems for multi-agent workflows - Building audit trails for agent actions and decisions - Enforcing rate limits, content filters, or tool restrictions on agents - Working with any agent framework (PydanticAI, CrewAI, OpenAI Agents, LangChain, AutoGen)

The English summary is being prepared. Showing the original description.

mouadja02/skills10Updated Oct 21, 2026

Check any AI agent codebase against the OWASP Agentic Security Initiative (ASI) Top 10 risks. Use this skill when: - Evaluating an agent system's security posture before production deployment - Running a compliance check against OWASP ASI 2026 standards - Mapping existing security controls to the 10 agentic risks - Generating a compliance report for security review or audit - Comparing agent framework security features against the standard - Any request like "is my agent OWASP compliant?", "check ASI compliance", or "agentic security audit"

The English summary is being prepared. Showing the original description.

mouadja02/skills10Updated Oct 21, 2026

See all skills by mouadja02

Report a problem with this skill