Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add skills/altimateai/data-engineering-skills/refactoring-dbt-modelsnpx skills add AltimateAI/data-engineering-skills --skill refactoring-dbt-modelsgit clone --depth 1 https://github.com/AltimateAI/data-engineering-skillsWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/altimateai/data-engineering-skills/refactoring-dbt-models)<a href="https://agentmods.dev/skills/altimateai/data-engineering-skills/refactoring-dbt-models"><img src="https://agentmods.dev/badge/skills/altimateai/data-engineering-skills/refactoring-dbt-models.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00108 | $0.01127 |
| Opus 5 | $0.00054 | $0.00563 |
| Sonnet 5 | $0.00022 | $0.00225 |
| Haiku 4.5 | $0.00011 | $0.00113 |
Grade A, and why
refactoring-dbt-models scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 187 lines — stays where its author put it; the contents beside it link to each section on GitHub.
dbt Refactoring
Find ALL downstream dependencies before changing. Refactor in small steps. Verify output after each change.
Workflow
1. Analyze Current Model
cat models/<path>/<model_name>.sql
Identify refactoring opportunities:
- CTEs longer than 50 lines → extract to intermediate model
- Logic repeated across models → extract to macro
- Multiple joins in sequence → split into steps
- Complex WHERE clauses → extract to staging filter
2. Find All Downstream Dependencies
CRITICAL: Never refactor without knowing impact.
# Get full dependency tree (model and all its children)
dbt ls --select model_name+ --output list
# Find all models referencing this one
grep -r "ref('model_name')" models/ --include="*.sql"
Report to user: "Found X downstream models: [list]. These will be affected by changes."
3. Check What Columns Downstream Models Use
BEFORE changing any columns, check what downstream models reference:
# For each downstream model, check what columns it uses
cat models/<path>/<downstream_model>.sql | grep -E "model_name\.\w+|alias\.\w+"
If downstream models reference specific columns, you MUST ensure those columns remain available after refactoring.
4. Plan Refactoring Strategy
| Opportunity | Strategy |
|---|---|
| Long CTE | Extract to intermediate model |
| Repeated logic | Create macro in macros/ |
| Complex join | Split into intermediate models |
| Multiple concerns | Separate into focused models |
5. Execute Refactoring
Pattern: Extract CTE to Model
Before:
-- orders.sql (200 lines)
with customer_metrics as (
-- 50 lines of complex logic
),
order_enriched as (
select ...
from orders
join customer_metrics on ...
)
select * from order_enriched
After:
-- customer_metrics.sql (new file)
select
customer_id,
-- complex logic here
from {{ ref('customers') }}
-- orders.sql (simplified)
with order_enriched as (
select ...
from {{ ref('raw_orders') }} orders
join {{ ref('customer_metrics') }} cm on ...
)
select * from order_enriched
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 6d ago First seen · 187 lines · 108 tokens per session scan A 738c129ceb49
refactoring-dbt-models is a skill published in the GitHub repository AltimateAI/data-engineering-skills (122 stars, last pushed 1mo ago), licensed MIT. It adds 108 tokens to every session and 1,127 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other skills, from other repositories
datahub-verified-remediation
Use this skill when a source schema change has broken, or is about to break, a downstream transformation and the user wants a fix they can merge — not a summary. Triggers on: "a column was renamed, fix the dbt model", "this field is gone downstream", "schema drift", "our model still selects the old column", "generate…
spark-engineer
Use when writing Spark jobs, debugging performance issues, or configuring cluster settings for Apache Spark applications, distributed data processing pipelines, or big data workloads. Invoke to write DataFrame transformations, optimize Spark SQL queries, implement RDD pipelines, tune shuffle operations, configure…
rudder-profiles-debug
Diagnoses RudderStack Profiles compile failures, run failures, and output-quality problems. Use when pb compile fails, pb run fails, identity stitching looks wrong, output quality regresses, or Profiles errors need structured recovery.
fabric-dataflows-perf-remediation
Diagnose and resolve Microsoft Fabric Dataflow Gen2 performance issues including slow refresh times, Fast Copy optimization, query folding failures, staging bottlenecks, gateway latency, incremental refresh tuning, capacity throttling, and data destination write performance. Use when troubleshooting dataflow refresh…
fabric-spark-compute-perf-remediate
Diagnose and resolve performance issues in Microsoft Fabric Delta Lake and Spark workloads. Use when remediate slow Spark notebooks, long-running Spark jobs, Delta table query degradation, small file problems, VOrder configuration, resource profile tuning, autotune configuration, capacity throttling (HTTP 430)…
fabric-data-agent-remediate
Diagnose and resolve Microsoft Fabric Data Agent issues including tenant settings, data source configuration, query generation failures, cross-region capacity errors, XMLA endpoint setup, Power BI semantic model integration, lakehouse/warehouse/KQL connectivity, example query validation, publishing/sharing problems…