Data Analysis & SQL5.0 · 0 ratings

Build An Incremental dbt Model

Writes an incremental dbt model with correct unique key, late-arriving handling, and backfill strategy.

Role-BasedStep-by-StepStructured-Output

Prompt

ROLE: You are an analytics engineer building production dbt models.

CONTEXT: Create an incremental model named [MODEL_NAME] from source [SOURCE_TABLE] (schema [SCHEMA]). Target warehouse: [DATABASE_ENGINE]. Grain: one row per [GRAIN]. Late-arriving data window: up to [LATENESS]. Unique/business key: [UNIQUE_KEY].

TASK:
1. Decide the incremental strategy (append, merge/upsert, insert_overwrite by partition) and justify it for this grain.
2. Write the dbt model SQL with the proper config block, the is_incremental() filter using an updated-at watermark with a safety lookback for late data, and the unique_key.
3. Add dbt tests (unique, not_null, relationships, accepted_values) for the key columns in YAML.
4. Explain how a full-refresh backfill behaves vs an incremental run.
5. Note idempotency: running twice must not duplicate or drift.

OUTPUT FORMAT: Strategy rationale -> Model ```sql``` -> schema.yml tests -> Backfill behavior -> Idempotency notes.

CONSTRAINTS: The is_incremental() predicate must include a lookback to catch late-arriving rows. Use merge with unique_key to stay idempotent on the chosen engine. No SELECT *; select explicit columns. State the watermark column and its timezone assumption.

How to use this prompt

  1. 1

    Copy the prompt above and paste it into ChatGPT, Claude, or Gemini — or open it in the visual Studio to edit each part on a canvas and run it with your own key.

  2. 2

    Replace any bracketed placeholders with your specifics. The more concrete your context and constraints, the sharper the result — see the 5-part prompt structure.

  3. 3

    Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.

Techniques in this prompt

Role-Based

Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.

Learn this technique
Step-by-Step

Forces explicit intermediate reasoning instead of jumping to a conclusion, which improves accuracy on hard tasks.

Learn this technique
Structured Output

Pins the response to a defined structure so it drops straight into your workflow.

Learn this technique

Recommended models

claudegpt-4ogemini

Build on this prompt

Open it in the visual Studio to wire it into a full workflow with your own API key — or learn the craft behind prompts like this.

More in Data Analysis & SQL