dbt-costgate
The BigQuery cost gate for dbt pull requests.
Dry-run what changed, price the diff, and catch the $500-a-day model
before it merges — not on next month's bill.
Quick start · How it works · What you get · Where it fits · Pricing accuracy · Security · Roadmap · Contributing
New here? Start with dbt-costgate, explained — plain English, ten minutes, no prior context assumed.
[!NOTE] MVP — feature-complete, not yet battle-tested. Everything on the roadmap ships: the CLI, the GitHub Action, a pre-commit hook, a published container image, and config scaffolding. What it has not had is mileage across many real projects, which is the only thing that finds the last class of bug. If it does something wrong or confusing, that is worth a bug report — including "the number looks wrong", which is the most useful report this tool can get.
Every report shown here is generated from the real renderers by
scripts/gen_samples.py, and CI fails if any of them drifts from what the code actually produces — the figures are illustrative, the output is not. See the usage guide and changelog.
The problem
On dbt + BigQuery teams, SQL changes merge with zero visibility into their cost impact. A changed join, a dropped partition filter, or a widened incremental window can multiply a model's bytes scanned — and the team finds out days later on the bill, or when finance escalates.
BigQuery's dry-run API returns the exact bytes a query would scan — for free, before running anything. dbt-costgate packages that into a first-class PR gate:
What you get on every PR
A sticky comment on the pull request, updated in place on every push. This is the comment itself — GitHub renders it from the same markdown dbt-costgate produces:
💸 dbt-costgate — cost impact of this change (2 models)
❌ Gate: FAIL
- fct_orders_daily: USD +13.19/run exceeds USD 5.00
- fct_orders_daily: +264% exceeds 25%
Net increase: USD 13.19/run · USD 395.70/month
| Model | Baseline | This change | Δ % | Δ / run | Δ / month |
|---|---|---|---|---|---|
fct_orders_daily full-refresh |
819.20 GiB | 2.91 TiB | +264% | USD +13.19 | USD +395.63 |
dim_customers new |
— | 412.50 MiB | — | USD +0.00 | USD +0.07 |
⚠ full-refresh — rows tagged full-refresh show what it costs to build the whole table from scratch. A normal incremental run scans much less, so read this as the ceiling rather than the nightly bill.
Pricing: US USD 6.25/TiB · built-in table (table 2026.07, verified 2026-07-25)
Priced from the first byte scanned: BigQuery's 1 TiB/month on-demand free tier is per billing account, so it is disclosed here and never deducted.
Estimates from BigQuery dry-run — nothing executed, no bytes billed, no SQL shown.
💻 The same check, in your terminal (real output)
dbt-costgate check --baseline path/to/main/manifest.json
dbt-costgate — region: US · on-demand USD 6.25/TiB · built-in table
MODEL BASELINE CURRENT Δ % Δ / RUN Δ / MONTH RUNS
──────────────── ──────────── ────────── ────────── ───── ────────── ─────────── ────
fct_orders_daily full-refresh 819.20 GiB 2.91 TiB +264% USD +13.19 USD +395.63 30
dim_customers new — 412.50 MiB — USD +0.00 USD +0.07 30
Net increase: USD 13.19/run · USD 395.70/month
GATE: FAIL
- fct_orders_daily: USD +13.19/run exceeds USD 5.00
- fct_orders_daily: +264% exceeds 25%
NOTES
⚠ full-refresh — rows tagged full-refresh show what it costs to build the whole table from
scratch. A normal incremental run scans much less, so read this as the ceiling rather than the
nightly bill.
Pricing: US USD 6.25/TiB · built-in table (table 2026.07, verified 2026-07-25)
Priced from the first byte scanned: BigQuery's 1 TiB/month on-demand free tier is per billing
account, so it is disclosed here and never deducted.
Estimates from BigQuery dry-run — nothing executed, no bytes billed, no SQL shown.
Or run it with no baseline at all for an instant local read of what your changed
models scan — and fail the run there on an absolute --max-usd-total /
--max-tib-total ceiling (no baseline required) — or get the full before/after
locally in one command with dbt-costgate check --against main (dbt-costgate compiles
main for you in a throwaway worktree). See the usage guide.
Quick start
pip install dbt-costgate
gcloud auth application-default login
dbt compile
dbt-costgate check
That's the entire local setup — no baseline, no CI, no config file. Add a baseline and thresholds when you want it to block a PR; see the usage guide.
When you do want a config file, dbt-costgate init writes one documenting every
setting, all commented out — so it changes nothing until you uncomment
something.
Every release also ships a
wheel, an sdist, and SHA256SUMS if you'd rather pin to an artifact.
Documentation
So you know where to look before you open anything:
| Document | What's inside | Go here when |
|---|---|---|
| Explained | Plain-English guide: how it works, what it costs to run, which pricing setup you're in, every config key, the deliberate non-goals, and when a number can be wrong | You're new, or you want to know what a setting does |
| Usage guide | The how-to: install, CI setup, baselines, thresholds, the GitHub Action, worked examples for on-demand / negotiated / slot pricing | You're setting it up or changing how it runs |
| Architecture | Why it's built this way, the invariants, the hard edges | You're contributing or reviewing a change |
| Security | Threat model, and what counts as a vulnerability | You're reviewing it for use next to production credentials |
| Changelog | What changed in each release, in operator terms | You're upgrading |
Every example report in these docs is generated from the real renderers, and CI fails if one drifts — so what you read is what the tool actually prints.
How it works
| Step | What happens | Cost to you |
|---|---|---|
| 1 · Find what changed | dbt's state:modified selector against a baseline manifest (your production artifacts), with a git-diff fallback |
free |
| 2 · Compile both versions | The baseline and PR-branch versions of each changed model | free |
| 3 · Dry-run each | BigQuery dryRun=true returns exact bytes scanned — executes nothing, reads no table data |
free |
| 4 · Price the diff | Region-aware on-demand rates; optionally × run frequency for $/month | free |
| 5 · Gate | Markdown PR comment, machine-readable JSON, policy-driven exit code (fail on a $ and/or % increase, or an absolute $/run or TiB/run ceiling) | free |
Where it fits
dbt-costgate is the preventive half of BigQuery cost control — it deliberately does not compete with the excellent retrospective tools:
| The question you're asking | Reach for |
|---|---|
| "What did our warehouse cost, by model / user / query?" | dbt-bigquery-monitoring |
| "What does the dbt platform estimate my models cost?" | dbt Cost Insights |
| "What is this PR about to do to our bill?" | dbt-costgate |
Accurate, transparent pricing
BigQuery on-demand rates differ by region — a gate that prices every byte at the US rate is silently wrong for half the world. dbt-costgate treats pricing accuracy as a feature:
-
🌍 Versioned per-region pricing table with a
last_verifieddate, auto-selected from your job's detected region. -
🧾 Every report discloses its math — region, rate, and rate source. Never a silent assumption:
region: US (multi-region) · on-demand USD 6.25/TiB · source: built-in table 2026.07
-
⚙️ Overridable —
pricing.regionto force a region,pricing.usd_per_tibfor negotiated or editions rates,pricing.currencyto label amounts in your own currency (an ISO 4217 code — dbt-costgate labels, it never converts). -
⚠️ Honest limits, stated up front — under capacity/editions pricing, bytes scanned is a proxy signal, not your invoice; set a rate of
0and reports drop money entirely and measure bytes instead. Every priced report's footer discloses the 1 TiB/month on-demand free tier it does not deduct — the allowance is per billing account, which a dry-run cannot see, so figures are priced from the first byte.
Security model
This tool runs in CI next to warehouse credentials, so the design is deliberately boring:
| Threat | Design answer |
|---|---|
| Billable or data-reading queries | Dry-run only. The single warehouse interaction is jobs.insert with dryRun=true — free, executes nothing |
| Credential theft / mishandling | No credential surface. Auth delegates entirely to Application Default Credentials; in CI the documented path is keyless Workload Identity Federation. There are no credential flags to misuse |
| Compromised CI runner | Least privilege. BigQuery Job User + metadata read — no data access, no writes; docs ship the exact IAM setup |
| Malicious fork PRs | Fork-safe by default. Documented workflows use the pull_request trigger; fork PRs degrade to "no report", never to exposed secrets |
| Secrets templated into SQL | No compiled SQL in reports — model names, bytes, and dollars only; snippets are strictly opt-in |
| Phone-home | No telemetry. The only network call is to the BigQuery API |
Details in SECURITY.md · deeper design notes in docs/architecture.md.
Roadmap
The MVP roadmap is complete — every item below ships as of v1.0.5.
-
dbt-costgate check— local (zero-setup) + CI diff, region-aware pricing, threshold gating - One-command local diff —
dbt-costgate check --against main(isolated git worktree) - GitHub Action wrapper with a sticky PR comment
- Absolute cost ceilings — gate on total
$/runorTiB/run, not just the increase (works without a baseline, so it gates local mode too) - Config- and macro-only change detection — catch a change that reaches a model without touching its
.sqlfile -
pre-commithook — catch it on your own machine, at pre-push - Docker image — for CI that isn't GitHub Actions; build it yourself, or
- pull the published image —
ghcr.io/drichards124/dbt-costgate:v1.0.5, pushed on every release
What's next is not another feature. The list above was written before anyone had run this against a real warehouse for a month. The useful next step is use — finding where the numbers, the defaults or the docs are wrong — and the next features should be the ones that use actually asks for, rather than the ones that looked obvious from here. Two places that already know what they don't do: when the number can be wrong and the non-goals below.
Non-goals
- Not a monitoring tool — retrospective observability belongs to dbt-bigquery-monitoring.
- BigQuery first — one warehouse done accurately beats three done approximately. Other warehouses come only once BigQuery is genuinely finished, and only where the cost model actually transfers.
- Never runs billable queries — features that require executing real queries are out of scope by design.
- No IDE/editor integration (for now).
Explained · Usage guide · Contributing · Security policy · Changelog · Code of Conduct · Apache-2.0 · NOTICE
Built by Dashan Richards — DCO sign-off required, hard invariants apply:
dry-run only · no credential handling · no telemetry
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dbt_costgate-1.0.5.tar.gz.
File metadata
- Download URL: dbt_costgate-1.0.5.tar.gz
- Upload date:
- Size: 256.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da771f07b01ce1f3ed891e12cc9ffb76acbe4569fb3b413c0d36b2693a37a860
|
|
| MD5 |
835d5fc18fa1e08485081eccf45cc873
|
|
| BLAKE2b-256 |
9cd72b0e91712c178370c7567503930b0eafe5baf2628f6e444a0730e53d1613
|
Provenance
The following attestation bundles were made for dbt_costgate-1.0.5.tar.gz:
Publisher:
release.yml on Drichards124/dbt-costgate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dbt_costgate-1.0.5.tar.gz -
Subject digest:
da771f07b01ce1f3ed891e12cc9ffb76acbe4569fb3b413c0d36b2693a37a860 - Sigstore transparency entry: 2264379346
- Sigstore integration time:
-
Permalink:
Drichards124/dbt-costgate@fc49aaeb3f99923ca461ba281578fd424ff798dd -
Branch / Tag:
refs/tags/v1.0.5 - Owner: https://github.com/Drichards124
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fc49aaeb3f99923ca461ba281578fd424ff798dd -
Trigger Event:
push
-
Statement type:
File details
Details for the file dbt_costgate-1.0.5-py3-none-any.whl.
File metadata
- Download URL: dbt_costgate-1.0.5-py3-none-any.whl
- Upload date:
- Size: 84.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f6987fdd4df6dd2fd3ef7938b513a66d0c37d269822b5122caabf2481844f1d
|
|
| MD5 |
720c032ac0be250f50a1af2ab9e3647c
|
|
| BLAKE2b-256 |
a79e528a91155349c1064dbb8f0c3247471e7f8a8cdc869db9a185a4d3eb9573
|
Provenance
The following attestation bundles were made for dbt_costgate-1.0.5-py3-none-any.whl:
Publisher:
release.yml on Drichards124/dbt-costgate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dbt_costgate-1.0.5-py3-none-any.whl -
Subject digest:
4f6987fdd4df6dd2fd3ef7938b513a66d0c37d269822b5122caabf2481844f1d - Sigstore transparency entry: 2264379393
- Sigstore integration time:
-
Permalink:
Drichards124/dbt-costgate@fc49aaeb3f99923ca461ba281578fd424ff798dd -
Branch / Tag:
refs/tags/v1.0.5 - Owner: https://github.com/Drichards124
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fc49aaeb3f99923ca461ba281578fd424ff798dd -
Trigger Event:
push
-
Statement type: