Skip to main content

sqlprove

Formally verified SQL cost optimizer for BigQuery, Snowflake, and dbt — 100% local, zero PII.

Blind LLM SQL rewrites look clean in PR reviews — and silently break dashboards. In our 120-rewrite blind benchmark across 40 real dbt-derived queries, unverified LLMs introduced 17.5%–34.4% silent semantic bugs (NULL traps, duplicate-row fan-out, dropped all-NULL groups).

sqlprove pairs rewrite discovery with unbounded algebraic proofs (A0–A9), a Z3 SMT equivalence prover (bag semantics + 3-valued NULL logic + dbt schema.yml/manifest.json constraints), DuckDB counterexample confirmation, and warehouse-specific cost gating measured live on Google BigQuery and Snowflake.


Try in 10 Seconds (Zero Config, No dbt Needed)

pip install sqlprove

# 1. Watch Z3 + DuckDB catch subtle NULL & join-multiplication bugs live
sqlprove demo

# 2. Check any raw query on the spot (conservative inferred schema)
sqlprove check "SELECT event_id, amount FROM events WHERE EXTRACT(YEAR FROM created_at) = 2025 AND EXTRACT(MONTH FROM created_at) = 12" \
  --target bigquery-ondemand --table-gb 500 --runs-per-month 30

# 3. Watch Z3 refuse an unsafe dead-join drop with a concrete DuckDB counterexample,
#    then unlock an unbounded proof once you declare --unique customers.id:
sqlprove check "SELECT o.id, o.amount FROM orders o LEFT JOIN customers c ON o.customer_id = c.id" --target snowflake
sqlprove check "SELECT o.id, o.amount FROM orders o LEFT JOIN customers c ON o.customer_id = c.id" --target snowflake --unique customers.id

Live Cloud Benchmark Summary (Cold Runs, Zero Cache)

Measured on live Google BigQuery (2M rows/table, 365 partitions, clustered) and Snowflake (6M rows/table, ~100 micro-partitions, USE_CACHED_RESULT = FALSE). Full data & reproducible SQL scripts: benchmarks/week2-cloud-validation.md.

Formally Proven Rewrite Pattern BigQuery On-Demand ($/TB) BigQuery Editions (slot_ms) Snowflake Scan (MB) Snowflake Compute (ms)
Cross-view dead LEFT JOIN + nested DISTINCT (A4) -20.0% -5.8% -13.1% -95.9% (24.4×)
Redundant DISTINCT via dbt unique+not_null (A3b) -10.3% -79.7% 0.0% -60.7%
Dead INNER JOIN via dbt relationships FK (A2) -4.3% -65.6% -13.1% -31.6%
COALESCE(bool, FALSE) / NOT COALESCE / <> sentinel (A5) -76.9% to -87.1% -21% to -37.5% 0% / +4.1% -10% to -31.3%
EXTRACT(YEAR/MONTH) → [lo, hi) range (A7) -91.3% -92.5% -3.1% -12.3%
2× repeated CTE UNION ALL → single pass (A8) 0.0% -61.2% 0.0% -70.4% (3.4×)
4× disjoint UNION ALL GROUP BY → 1 scan (A9) 0.0% -74.8% -75.0% -62.7%
Cross-col OR → disjoint UNION ALL w/ IS NULL (A6) 0.0% -75.6% +16.5% (auto-blocked on Snowflake!) +1.9%

Audit a dbt Project (target/manifest.json)

dbt compile

# Audit compiled models + automatically unfold upstream logical views (`view`/`ephemeral`)
sqlprove audit . --target snowflake --format github-pr
sqlprove audit . --target bigquery-ondemand --table-stats table_stats.json --format github-pr
sqlprove audit . --target bigquery-editions --show-all

Per-Model Cost Calibration (table_stats.json or dbt meta:)

Instead of applying one uniform --table-gb across every model, you can calibrate monthly $/mo estimates per model via either dbt meta: tags in schema.yml / config(meta=...):

models:
  - name: fct_events
    meta:
      table_gb: 1200
      runs_per_month: 60

or a lightweight --table-stats table_stats.json:

{
  "cost_per_tb": 6.25,
  "credit_price": 3.0,
  "models": {
    "fct_events": { "table_gb": 1200, "runs_per_month": 60 },
    "tides_publication_organizations": { "avg_runtime_sec": 95, "warehouse_size": "L", "runs_per_month": 30 }
  }
}

