← Docs
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-core installed

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 tests

Example 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, 2

models/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_null

Usage

  1. Paste the prompt into Meridian with your schema and description.
  2. Copy the generated SQL into models/.
  3. Run dbt test to validate.