MetricProof
Executable checks for the assumptions behind business metrics.
MetricProof is a small, dependency-free Python package and CLI for detecting analytical failures that ordinary schema tests can miss: a KPI calculated from the wrong denominator, customers silently lost before evaluation, segment totals that do not reconcile, and malformed retention cohorts.
It was built from a practical SaaS retention problem: a dashboard value can look plausible while still being misleading because its population or denominator changed upstream.
Why this project is different
Most data-quality tools are strong at generic checks such as nulls, types, ranges, and duplicate rows. MetricProof has a narrower purpose: it turns metric definitions into executable evidence.
ratio_consistencyrecomputes a published rate from its numerator and denominator.population_preservedcatches survivorship bias when inactive or unmatched entities disappear before analysis.cohort_integritychecks frozen denominators, period-zero retention, valid rates, and monotonic strict-retention curves.reconciliationproves that headline and segmented totals tie out.unique_grainandnumeric_rangeprotect the table structure and metric bounds supporting those business assertions.
The checks are deliberately narrow. They complement schema validation by testing whether a published analytical result still matches its declared population, grain, and calculation.
Quick start
MetricProof requires Python 3.11 or newer and has no runtime dependencies.
python -m pip install metricproof
metricproof --help
metricproof --version
To run the included SaaS retention audit:
git clone https://github.com/AtomicGlance/metricproof.git
cd metricproof
metricproof audit examples/retention_contract.json
Expected result:
MetricProof: SaaS retention metric audit
Result: PASS | 6 passed, 0 failed, 0 errors
[PASS ] one-headline-per-month (unique_grain)
1 rows match the declared grain.
[PASS ] activation-rate-bounds (numeric_range)
All 1 'activation_rate' values are within range.
[PASS ] activation-rate-recomputes (ratio_consistency)
All 1 reported rates recompute correctly.
[PASS ] segment-mrr-ties-to-headline (reconciliation)
The two sum aggregates reconcile.
[PASS ] eligible-population-survives (population_preserved)
Evaluated population preserves 100.0% of baseline entities.
[PASS ] retention-cohorts-are-valid (cohort_integrity)
All 2 cohort(s) preserve their analytical contract.
Run the intentionally broken example to see the audit expose four subtle failures:
metricproof audit examples/broken_retention_contract.json
The command exits with 0 when critical checks pass, 1 when a critical check
fails, and 2 when the contract or input cannot be read. That makes it useful
as a lightweight CI quality gate.
Analytical contract
Checks live in a readable JSON contract. Dataset paths are resolved relative to the contract file.
{
"contract_version": "1.0",
"title": "SaaS retention metric audit",
"datasets": {
"headline": "data/headline.csv",
"baseline": "data/baseline_accounts.csv",
"evaluated": "data/evaluated_accounts.csv"
},
"checks": [
{
"id": "activation-rate-recomputes",
"type": "ratio_consistency",
"dataset": "headline",
"numerator": "activated_accounts",
"denominator": "eligible_accounts",
"rate": "activation_rate"
},
{
"id": "eligible-population-survives",
"type": "population_preserved",
"baseline": "baseline",
"evaluated": "evaluated",
"key": "account_id"
}
]
}
Reports can be emitted for people or automation:
metricproof audit examples/retention_contract.json --format json
metricproof audit examples/retention_contract.json \
--format markdown --output audit-report.md
JSON and Markdown reports also record a dataset inventory: the contract-relative source path, row count, file size, and SHA-256 fingerprint. This makes an audit reproducible and lets a reviewer confirm which exact extracts produced the reported result, even when the source files are regenerated later.
MetricProof 0.2 reports use a versioned, domain-neutral evidence envelope. The
JSON output includes schema_version, report_type, producer identity,
artifact fingerprints, structured check results, and report-specific context.
Print the bundled schemas or validate a contract before loading its data:
metricproof schema contract
metricproof schema evidence
metricproof validate-contract examples/retention_contract.json
Check plugins
External packages can add contract check types without modifying MetricProof.
A runner receives the check definition, loaded datasets, and severity, and
returns a CheckResult:
from metricproof import CheckResult, register_check_type
def row_count(check, datasets, severity):
observed = len(datasets[check["dataset"]])
expected = int(check["expected"])
return CheckResult(
check_id=check["id"],
check_type="row_count",
status="pass" if observed == expected else "fail",
severity=severity,
message=f"Observed {observed} row(s); expected {expected}.",
observed=observed,
expected=expected,
)
register_check_type("row_count", row_count)
Published plugins should expose the runner through the
metricproof.checks entry-point group. The entry-point name becomes the
contract check type:
[project.entry-points."metricproof.checks"]
row_count = "my_package.checks:row_count"
Python API
from metricproof import check_population_preserved
eligible = [{"account_id": "A01"}, {"account_id": "A02"}]
evaluated = [{"account_id": "A01"}]
result = check_population_preserved(
eligible,
evaluated,
key="account_id",
)
assert result.status == "fail"
assert result.evidence == [
{"key": "A02", "issue": "missing from evaluated population"}
]
Inputs are sequences of dictionaries, so the package works with standard CSV and JSON data and can also accept records from a dataframe:
rows = dataframe.to_dict(orient="records")
Where it fits
MetricProof is useful after analytical tables or dashboard extracts have been produced and before their metrics are published. A JSON contract can run locally, in a scheduled pipeline, or in CI and return a non-zero exit code when a critical analytical assumption fails.
It does not replace source-system validation. Instead, it checks the layer between clean source data and a trustworthy reported metric.
Design boundaries
MetricProof intentionally stays small:
- CSV and JSON are supported directly; warehouse connections are out of scope.
- Strict retention is expected to be monotonic. Set
"monotonic": falsefor rolling or resurrection-style retention. - The package validates supplied analytical outputs; it does not calculate product KPIs or replace source-system tests.
- Version
0.2.0introduces versioned contracts, external check plugins, and a stable evidence-report schema shared with domain integrations.
Development
$env:PYTHONPATH = (Resolve-Path src).Path
python -m unittest discover -s tests -v
python -m metricproof audit examples/retention_contract.json
python -m metricproof audit examples/broken_retention_contract.json
On macOS or Linux, use export PYTHONPATH="$PWD/src" instead.
License
MIT
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 metricproof-0.2.0.tar.gz.
File metadata
- Download URL: metricproof-0.2.0.tar.gz
- Upload date:
- Size: 22.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46d4350715da77d62a33bdc21ce6c13bd8300dc63a33ce199622b97c05927ded
|
|
| MD5 |
5285d2971234a51a14e125f5c8719a12
|
|
| BLAKE2b-256 |
418f9f40286eaad4e7c41c84aedc8bfe9cd093d96457de02da4756b688d691d1
|
Provenance
The following attestation bundles were made for metricproof-0.2.0.tar.gz:
Publisher:
publish.yml on AtomicGlance/metricproof
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
metricproof-0.2.0.tar.gz -
Subject digest:
46d4350715da77d62a33bdc21ce6c13bd8300dc63a33ce199622b97c05927ded - Sigstore transparency entry: 2435244642
- Sigstore integration time:
-
Permalink:
AtomicGlance/metricproof@0fbd6ae8262d7e55cec06a7560e7bcfcada25036 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/AtomicGlance
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0fbd6ae8262d7e55cec06a7560e7bcfcada25036 -
Trigger Event:
release
-
Statement type:
File details
Details for the file metricproof-0.2.0-py3-none-any.whl.
File metadata
- Download URL: metricproof-0.2.0-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c7bf631afa5271a08d37cb7a3eac6d9e098365ccad0305fb89a9d819d71e67b
|
|
| MD5 |
bde89e0c1a59af288a50221b63c4e9b5
|
|
| BLAKE2b-256 |
2fdf0c579e0a652abf4f22ebd13edc5bfb4e640af0ea8b1b7115801de854c213
|
Provenance
The following attestation bundles were made for metricproof-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on AtomicGlance/metricproof
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
metricproof-0.2.0-py3-none-any.whl -
Subject digest:
1c7bf631afa5271a08d37cb7a3eac6d9e098365ccad0305fb89a9d819d71e67b - Sigstore transparency entry: 2435244720
- Sigstore integration time:
-
Permalink:
AtomicGlance/metricproof@0fbd6ae8262d7e55cec06a7560e7bcfcada25036 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/AtomicGlance
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0fbd6ae8262d7e55cec06a7560e7bcfcada25036 -
Trigger Event:
release
-
Statement type: