Metadata-Version: 2.5
Name: contextlift
Version: 0.3.0
Summary: GitHub-native Context CI for AI SQL agents, dbt semantic layers, and enterprise warehouses: lint cross-layer conflicts, prove SQL lift on sealed holdouts, and serve certified context over MCP.
Project-URL: Homepage, https://github.com/moutasemalakkad/context-lift
Project-URL: Documentation, https://moutasemalakkad.github.io/context-lift/
Project-URL: Repository, https://github.com/moutasemalakkad/context-lift
Project-URL: Changelog, https://github.com/moutasemalakkad/context-lift/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/moutasemalakkad/context-lift/issues
Author-email: Moutasem Akkad <moutasemalakkad@gmail.com>
Maintainer-email: Moutasem Akkad <moutasemalakkad@gmail.com>
License: Apache-2.0
License-File: AUTHORS
License-File: LICENSE
License-File: NOTICE
Keywords: bigquery,context-engineering,data-engineering,dbt,duckdb,mcp,semantic-layer,snowflake,sql-evaluation,text-to-sql
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Provides-Extra: bigquery
Requires-Dist: google-cloud-bigquery>=3.0; extra == 'bigquery'
Provides-Extra: ca
Requires-Dist: google-cloud-geminidataanalytics>=0.13; extra == 'ca'
Provides-Extra: catalog
Requires-Dist: google-cloud-dataplex>=2.0; extra == 'catalog'
Provides-Extra: databricks
Requires-Dist: databricks-sql-connector>=3.0; extra == 'databricks'
Provides-Extra: dev
Requires-Dist: duckdb>=1.0; extra == 'dev'
Requires-Dist: google-cloud-dataplex>=2.0; extra == 'dev'
Requires-Dist: google-cloud-geminidataanalytics>=0.2; extra == 'dev'
Requires-Dist: lkml>=1.3.7; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: pyyaml>=6; extra == 'dev'
Provides-Extra: duckdb
Requires-Dist: duckdb>=1.0; extra == 'duckdb'
Provides-Extra: gemini
Requires-Dist: google-genai<3.0.0,>=1.0; extra == 'gemini'
Provides-Extra: lookml
Requires-Dist: lkml>=1.3.7; extra == 'lookml'
Provides-Extra: postgres
Requires-Dist: psycopg[binary]>=3.1; extra == 'postgres'
Provides-Extra: snowflake
Requires-Dist: snowflake-connector-python>=3.0; extra == 'snowflake'
Provides-Extra: yaml
Requires-Dist: pyyaml>=6; extra == 'yaml'
Description-Content-Type: text/markdown

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/moutasemalakkad/context-lift/v0.3.0/docs/assets/wordmark-dark.svg">
    <img alt="contextlift" src="https://raw.githubusercontent.com/moutasemalakkad/context-lift/v0.3.0/docs/assets/wordmark-light.svg" width="400">
  </picture>
</p>

<h3 align="center">CI for the context your SQL agent reads.</h3>

<p align="center">Rules, dbt metrics, semantic views, LookML: every change gets a verdict before it merges.</p>

<p align="center"><a href="https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/docs/quickstart.md">Quickstart</a> &nbsp;&middot;&nbsp; <a href="https://moutasemalakkad.github.io/context-lift/">Docs &amp; live verdict</a> &nbsp;&middot;&nbsp; <a href="https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/docs/how-it-works.md">How it decides</a> &nbsp;&middot;&nbsp; <a href="#install">Install</a></p>

<br>

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/moutasemalakkad/context-lift/v0.3.0/docs/assets/verdicts-dark.svg">
  <img alt="Three context changes, three verdicts. Definitions written by people: +23.1 points, REAL GAIN. BI metadata scraped from LookML: +2.0 points, NOT PROVEN. Perfect retrieval instead of the full 22 KB: -8.6 points, REAL LOSS." src="https://raw.githubusercontent.com/moutasemalakkad/context-lift/v0.3.0/docs/assets/verdicts-light.svg" width="100%">
</picture>

<p align="center"><b>Some context helps. Some does nothing. Some makes your agent worse.</b><br>
<sub>Each row is a paired run: same model, same questions, one context change. Every number is pinned by a test to a committed run.</sub></p>

