Recipe
Recipe: dbt model + test writer
Generate dbt SQL models and accompanying data tests from natural-language table descriptions.
Ingredients
- Source table schema (column names + types)
- Target table description in plain English
- dbt project with
dbt-coreinstalled
Prompt template
You are a dbt expert. Given the source schema below,
write a dbt SQL model that produces the described
target table. Then write dbt tests (unique, not_null,
accepted_values, relationships) for every column
where they apply.
Source schema:
{{source_schema}}
Target description:
{{target_description}}
Output format:
1. model.sql
2. schema.yml with testsExample output
models/marts/customer_360.sql
SELECT
c.customer_id,
c.email,
SUM(o.amount) AS lifetime_value
FROM {{ ref('stg_customers') }} c
LEFT JOIN {{ ref('stg_orders') }} o
ON c.customer_id = o.customer_id
GROUP BY 1, 2models/marts/schema.yml
models:
- name: customer_360
columns:
- name: customer_id
tests:
- unique
- not_null
- name: email
tests:
- not_null
- name: lifetime_value
tests:
- not_nullUsage
- Paste the prompt into Meridian with your schema and description.
- Copy the generated SQL into
models/. - Run
dbt testto validate.