---
title: "dbt models with too many CTEs | Metacenta"
description: "A dbt model with a long chain of CTEs is hard to test in pieces. Where our threshold sits, how we count, and when one long model is the right shape."
url: "https://metacenta.com/rules/high-cte-count"
updated: "2026-10-14"
tokens: 504
---

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`.

[Ask about a review](https://metacenta.com/enquire?src=rule-high-cte-count&via=md)

## Related pages

- [Duplicate logic across dbt models](https://metacenta.com/rules/duplicate-model-logic)
- [select * in dbt models](https://metacenta.com/rules/select-star)
- [dbt layer naming: inconsistent model prefixes](https://metacenta.com/rules/layer-naming-mismatch)
- [dbt tests declared away from their models](https://metacenta.com/rules/test-not-beside-model)
- [A sample review, as a client reads it](https://metacenta.com/sample)
- [All published rules](https://metacenta.com/rules)
- [How a review is assessed](https://metacenta.com/standard)
