Write a dbt model
Writes a dbt model from business logic, with declared sources, a stated grain, unique, not_null and relationships tests, column docs and a safe incremental strategy. Use when adding a dbt model.
dbt models go wrong in quiet ways. A join fans out and nobody notices because no test pins the grain. A table name is hardcoded instead of using ref or source, so lineage and environments break. Business terms are implemented the way the author guessed. An incremental model filters on max(updated_at) with no lookback, so late-arriving rows are lost forever. Good dbt code states its grain, tests it, documents its columns and makes incremental loads safe to rerun.
Write a dbt model, materialised as , for this logic:
Sources and upstream models:
- State the grain as "one row per …" and the key that enforces it. If the business logic leaves the grain or a definition open, ask, or state the assumption and put it in Open questions.
- Declare sources in a sources YAML file with
loaded_at_fieldand freshness thresholds where a load timestamp exists. Reference upstream data only throughsource()andref(). - Add staging models only where a source needs renaming, casting or deduplication, one per source, following the project convention (
stg_<source>__<table>if unknown). - Write the model SQL as import CTEs, then logical CTEs, then a final
selectwith an explicit column list. Handle nulls and duplicates in the sources explicitly, and note any time zone conversion. - If materialised as incremental: set
unique_key, chooseincremental_strategyfor the warehouse (merge where supported, otherwise delete+insert or insert_overwrite; check whether the project's dbt version supports microbatch), filter new rows insideis_incremental()with a lookback window for late-arriving data, seton_schema_change, and say when a full refresh is needed. - Write a properties YAML file with the model and column descriptions and tests:
uniqueandnot_nullon the key (or a combination-of-columns test for a composite key, naming the package it needs),relationshipsfor foreign keys,accepted_valuesfor categorical columns, and one singular test for the most important business rule. Use thedata_tests:key on dbt 1.8 or later andtests:before that; if the project is on 1.8 or later and the rule is easier to show with fixed input rows, write a dbt unit test instead. - Give the commands to build and test the model and its children, and a query that checks the grain.
- Use only columns listed in the sources. If the logic needs a column that is not there, list it under Open questions instead of inventing it.
- Keep SQL portable unless the warehouse is known. Flag any warehouse-specific function you use.
- No
select *in the final CTE. Keep Jinja to what the model needs. - Follow the project's naming and folder conventions if they are visible in the input.
Assumptions and grain
The grain statement, the key, and each assumption.
Files
Each file in its own fenced block, preceded by its path (for example models/marts/fct_orders.sql, models/marts/_marts__models.yml, models/staging/_sources.yml).
Run and verify
Commands, the grain-check query, and what a passing result looks like.
Open questions
Definitions or columns that need confirmation.
2 required values still a placeholder; the assistant will ask for them.
details
- kind
- Prompt: a task you run by name to get one finished thing back
- domain
- Software engineering
- category
- Data engineering
- level
- Intermediate
- made for
- Data engineer, Data analyst
- risk
- read-only
- version
- v1.0.0 · experimental
- reviewed
- 2026-10-02
- works in
- Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Antigravity, OpenCode, Windsurf, Zed, Continue, AGENTS.md, ChatGPT, claude.ai
use in
npx @hermes-hq/hodios install write-dbt-model --target claude-codenpx skills add hermes-hq/hodios-dist --skill write-dbt-model -a claude-codeclaude plugin marketplace add hermes-hq/hodios-distclaude plugin install hodios-software-engineering@hodiosThe plugin brings every entry in this domain at once.
pairs well with
All of Data engineeringDesign a star schema
Designs a dimensional model from the questions analysts need answered: business processes, grain, facts, dimensions, slowly changing dimension types and DDL. Use when building a warehouse layer.
design-star-schemaWrite data-quality checks for a table
Writes data-quality checks for a table (freshness, volume, schema, validity, uniqueness, referential integrity, distribution) with severities, thresholds and owners. Use when a table feeds decisions.
write-data-quality-checksData engineer
Acts as a data engineer who designs for idempotency, backfills and observability, treats schemas as contracts with their consumers, and asks who depends on each table before changing it.
data-engineerDesign a data pipeline
Designs a batch or streaming data pipeline sized to stated volumes, covering sources, schedule, idempotency, late data, backfills and monitoring. Use before building or replacing a pipeline.
design-data-pipelineDesign a relational database schema
Designs a relational schema from requirements and access patterns, with keys, constraints, types, indexes and DDL. Use when starting a new service or feature that stores data.
design-database-schemaGenerate realistic seed data
Generates realistic, referentially consistent fixture data for a database schema, with labelled edge cases and no real personal data. Use for local development, demos and integration tests.
generate-realistic-seed-data