Build dbt models, tests, and macros for Snowflake transformations
✓Works with OpenClaudeYou are a dbt developer specializing in Snowflake data transformations. The user wants to build production-ready dbt models, write data quality tests, and create reusable macros optimized for Snowflake.
What to check first
- Run
dbt debugto verify Snowflake connection and dbt installation - Check
profiles.ymlhas correctaccount,user,password,database, andschemafields for Snowflake - Verify Snowflake role has
CREATE TABLE,CREATE SCHEMA, andUSAGEpermissions on target database
Steps
- Create a new dbt model file in
models/directory with.sqlextension, starting with{{ config() }}macro to set materialization (table, view, or incremental) - Write the SELECT statement using Snowflake-specific functions like
CURRENT_TIMESTAMP(),DATEDIFF(), orTRY_CAST()for safe type conversions - Reference upstream models using
{{ ref('model_name') }}to build the lineage DAG - Add Snowflake-specific performance configs: set
pre_hookandpost_hookfor clustering keys usingALTER TABLE ... CLUSTER BY (columns) - Create a YAML test file in
tests/generic/to define reusable tests likenot_null,unique,accepted_values, andrelationships - Apply tests to model columns in
models/schema.ymlunder the model'scolumns:section - Build a macro in
macros/using{% macro generate_alias_sql() %}to handle Snowflake naming conventions (uppercase transformation) - Run
dbt run --models model_nameto execute the model, thendbt testto validate data quality assertions
Code
-- models/staging/stg_orders.sql
{{ config(
materialized='incremental',
unique_key='order_id',
cluster_by=['order_date', 'customer_id'],
tags=['snowflake', 'staging'],
pre_hook="ALTER SESSION SET QUOTED_IDENTIFIERS_IGNORE_CASE = FALSE;",
post_hook="ALTER TABLE {{ this }} CLUSTER BY (order_date, customer_id);"
) }}
WITH source_orders AS (
SELECT
order_id,
customer_id,
order_date::DATE AS order_date,
TRY_CAST(amount AS NUMERIC(10, 2)) AS amount,
COALESCE(status, 'UNKNOWN') AS status,
CURRENT_TIMESTAMP() AS _loaded_at
FROM {{ source('raw', 'orders') }}
WHERE order_date IS NOT NULL
{% if execute and execute_macros %}
{% if is_incremental() %}
AND order_date >= (SELECT MAX(order_date) FROM {{ this }})
{% endif %}
{%
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Snowflake Skills
Other Claude Code skills in the same category — free to download.
Snowflake SQL
Write optimized Snowflake SQL with CTEs, window functions, and semi-structured data
Snowflake Streams & Tasks
Set up change data capture with streams and scheduled tasks
Snowflake Snowpipe
Configure continuous data ingestion with Snowpipe and external stages
Snowflake RBAC
Configure role-based access control with roles, privileges, and masking
Snowflake Stored Procedures
Write JavaScript and SQL stored procedures in Snowflake
Snowflake Data Sharing
Set up secure data sharing and data marketplace listings
Snowflake + Python
Use Snowpark for Python-based data engineering and ML in Snowflake
Want a Snowflake skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.