How it works
contextlift treats business context like application code. A change to a rule, dbt metric, semantic view, or worked example does not ship on intuition; it runs in a paired experiment against real SQL execution on a held-out question set.
Two arms, one difference
Every spec/ repository compiles into two strict arms:
| Arm | Name | Contents |
|---|---|---|
| Control | Arm 0d | spec/schema/ only: the physical table and column descriptions the estate already had. |
| Treatment | Arm 1 | spec/schema/ plus authored context: rules/, authored/, vocabulary/, examples/, and relationships.yaml. |
Because Arm 0d is a strict subset of Arm 1, any accuracy delta belongs exclusively to the authored context change. Giving Arm 0d zero schema descriptions would credit authored rules for baseline metadata the warehouse already carried.
Execution accuracy as ground truth
contextlift never grades SQL by string similarity or by an uncalibrated LLM judge alone. Every predicted query and every gold query runs read-only against your real warehouse:
- Result sets are compared as normalized multisets (bag semantics for unordered queries; ordered comparison when the gold query specifies
ORDER BY). - Numeric values tolerate floating-point representation jitter (
1e-4relative tolerance); column aliases do not cause false negatives. - Every query is bounded by
--timeout(default60seconds) and--row-cap(default500rows). - Extra projected columns fail strict scoring (
MATCHvsMISMATCH), while--extra-columns toleratelets you inspect strict alongside projection-tolerant accuracy inpr-summary.
The sealed holdout firewall
A gold set is split deterministically by hash (split) into two disjoint halves:
- Working set (
curate.csv): used for failure triage (triage), rule drafting (draft-rules), patch proposals (suggest), worked-example pooling (curate-examples), and lint coverage checks. - Held-out set (
holdout.csv): never fed intodraft-rules,suggest,curate-examples, or pre-round lint coverage.roundevaluates both arms on the held-out set and records every scored holdout read in.contextlift/holdout_ledger.json. Reading the same holdout a second time triggers an interactive confirmation gate so teams cannot hill-climb on the exam.
Paired statistics: McNemar and Tango
Every question is answered by both arms, creating paired binary outcomes:
- Fixed (
c): wrong in Arm 0d, right in Arm 1. - Broke (
b): right in Arm 0d, wrong in Arm 1. - Lift:
100 * (c - b) / npercentage points (computed at the question level, never inflated by repeating the same questionKtimes).
contextlift computes two exact paired statistics:
- Exact two-sided McNemar p-value over discordant pairs
(b, c)using the binomial distribution. - 95% paired Tango score interval (
metrics.paired_difference_interval, Tango 1998 with continuity correction), which maintains nominal coverage even on small samples (n = 20to100) where unadjusted Wald intervals under-cover.
Verdict words
Every completed round produces exactly one verdict word:
| Verdict | Meaning |
|---|---|
REAL GAIN | Statistically significant positive lift (p < 0.05 and lift > 0) on held-out questions, with all validity gates passing. |
REAL LOSS | Statistically significant negative lift (p < 0.05 and lift < 0). The context actively harmed accuracy. |
NOT PROVEN | Held-out set had enough statistical power to detect the target lift, but the observed difference is not significant (p >= 0.05). |
UNDERPOWERED | Held-out set is too small to resolve --target-lift cleanly; neither a gain nor a null can be claimed. |
INVALID | A pre-flight or post-run validity gate failed (leakage, template twins, unwaived lint refusals, copied gold answers, or insufficient power). |
Safety badges
Positive average lift can hide regressions. Every verdict therefore carries an independent safety badge alongside the lift:
| Safety badge | Condition |
|---|---|
SAFE | 0 held-out questions broke (b == 0). Every movement was an improvement or unchanged. |
MIXED | Positive net lift, but at least one question that worked without context broke with it (c > b > 0). Broken question IDs are printed beside the badge. |
UNSAFE | Context broke at least as many questions as it fixed (b >= c with b > 0). |
Pre-flight refusal gates (fail closed at $0)
Before making the first paid model call, round runs six free checks and stops if any fail:
- Table coverage: confirms the arm exposes the tables named by the golds.
- Project match: catches cross-project BigQuery references before billing.
- Resolvable lift: refuses question sets too small to prove
--target-lift(6 unanimous flips is the smallest exact McNemar result atp < 0.05). - Leakage & template twins: refuses any context containing a held-out question, held-out SQL, or structurally identical worked-example template twin.
- Context lint: runs
lint(including live--dbenum literal checks when--dbis set) and refuses on hard defects unless explicitly waived with--allow-lint-refusals(recorded in the manifest). - Budget and confirmation: requires an explicit
--budgetceiling on paid calls and interactive/dev/ttyconfirmation (or signed CI approval token).
Rule attribution and bisection
When a round fixes or breaks questions, attribute parses the SQL ASTs of baseline and treatment queries to score which specific rule lines or terms explain each flip. Suspect rules are leads rather than final proof; bisect confirms causality by binary-searching the rule set to isolate the exact offending rule.
For the full statistical proofs and historical derivation, see docs/research/METHODOLOGY.md and docs/research/ATTRIBUTION.md.