📘 Introduction

Codex can be very useful in a dbt project, especially when you already have a clean Silver layer and want to create a business-ready Gold model from it. Instead of starting from an empty prompt, you can give Codex the current project structure, the existing models, and the exact output you want.

In this tutorial, you will learn how to use Codex to create a dbt Gold model. We will use the Medallion Architecture in dbt for this example, where data moves from cleaned Silver models into a business-ready Gold model: two Silver models already exist, and Codex will help us create a Gold dimension model named dim_course.

💡 What are we implementing?

We start with two existing Silver models:

  • course_cleaned contains cleaned course facts such as id, code, credits, level, semester_number, and source_name.
  • course_mapping_cleaned contains descriptive course information such as code and name.

Codex will generate a Gold model that joins both models and creates a simple course dimension:

Silver course_cleaned + Silver course_mapping_cleaned -> Codex -> Gold dim_course

The important part is that Codex should not guess the business logic. We will tell it the model name, the input models, the join key, the expected grain, and the columns we want in the final output.

✅ Prerequisites

☑️ A working dbt project with a Silver layer
☑️ The Silver models course_cleaned and course_mapping_cleaned already exist
☑️ Codex is available in the Codex app, CLI, or IDE extension
☑️ Basic knowledge of SQL and dbt models
☑️ A Git workflow where you can review changes before committing them

🧭 Current project state

Before asking Codex to create anything, make the current state of the project clear. In our example, this excerpt of the project already contains the Silver layer, but the Gold layer is still empty.

💡
This is only the relevant excerpt of the dbt project structure. A complete dbt project also includes files and folders such as dbt_project.yml, profiles configuration, macros, seeds, snapshots, tests, and packages depending on the setup.
models/
├── silver/
│   ├── course_cleaned.sql
│   └── course_mapping_cleaned.sql
└── gold/

This is a useful point to pause and define what the Gold layer should do. In a Medallion Architecture, Silver models are cleaned and standardized, while Gold models are shaped for reporting, analytics, or business-facing use cases.

🎓 Want to go deeper with dbt?

If you want to understand Bronze, Silver, and Gold layers in more detail, the Academy and the dbt book go deeper into hands-on Medallion Architecture projects with practical examples.

CTA Image

If you’d like to dive deeper into dbt (data build tool), our book Building Modern Data Pipelines with dbt: From Raw Data to Gold Standard with the Medallion Architecture provides a hands-on guide to designing modern data pipelines. It covers dbt’s core concepts and best practices, including building Bronze, Silver, and Gold layers with the Medallion Architecture. It also serves as a hands-on study guide for the dbt Analytics Engineering Certification.

View on Amazon

You can view this post with the tier: Academy Membership

Join academy now to read the post and get access to the full library of premium posts for academy members only.

Join Academy Already have an account? Sign In