<br>

```sh
uvx contextlift demo    # no key, no cloud: canned answers, real SQL, the real paired test
```

## 1 &nbsp; Lint what you already have

`2 minutes` &nbsp; `$0` &nbsp; `no questions needed`

```console
$ contextlift lint --spec spec/ --dbt dbt/ --db warehouse.duckdb

  [REFUSE] invalid enum literal: 00-finance:1
  [REFUSE] cross-layer metric conflict: Active ARR (dbt vs spec)

2 refusal(s). Fix these before paying for a round: each one was measured to cost more than it takes to fix.
```

Your rule says `'ACTIVE'`, the warehouse holds `'active'`, and dbt counts trials as Active ARR while your spec does not. No model was called.
`lint` reads Markdown rules, dbt, Snowflake Semantic Views, Apache Ossie and LookML. Run it as the `contextlift-lint` pre-commit hook, or on every pull request:

```yaml
# .github/workflows/context.yml
on: pull_request
permissions: { contents: read, pull-requests: write }
jobs:
  context:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: moutasemalakkad/context-lift@v0.3.0   # lints, comments on the PR, fails on a refusal
        with: { spec-dir: spec/, dbt-dir: dbt/ }
```

## 2 &nbsp; Prove a change on real SQL

`10 minutes` &nbsp; `your warehouse` &nbsp; `any agent`

Write down what the agent should know, and what a right answer looks like:

```text
# spec/rules/00-finance.md
- "Active ARR" -> SUM(subscriptions.mrr_usd) * 12 WHERE subscriptions.status = 'active'

# golds.csv: a few dozen questions your users really ask, with the SQL that answers each
id,question,gold_sql
q1,What is active ARR?,SELECT SUM(mrr_usd) * 12 FROM subscriptions WHERE status = 'active'
q2,How many trials are running?,SELECT COUNT(*) FROM subscriptions WHERE status = 'trial'
```

Then run the same questions twice, once without the context and once with it:

```sh
contextlift init --db warehouse.duckdb                                 # writes contextlift.yaml + schema/
contextlift round --runner openai:gpt-4.1 --budget 5 --out round.json  # two arms, one verdict
contextlift bundle                                                     # .contextlift/verdict.html
contextlift pr-summary --report round.json                             # the comment below
```

Swap in `anthropic:MODEL`, `gemini`, any OpenAI-compatible server (`--base-url`: Ollama, vLLM) or your own agent (`--runner command`), or score two CSVs of answers you already have.
Every query runs read-only and row-capped, as the `--db-role` you pass. A question set too small to decide is refused before the first paid call.

<img alt="The pull-request comment: verdict, held-out lift with its interval, questions fixed and broken, Conflict Radar, cost per correct answer, and the rule lines that moved each answer." src="https://raw.githubusercontent.com/moutasemalakkad/context-lift/v0.3.0/docs/assets/pr-summary.png" width="100%">

## 3 &nbsp; Serve what you proved

`1 command`

```sh
contextlift serve-mcp --spec spec/ --attestation .contextlift/attestation.json
```

A local stdio MCP server for Claude Code, Cursor or any MCP client: six tools over your spec, from `get_metric` to `get_attestation_status`, which verifies the round's sealed HMAC integrity and spec hash binding. Or compile the spec into the layer you already run:

```sh
contextlift compile --spec spec/ --target snowflake-yaml    # or dbt-yaml, ossie
```

<details>
<summary><b>Three results that changed what we build</b>, and every number behind the chart</summary>
<br>

**Sending everything beat perfect retrieval.** Giving each question only its own sentence instead of all 22 KB scored -2.2 points across 450 questions (NOT PROVEN) and -8.6 points [-17.0, -0.8] on Toxicology: 7 fixed, 19 broke, p = 0.0290, REAL LOSS. [Run](https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/docs/evidence/blob-vs-selection.txt)

**A BI model with no descriptions is not context.** LookML read straight into rules: +2.0 points over 102 questions, p = 0.6875, NOT PROVEN. Looker's public project also says `orders.id` where the warehouse has `orders.order_id`. [Run](https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/examples/thelook/lookml-arm/round-2026-09-12.txt)

