Maintainability · rule high-cte-count
dbt models with too many CTEs
A Metacenta review checks this under the rule Model bodies stay readable. Everything below applies whether or not you ever commission one.
What this rule checks
This rule flags dbt models with more than eight CTEs; a model with eight passes. We count CTE definitions in the model's SQL, including any inside nested with clauses. Jinja loops are not expanded, so the count is approximate.
Why it matters
Logic this dense is hard to test in pieces and tends to hide the transformation that matters. A wrong step deep in the chain is hard to find and harder to test on its own.
How to fix it
Split the densest models into intermediate models. Split the intermediate steps into their own models, usually in an intermediate/ layer. Start with the steps other models could reuse, and the ones you would most want to test.
When it is fine to leave
A model built from many short import CTEs, one per upstream model, may exceed the threshold while staying easy to read. Splitting that into models adds nodes without adding clarity. Leave it, and say why in the description.
What we need to check it
manifest.json with each model's raw_code. We tokenise the SQL rather than parse it, so the finding is medium confidence. We decline when no model carries raw_code.