Drop-in GitHub Action (Sticky PR Comment, Zero Spam on Clean PRs)

Save as .github/workflows/sqlprove.yml in your dbt repo:

name: sqlprove SQL Cost Audit
on:
  pull_request:
    paths: ["models/**/*.sql", "models/**/*.yml"]

permissions:
  pull-requests: write

jobs:
  sqlprove:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: pip install sqlprove
      # Run your existing `dbt compile` step (or point sqlprove at a cached target/manifest.json)
      - name: Run sqlprove audit
        run: |
          sqlprove audit . \
            --target bigquery-ondemand \
            --format github-pr \
            --skip-if-clean > sqlprove-report.md
      - name: Post or update sticky PR comment
        if: always()
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          if [ -s sqlprove-report.md ]; then
            gh pr comment "${{ github.event.pull_request.number }}" \
              --body-file sqlprove-report.md \
              --edit-last --create-if-none
          fi

Verification Tiers (Fail-Closed)

  • ALGEBRAICALLY_PROVEN — Unbounded equivalence established by a sound schema-aware rule (A0–A9).
  • BOUNDED_VERIFIED — Z3 proved UNSAT for every symbolic database up to bound rows per table (including arbitrary NULLs and duplicates).
  • COUNTEREXAMPLE_FOUND — Z3 synthesized concrete input tables where the queries return different multisets, independently confirmed in DuckDB.
  • UNSUPPORTED / UNKNOWN — Fails closed; never emitted as a proven rewrite.
  • 0 false positives across 35,900 randomized NULL/duplicate/FK DuckDB fuzz trials.

Zero-PII Top-20 Warehouse Spend Audit (Pilot)

Spending $10k+/mo on BigQuery or Snowflake? Send your target/manifest.json + a 30-day query cost rollup (model_name, bytes_billed/credits, runs_per_month — zero customer rows or PII) to marklar@marklar.systems for a free audit returning formally verified PR diffs ranked by real monthly spend.

Layout

sqlprove/
  src/sqlprove/
    cli.py            # CLI: demo, check, audit, rewrite, prove, scan
    audit.py          # Compiled dbt manifest audit & github-pr / markdown / json / text formatters
    dbt_manifest.py   # target/manifest.json loader, constraint extractor & sound view unfolder
    targets.py        # Live-benchmarked warehouse cost gating & parameterized $/mo estimator
    algebra.py        # Unbounded sound algebraic equivalence rules (A0-A9)
    prover.py         # Z3 SMT 3-valued NULL + bag-semantics equivalence checker
    rewrites.py       # Dialect-native candidate rewrites + CTE congruence verification
    schema.py         # Schema constraints, conservative inference & dbt schema.yml parser
    fuzzer.py         # DuckDB counterexample confirmer & randomized differential fuzzer
    corpus.py         # Raw dbt/SQL repository pattern scanner
    cost.py           # DuckDB EXPLAIN (ANALYZE, FORMAT JSON) profiler
  benchmarks/         # Corpus audit, blind LLM bug-catch, 1M-row scale, and $0 live BQ/SF scripts & results
  tests/              # Unit, soundness, manifest, view-unfolding, PR formatter & fuzz tests

Metadata

Release files for sqlprove 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlprove 0.3.0
File Size Uploaded Provenance Actions
sqlprove-0.3.0.tar.gz 95.6 kB Without provenance Details for sqlprove-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sqlprove 0.3.0
File Interpreter ABI Platform Actions
sqlprove-0.3.0-py3-none-any.whl Python 3 none any Details for sqlprove-0.3.0-py3-none-any.whl

Total release size: 179.8 kB

Release files / sqlprove-0.3.0.tar.gz

Download URL sqlprove-0.3.0.tar.gz
Size 95.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0efd9f1cbb03528ba7649bfb994510f307185a837182e05aebc802693d007a84
BLAKE2b-256 checksum
How to use checksums
51e90043837b99f37990b4950e2b7baa0b1c198387ab7a5b893ec845297d5ae3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / sqlprove-0.3.0-py3-none-any.whl

Download URL sqlprove-0.3.0-py3-none-any.whl
Size 84.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
173d978fd4730e6e61617948090c948373db5281303cc7bc9df7d4f14c23116a
BLAKE2b-256 checksum
How to use checksums
529467aa9597f8a2c6a683e132d1383cf0aea6c027b9acd54a82a6efc397c22f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for sqlprove 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page