$npx -y skills add AltimateAI/data-engineering-skills --skill creating-dbt-modelsCreates dbt models following project conventions. Use when working with dbt models for: (1) Creating new models (any layer - discovers project's naming conventions first) (2) Task mentions "create", "build", "add", "write", "new", or "implement" with model, table, or SQL (3) Modi
| 1 | # dbt Model Development |
| 2 | |
| 3 | **Read before you write. Build after you write. Verify your output.** |
| 4 | |
| 5 | ## Critical Rules |
| 6 | |
| 7 | 1. **ALWAYS run `dbt build`** after creating/modifying models - compile is NOT enough |
| 8 | 2. **ALWAYS verify output** after build using `dbt show` - don't assume success |
| 9 | 3. **If build fails 3+ times**, stop and reassess your entire approach |
| 10 | |
| 11 | ## Workflow |
| 12 | |
| 13 | ### 1. Understand the Task Requirements |
| 14 | |
| 15 | - What columns are needed? List them explicitly. |
| 16 | - What is the grain of the table (one row per what)? |
| 17 | - What calculations or aggregations are required? |
| 18 | |
| 19 | ### 2. Discover Project Conventions |
| 20 | |
| 21 | ```bash |
| 22 | cat dbt_project.yml |
| 23 | find models/ -name "*.sql" | head -20 |
| 24 | ``` |
| 25 | |
| 26 | Read 2-3 existing models to learn naming, config, and SQL patterns. |
| 27 | |
| 28 | ### 3. Find Similar Models |
| 29 | |
| 30 | ```bash |
| 31 | # Find models with similar purpose |
| 32 | find models/ -name "*agg*.sql" -o -name "*fct_*.sql" | head -5 |
| 33 | ``` |
| 34 | |
| 35 | Learn from existing models: join types, aggregation patterns, NULL handling. |
| 36 | |
| 37 | ### 4. Check Upstream Data |
| 38 | |
| 39 | ```bash |
| 40 | # Preview upstream data if needed |
| 41 | dbt show --select <upstream_model> --limit 10 |
| 42 | ``` |
| 43 | |
| 44 | ### 5. Write the Model |
| 45 | |
| 46 | Follow discovered conventions. Match the required columns exactly. |
| 47 | |
| 48 | ### 6. Compile (Syntax Check) |
| 49 | |
| 50 | ```bash |
| 51 | dbt compile --select <model_name> |
| 52 | ``` |
| 53 | |
| 54 | ### 7. BUILD - MANDATORY |
| 55 | |
| 56 | **This step is REQUIRED. Do NOT skip it.** |
| 57 | |
| 58 | ```bash |
| 59 | dbt build --select <model_name> |
| 60 | ``` |
| 61 | |
| 62 | If build fails: |
| 63 | 1. Read the error carefully |
| 64 | 2. Fix the specific issue |
| 65 | 3. Run build again |
| 66 | 4. **If fails 3+ times, step back and reassess approach** |
| 67 | |
| 68 | ### 8. Verify Output (CRITICAL) |
| 69 | |
| 70 | **Build success does NOT mean correct output.** |
| 71 | |
| 72 | ```bash |
| 73 | # Check the table was created and preview data |
| 74 | dbt show --select <model_name> --limit 10 |
| 75 | ``` |
| 76 | |
| 77 | Verify: |
| 78 | - Column names match requirements exactly |
| 79 | - Row count is reasonable |
| 80 | - Data values look correct |
| 81 | - No unexpected NULLs |
| 82 | |
| 83 | ### 9. Verify Calculations Against Sample Data |
| 84 | |
| 85 | **For models with calculations, verify correctness manually:** |
| 86 | |
| 87 | ```bash |
| 88 | # Pick a specific row and verify calculation by hand |
| 89 | dbt show --inline " |
| 90 | select * |
| 91 | from {{ ref('model_name') }} |
| 92 | where <primary_key> = '<known_value>' |
| 93 | " --limit 1 |
| 94 | |
| 95 | # Cross-check aggregations |
| 96 | dbt show --inline " |
| 97 | select count(*), sum(<column>) |
| 98 | from {{ ref('model_name') }} |
| 99 | " |
| 100 | ``` |
| 101 | |
| 102 | For example, if calculating `total_revenue = quantity * price`: |
| 103 | 1. Pick one row from output |
| 104 | 2. Look up the source quantity and price |
| 105 | 3. Manually calculate: does it match? |
| 106 | |
| 107 | ### 10. Re-review Against Requirements |
| 108 | |
| 109 | **Before declaring done, re-read the original request:** |
| 110 | - Did you implement what was asked, not what you assumed? |
| 111 | - Are column names exactly as specified? |
| 112 | - Is the calculation logic correct per the requirements? |
| 113 | - Does the grain (one row per what?) match what was requested? |
| 114 | |
| 115 | ## Anti-Patterns |
| 116 | |
| 117 | - Declaring done after compile without running build |
| 118 | - Not verifying output data after build |
| 119 | - Getting stuck in compile/build error loops |
| 120 | - Assuming table exists just because model file exists |
| 121 | - Writing SQL without checking existing model patterns first |