contextlift

Quickstart

Go from zero to a verified context verdict in about ten minutes. Every command below runs against the live CLI.

Level 0: Try the offline demo (30 seconds, $0)

No API key, no cloud account, and no optional dependencies required:

uvx contextlift demo

The demo builds a small SQLite database in a temporary directory, runs canned baseline and context predictions as real SQL, applies the paired McNemar test, writes a static verdict.html, and prints three follow-up commands you can paste straight into your terminal.

Three-beat terminal demo showing lint, round with attestation, and serve-mcp

For real projects, install the package with the extras you need:

pip install contextlift                 # zero deps: SQLite, lint, stats, verdict, MCP
pip install "contextlift[duckdb,yaml]"  # add [postgres] [snowflake] [databricks] [bigquery] [lookml]

Level 1: Initialize and lint what you already have (2 minutes, $0)

Point contextlift init at your local database (and optional dbt project or SQL folder):

contextlift init --db warehouse.duckdb --dbt .

init writes contextlift.yaml (with workspace: .contextlift and a starter policy: merge gate), introspects SQLite or DuckDB table/column metadata read-only into spec/schema/<table>.json, and creates spec/rules/00-definitions.md.

Add a business rule in spec/rules/00-definitions.md:

# Core business definitions
- "Active ARR" -> On `subscriptions` (`status = 'active'`): `SUM(mrr_usd) * 12`.

Run the free linter and Cross-Layer Conflict Radar before any paid model call:

contextlift lint --spec spec/ --dbt . --db warehouse.duckdb

lint checks rule hygiene, column coverage, cross-layer metric disagreements across Markdown spec/, dbt, Snowflake Semantic Views, Apache Ossie, and LookML, and live warehouse enum values. Pass --db-role ROLE on Postgres or Snowflake to enforce read-only role scoping.

Level 2: Prove a change on real SQL (10 minutes)

Build a gold answer key (golds.csv with id,question,gold_sql) from production agent failures:

contextlift ingest-failures --input prod_failures.jsonl --out review/review.csv
contextlift review --sheet review/review.csv --html --db warehouse.duckdb

Or mine BigQuery query history (filtering for multi-table analytical queries under a scan ceiling):

contextlift log --db bq://BILLING --days 90 --min-tables 2 --require-analytical --max-bytes 1GB --out log.csv
contextlift mine --db bq://BILLING --queries log.csv --out candidates.csv --write-questions

Audit the gold set and create a sealed split (directly copy-pasteable):

contextlift gate --db warehouse.duckdb --golds golds.csv --timeout 60 --clean-out golds_clean.csv
contextlift split --golds golds_clean.csv \
  --out-curate-csv curate.csv --out-holdout-csv holdout.csv \
  --out-curate curate_ids.txt --out-holdout holdout_ids.txt

gate checks every gold statement against 16 defect classes (including EXEC_FAIL, ZERO_ROWS, WHOLE_ROW, DEGENERATE, and TIMEOUT) and 4 warnings (MISSING_LITERAL, MISSING_ORDER, MISSING_PROJECTION, LITERAL_ON_WRONG_COLUMN).

Now run one paired evaluation round over the cleaned gold set (export your model key and CONTEXTLIFT_SIGN_KEY to produce a signed HMAC-SHA256 attestation):

export OPENAI_API_KEY="your-key"
export CONTEXTLIFT_SIGN_KEY="$(openssl rand -hex 32)"

contextlift round \
  --db warehouse.duckdb \
  --spec spec/ \
  --golds golds_clean.csv \
  --runner openai:gpt-4.1 \
  --target-lift 50 \
  --budget 5 \
  --out round.json \
  --attestation-out .contextlift/attestation.json

For small pilot sets (~30 questions with --target-lift 50), declare the target effect explicitly; the default +6.9 point floor needs ~60 reserved questions before round allows paid model calls.

Generate the static verdict report and pull-request summary:

contextlift bundle
contextlift pr-summary --report round.json

Level 3: Serve or compile what you proved (1 command)

Serve the verified spec directly to Claude Code, Cursor, or any MCP client over local stdio JSON-RPC 2.0:

contextlift serve-mcp --spec spec/ --attestation .contextlift/attestation.json --require-signature

get_attestation_status verifies the HMAC-SHA256 signature and spec SHA-256 hash binding, returning certified: true only when the attestation is signed, valid, matches the live spec/, achieved REAL GAIN, and passed every merge policy.

Or compile the spec back into your semantic layer:

contextlift compile --spec spec/ --target snowflake-yaml --attestation .contextlift/attestation.json --out semantic_view.yaml
contextlift compile --spec spec/ --target dbt-yaml --attestation .contextlift/attestation.json --out models/semantic_metrics.yml
contextlift compile --spec spec/ --target ossie --attestation .contextlift/attestation.json --out semantic_model.yaml

Next steps