Skip to main content

sqlprove

Proof-carrying SQL cost optimizer for BigQuery, Snowflake, and dbt — 100% local, zero PII.

Instead of asking data teams to blindly trust LLM-rewritten SQL (which introduced 17.5%–34.4% silent NULL, duplicate-row, and LEFT JOIN bugs in our 120-rewrite blind benchmark), sqlprove pairs rewrite discovery with unbounded algebraic proofs, a Z3 SMT formal equivalence checker (bag semantics + 3-valued NULL logic + dbt schema.yml / manifest.json constraints), DuckDB counterexample confirmation, and warehouse-specific cost gating backed by live BigQuery and Snowflake benchmarks.

Live Cloud Benchmark Summary ($0 Reproducible Validation)

Measured cold (zero cache hits) on live Google BigQuery (2M rows/table, 365 partitions, clustered) and Snowflake (6M rows/table, ~100 micro-partitions, USE_CACHED_RESULT = FALSE). Full breakdown: 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%

Quickstart

pip install sqlprove

# Built-in Z3 + DuckDB bug-catch demo
sqlprove demo

# Audit a compiled dbt project (`dbt compile` -> target/manifest.json) with view unfolding + warehouse gating
sqlprove audit /path/to/dbt_project --target snowflake
sqlprove audit /path/to/dbt_project --target bigquery-ondemand --format markdown
sqlprove audit /path/to/dbt_project --target bigquery-editions --show-all

# Rewrite & verify a single SQL query for a specific warehouse target
sqlprove rewrite --sql "SELECT ..." --schema schema.json --dbt-schema models/ --target bigquery-ondemand

# Prove equivalence (or synthesize a DuckDB-confirmed counterexample) for any two SQL queries
sqlprove prove --q1 "..." --q2 "..." --schema schema.json --dbt-schema models/

Verification Tiers (Fail-Closed)

  • ALGEBRAICALLY_PROVEN — Unbounded equivalence established by a verified schema-aware algebraic rule (A0–A9).
  • BOUNDED_VERIFIED — Z3 proved UNSAT (no counterexample) for all symbolic databases up to bound rows per table, including arbitrary NULLs and duplicates.
  • COUNTEREXAMPLE_FOUND — Z3 synthesized concrete table rows where the two queries return different multisets, independently confirmed in DuckDB.
  • UNSUPPORTED / UNKNOWN — Fails closed; never emitted as a proven rewrite.

Layout

sqlprove/
  src/sqlprove/
    cli.py            # CLI: demo, audit, rewrite, prove, scan
    audit.py          # Compiled dbt manifest audit orchestrator (text/markdown/json)
    dbt_manifest.py   # target/manifest.json loader, constraint extractor & sound view unfolder
    targets.py        # Live-benchmarked warehouse cost gating (BQ On-Demand, BQ Editions, Snowflake, DuckDB)
    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 & zero-dependency 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/              # 32 unit, soundness, manifest, view-unfolding & differential fuzz tests

Metadata

Release files for sqlprove 0.1.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.1.0
File Size Uploaded Provenance Actions
sqlprove-0.1.0.tar.gz 82.0 kB Without provenance Details for sqlprove-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 156.5 kB

Release files / sqlprove-0.1.0.tar.gz

Download URL sqlprove-0.1.0.tar.gz
Size 82.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1973d7e14f20fc641bcecbe576ad98b02abdd3dc98fbf5b91e61c00bb95c757a
BLAKE2b-256 checksum
How to use checksums
51b6b26cad8729f0205101b9787848db4e261cba2b1b36258c6431fdc1a85160
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.1.0-py3-none-any.whl

Download URL sqlprove-0.1.0-py3-none-any.whl
Size 74.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ffe075dd69966bc77d36d5d9ea224606c83091b8c238bb313ac386df8faad51b
BLAKE2b-256 checksum
How to use checksums
63826e1274e661cb1cc991ac897f021ae21b9be8493832fd1e600b16610ee049
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.1.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