Skip to main content

dbt Integration

Import a dbt project into Wren AI to query dbt models through the Wren semantic layer.

What Wren Imports

dbt already contains the context an agent needs to query modeled data safely: model and column descriptions, refs, source definitions, test metadata, compiled SQL, adapter profile settings, and the physical column list in catalog.json. Wren imports that context so agents do not have to infer model purpose, join paths, or trusted constraints from table and column names alone.

Wren stores imported dbt context in regular Wren project files:

dbt inputWren outputWhy it matters
Active dbt targetWren connection profileReuses the same warehouse connection target dbt uses
Model and source nodesmodels/*/metadata.ymlPreserves model names, table references, descriptions, layers, and columns
relationships testsrelationships.ymlTurns tested dbt refs into explicit Wren join paths
not_null, unique, accepted_values testsModel and column metadataGives agents verified constraints and useful filter values
Test resultsinstructions.mdSurfaces verified constraints and warnings for agent workflows
Model graph and metadataqueries.ymlSeeds memory with dbt-aware example questions and SQL

The generated wren_project.yml also keeps a dbt binding:

dbt:
project_dir: ../your-dbt-project
profile: your_dbt_profile
target: dev

project_dir points back to the imported dbt project, while profile and target record the dbt profile target used for the import. This makes the Wren project traceable to its dbt source and gives future tooling enough context to refresh or inspect the original dbt artifacts.

The dbt binding stores only project metadata. Credentials stay in Wren profiles and any environment variables referenced by those profiles.

Prerequisites

  • A dbt project with dbt_project.yml
  • A dbt profile in ~/.dbt/profiles.yml, or a custom profiles.yml
  • Generated dbt artifacts:
cd your-dbt-project
dbt build
dbt docs generate

dbt docs generate is required because Wren imports the authoritative column list and types from target/catalog.json.

Import the dbt Profile

Convert the active dbt target into a Wren connection profile:

wren profile import dbt --project-dir ./your-dbt-project

Useful options:

FlagDescription
--project-dirdbt project root. Defaults to .
--profiles-pathCustom path to dbt profiles.yml
--profiledbt profile name override
--targetdbt target name override
--nameDestination Wren profile name
--no-activateSave the profile without making it active

Supported adapters include postgres, bigquery, snowflake, databricks, trino, clickhouse, duckdb, mysql, redshift, spark, athena, mssql, and doris.

Import the dbt Project

Generate a Wren project from dbt artifacts:

wren context import dbt \
--project-dir ./your-dbt-project \
--path ./wren-project

Preview generated files first:

wren context import dbt \
--project-dir ./your-dbt-project \
--path ./wren-project \
--dry-run

Use --force to overwrite files managed by the importer.

Generated files:

FileDescription
wren_project.ymlProject metadata, data source, and dbt binding
models/*/metadata.ymlImported dbt models and sources
relationships.ymlJoins inferred from dbt relationships tests
instructions.mddbt test summary, verified constraints, and warnings
AGENTS.mdAgent workflow guidance
queries.ymldbt-derived seed NL-SQL pairs for memory indexing

The importer skips ephemeral models, nodes without catalog columns, and manifest-only columns that are not present in catalog.json.

dbt Test Mapping

Wren imports dbt tests as semantic metadata:

dbt testWren output
not_nullnot_null: true on the column
unique + not_nullis_primary_key: true and model primary_key
accepted_valuesproperties.accepted_values
relationshipsAn entry in relationships.yml

Relationship tests stay in relationships.yml; the importer does not stamp relationship dereferences onto FK columns.

Build and Query

Compile the Wren project:

wren context build --path ./wren-project

Run SQL against imported model names:

wren --sql "SELECT * FROM fct_orders LIMIT 5"

Memory

If memory is installed, index the imported project:

wren memory index --path ./wren-project

The memory index includes dbt descriptions, layers, test status, accepted values, and seed pairs from queries.yml.

Complete DuckDB Example

cd jaffle_shop_duckdb
dbt build
dbt docs generate

wren profile import dbt --project-dir .
wren context import dbt --project-dir . --path ../wren-jaffle
wren context build --path ../wren-jaffle
wren --sql "SELECT * FROM fct_orders LIMIT 5"

Troubleshooting

dbt project file not found: make sure --project-dir points to the directory containing dbt_project.yml.

dbt manifest file not found: run dbt build or dbt compile.

dbt catalog file not found: run dbt docs generate.

Environment variable 'X' is required: export variables referenced by env_var() in your dbt profile before importing.

Models skipped without columns: regenerate catalog.json with dbt docs generate, then re-run wren context import dbt --force.