Skip to content
Latchkey

sqlfluff dbt templater error in CI

sqlfluff was configured with templater = dbt but could not render the models: the sqlfluff-templater-dbt plugin is missing, dbt packages were not installed, or the profile/connection is unavailable in CI.

What this error means

A sqlfluff lint step with the dbt templater fails to compile models, reporting a missing dbt templater plugin, a profile error, or an unresolved ref.

sqlfluff
User Error: Failed to import dbt templater. Please ensure sqlfluff-templater-dbt
is installed. ModuleNotFoundError: No module named 'dbt'

Common causes

The dbt templater plugin is not installed

templater = dbt requires the separate sqlfluff-templater-dbt package plus a dbt adapter; without them sqlfluff cannot render models.

dbt deps or the profile are missing in CI

The templater compiles via dbt, so it needs dbt deps run and a valid profiles.yml/connection, which may be absent in the lint job.

How to fix it

Install the templater and prepare dbt

  1. Install sqlfluff-templater-dbt and your dbt adapter.
  2. Run dbt deps so package macros resolve.
  3. Provide a profiles.yml (credentials from secrets) so compilation succeeds.
.github/workflows/ci.yml
python -m pip install sqlfluff sqlfluff-templater-dbt dbt-postgres
dbt deps
sqlfluff lint models/ --dialect postgres

Use the jinja templater to avoid a live connection

If you do not want dbt compilation in the lint job, use templater = jinja with a static context so no warehouse connection is needed.

.sqlfluff
[sqlfluff]
templater = jinja
dialect = postgres

How to prevent it

  • Install sqlfluff-templater-dbt and the adapter together.
  • Run dbt deps before linting with the dbt templater.
  • Prefer the jinja templater when a live warehouse is not available in CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →