Repository avatar
Developer Tools
v0.3.2
active

contextlift

io.github.moutasemalakkad/contextlift

Certified read-only business context MCP server backed by contextlift specs and attestations.

Documentation

contextlift

CI for the context your SQL agent reads.

Rules, dbt metrics, semantic views, LookML: every change gets a verdict before it merges.

Quickstart  ·  Docs & live verdict  ·  How it decides  ·  Install


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.

Some context helps. Some does nothing. Some makes your agent worse.
Each row is a paired run: same model, same questions, one context change. Every number is pinned by a test to a committed run.


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

1   Lint what you already have

2 minutes   $0   no questions needed

$ 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:

# .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.2   # lints, comments on the PR, fails on a refusal
        with: { spec-dir: spec/, dbt-dir: dbt/ }

2   Prove a change on real SQL

10 minutes   your warehouse   any agent

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

# 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:

export OPENAI_API_KEY="your-key"                                        # or score two CSVs offline ($0)
export CONTEXTLIFT_SIGN_KEY="$(openssl rand -hex 32)"                   # signs .contextlift/attestation.json
contextlift init --db warehouse.duckdb                                  # writes contextlift.yaml + schema/
contextlift round --runner openai:gpt-4.1 --target-lift 50 --budget 5 \
  --out round.json --attestation-out .contextlift/attestation.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 (with --db-role scoping on Postgres and Snowflake). A question set too small to decide is refused before the first paid call (~30 questions with --target-lift 50; default +6.9 needs ~60 reserved).

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.

3   Serve what you proved

1 command

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

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:

contextlift compile --spec spec/ --target snowflake-yaml --attestation .contextlift/attestation.json    # or dbt-yaml, ossie
Three results that changed what we build, and every number behind the chart

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

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

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

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

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 changeQuestionsLift, points [95% CI]pVerdict
BIRD evidence sentences written by people, 3 databases (K=1, no holdout split)39+23.1 [+1.2, +43.6]0.0352REAL GAIN
BIRD evidence sentences, 11 databases (25.4% selective coverage, oracle table routing)65+18.5 [+4.6, +32.7]0.0044REAL GAIN
BEAVER verified-query worked examples, 97-table warehouse69+10.1 [+0.2, +21.8]0.0391REAL GAIN
LookML read into rules, no written descriptions102+2.0 [-4.8, +9.3]0.6875NOT PROVEN
Oracle selection vs the 22 KB blob, 3 databases450-2.2 [-5.9, +1.4]0.2451NOT PROVEN
Oracle selection vs the 22 KB blob, Toxicology139-8.6 [-17.0, -0.8]0.0290REAL 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 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, postmortem in docs/how-it-works.md#results.

Install

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

Warehouses   DuckDB, SQLite, BigQuery. Postgres, Snowflake and Databricks in beta.
Context   Markdown rules, dbt schema.yml and manifest.json, Snowflake Semantic Views, Apache Ossie, LookML.
Agents   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 · How it works · CI setup · Warehouses & agents · CLI reference · Security · Contributing

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.

DOI

PYPI
contextlift
Install Command
pip install contextlift
Runtime: uvx