**Models almost never ask for more.** Told to answer INSUFFICIENT rather than guess: 2 of 139 questions escalated, 1.4%. The run had no positive control, so it cannot tell a model that will not escalate from a prompt it ignores. [Run](https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/docs/evidence/self-route.txt)

The headline row, recomputed offline from committed predictions with `make example-bird` (no key, no network):

<!-- headline:example-bird -->
```
paired ablation on 39 questions (execution accuracy)
  without context :  30.8%  [18.6%, 46.4%]
  with context    :  53.8%  [38.6%, 68.4%]
  lift            : +23.1%  [+1.2%, +43.6%]   (the two rates subtracted; 95% interval on the paired difference)

  context fixed   : 12 questions
  context broke   : 3 questions
  McNemar p       : 0.0352   significant at 0.05
  one repetition per arm: a single sample, not a measurement; run each arm again before quoting this

  ruling          : REAL GAIN
```

Every published result:

| Context change | Questions | Lift, points [95% CI] | p | Verdict |
|:--|--:|:--|--:|:--|
| BIRD evidence sentences written by people, 3 databases (K=1, no holdout split) | 39 | **+23.1** [+1.2, +43.6] | 0.0352 | REAL GAIN |
| BIRD evidence sentences, 11 databases (25.4% selective coverage, oracle table routing) | 65 | **+18.5** [+4.6, +32.7] | 0.0044 | REAL GAIN |
| BEAVER verified-query worked examples, 97-table warehouse | 69 | **+10.1** [+0.2, +21.8] | 0.0391 | REAL GAIN |
| LookML read into rules, no written descriptions | 102 | +2.0 [-4.8, +9.3] | 0.6875 | NOT PROVEN |
| Oracle selection vs the 22 KB blob, 3 databases | 450 | -2.2 [-5.9, +1.4] | 0.2451 | NOT PROVEN |
| Oracle selection vs the 22 KB blob, Toxicology | 139 | -8.6 [-17.0, -0.8] | 0.0290 | REAL LOSS |

On BEAVER the worked examples came after hand-written rules scored -0.7 on the working set. Intervals are paired score intervals. [results.json](https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/docs/assets/results.json) names the committed file and the test behind every row.

**WITHDRAWN:** an earlier worked-examples penalty on thelook was one schema, one model, one run, and a scoring bug: `_cmd_classes` graded 22 stored-answer hits as errors. Raw run in [docs/evidence/classes-thelook-cost.txt](https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/docs/evidence/classes-thelook-cost.txt), postmortem in [docs/results.md](https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/docs/results.md).

</details>

## Install

```sh
pip install contextlift                 # zero dependencies: SQLite, lint, the stats, the verdict
pip install "contextlift[duckdb,yaml]"  # or [postgres] [snowflake] [databricks] [bigquery] [lookml]
```

**Warehouses** &nbsp; DuckDB, SQLite, BigQuery. Postgres, Snowflake and Databricks in beta.<br>
**Context** &nbsp; Markdown rules, dbt `schema.yml` and `manifest.json`, Snowflake Semantic Views, Apache Ossie, LookML.<br>
**Agents** &nbsp; OpenAI, Anthropic, Gemini, Ollama or vLLM, your own CLI agent, or answers in a CSV.

Eight verbs complete one measurement: `demo` `doctor` `gate` `split` `lint` `round` `bundle` `next`. `contextlift --help` lists those eight. `contextlift --help-all` lists the rest, grouped.

[Quickstart](https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/docs/quickstart.md) &middot; [How it works](https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/docs/how-it-works.md) &middot; [CI setup](https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/docs/guides/ci.md) &middot; [Warehouses &amp; agents](https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/docs/guides/connect.md) &middot; [CLI reference](https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/docs/reference/cli.md) &middot; [Security](https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/docs/security.md) &middot; [Contributing](https://github.com/moutasemalakkad/context-lift/blob/v0.3.0/CONTRIBUTING.md)

<sub>`src/context_lift/` is the package: 8 core verbs, every number on this page pinned by `tests/` to a run in `docs/evidence/` or `examples/`. `make test` runs green from a fresh clone, no credentials. Apache-2.0.</sub>
