Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
8e374a5
Expose relational keys and evaluate evidence-based SQL review
seyoung4503 Nov 26, 2026
9d8ebb1
Diagnose baseline errors and accept commented read-only final SQL
seyoung4503 Nov 26, 2026
6bdd686
Supply pinned official BIRD schema descriptions without gold annotations
seyoung4503 Nov 26, 2026
6f3baff
Include hash-pinned Spider schema and sample metadata in optional con…
seyoung4503 Nov 26, 2026
489660b
Document review protocol, metadata provenance and verification
seyoung4503 Nov 26, 2026
a207da1
Clarify missing query constraints without inventing filters from back…
seyoung4503 Nov 26, 2026
e220c0a
Compare Responses API with opaque reasoning continuity and shared bud…
seyoung4503 Nov 26, 2026
d6ae724
Serialize Responses items using wire aliases and omit null SDK fields
seyoung4503 Nov 26, 2026
7a51b9f
Normalize Responses token accounting for existing benchmark summaries
seyoung4503 Nov 26, 2026
77660a5
Document reasoning continuity trials and clarification boundary
seyoung4503 Nov 26, 2026
fafab98
Stop on exhausted provider credits and publish all accuracy trials
seyoung4503 Nov 26, 2026
39dbcd9
Evaluate ChatGPT Codex through Lang2SQL MCP and compare fixed benchma…
seyoung4503 Nov 26, 2026
60e4f9c
Align MCP clarification with explicit request criteria and pin evalua…
seyoung4503 Nov 26, 2026
0381343
Verify actual MCP SQL execution and preserve result types for agent r…
seyoung4503 Nov 26, 2026
12b81cd
Fix MCP execution evidence grading and document Spider failure traces
seyoung4503 Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions bench/accuracy/CODEX_MCP_RESULTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Latest correction and targeted review (2026-11-27)

The execution verifier now accepts the SQL returned by a successful MCP result,
including the server-added LIMIT, as well as the submitted SQL under the existing
capped-execution contract. It does not strip arbitrary limits or accept blocked
responses. Official result comparison is unchanged. Original records are retained;
regrading makes no model calls and does not change final answers.

| Sol/high, same 20 development cases | v3 corrected | v4 guidance update |
|---|---:|---:|
| BIRD Mini-Dev SQLite | 18/20 | 19/20 |
| Spider 2.0-Lite SQLite | 10/20 | 10/20 |

Evidence: `mcp-review-results/` contains manifests, settings, per-case scores and
full recorded MCP calls/final answers with source-record hashes. Internal API call
counts are unknown, not zero. v4 source snapshots and patch were recorded before
execution. These are exposed development cases, not full-set or holdout scores.

## Spider remaining failures

- local041: DISTINCT changes the population; removing deduplication reproduces 78.1472656.
- local335: extra constructor-points filter excludes affiliations; removing it reproduces the reference teams/counts.
- local264: model table has regression=213; agent observes this but chooses filtered stack_ok=114.
- local194: per-film actor share calculated, but average over each actor's top three films omitted.
- local062: nonbuyers zero-filled, adding 7712 customers to the first bucket (7741 vs29); wording/population ambiguity remains.
- local073: NOCASE changes ingredient string ordering; string-internal order is graded literally.
- local064: all eight tied minimum months returned vs one reference month; tie policy underspecified. Including empty months is NOT itself the error.
- local003/local202/local279: clarification without final SQL; distinguish genuine ambiguity from repeated lookup of definitions already supplied in the request.

Shared guidance now asks for population, grain, source, quantile policy and final
output checks. This is probabilistic guidance, not a semantic correctness guard.
It fixed local004 but regressed local041; no net Spider improvement is claimed.
Do not inject reference SQL, force guesses, or adjust official grading to hide these failures.

---

# Codex MCP comparison — fixed development questions

Executed with ChatGPT-authenticated Codex CLI, not the exhausted API credential.
Each suite uses exactly the same original 20 development IDs as the API baseline.
These are development diagnostics, not full 135/500 scores or independent holdout
accuracy. Model/API/input differences mean this is not an isolated MCP-effect study.

| Same 20 questions | Previous API baseline | Codex final SQL, executed offline | Codex → Lang2SQL MCP end-to-end |
|---|---:|---:|---:|
| spider | 10/20 (50%) | 3/20 (15%) | 0/20 (0%) |
| bird | 18/20 (90%) | 12/20 (60%) | 0/20 (0%) |

The offline column re-executes only the final fenced SQL from the same Codex
trajectory, unchanged, using the official comparator. It is a secondary diagnostic
added after observing the MCP blockade, **not successful MCP execution**. Missing
SQL/clarifications stay in the full 20-question denominator. No model was rerun
or answer chosen using gold. The MCP column additionally requires final SQL to
have actually executed through the production MCP server.

## Why the result differs

- spider: 20/20 blocked by definition confirmation; 0 run_sql calls; 4/20 final SQL outputs. Compared with baseline final SQL, 0 previously wrong answers became correct and 7 previously correct became wrong.
- bird: 20/20 blocked by definition confirmation; 0 run_sql calls; 13/20 final SQL outputs. Compared with baseline final SQL, 1 previously wrong answers became correct and 7 previously correct became wrong.

The MCP runtime is deliberately fresh per case: no registered business definitions
or prior answers. `ResolveBusinessTerms` requires a nonempty list of exact confirmed
metadata entries; its schema rejects an empty list even for questions expressed
only in literal SQL fields. Question text and official schema/evidence do not
become approved entries. Thus Codex may understand the request and write SQL, but
cannot execute it through this MCP contract. This is a product integration limit,
not evidence that Codex intrinsically has zero SQL accuracy.

No definition guard was disabled and no fabricated/gold-derived definitions were
registered. A full 635-case MCP replay was not launched after all 40 pilot cases
failed to reach SQL execution; the same deterministic blocker must be addressed
before a meaningful full end-to-end comparison.

The next implementation needs to distinguish literal field queries from ambiguous
business definitions and safely accept explicit user-provided criteria without
inventing policy. Test that missing definitions still stop execution, then repeat
this same fixed comparison before the full run. The 95% target remains unmet.

## Protocol and evidence

- Codex CLI default model, no model override; exact resolved model is not exposed in captured events.
- User configuration, shell, unified execution, apps and web search disabled for these invocations. Only the three read-only Lang2SQL MCP tools were enabled.
- Same pinned SQLite DBs and official graders; official schema metadata and per-question evidence supplied. Gold SQL/results never enter Codex input.
- Two concurrent cases per suite; 600s case deadline; 30s offline SQL deadline; 100,000 rows.
- ChatGPT login checked locally; no API credential file loaded. Each question has a new ephemeral session and in-memory metadata store.
- All 40 Codex invocations completed. CLI usage is recorded separately; internal API-call counts are unavailable and must not be reported as zero calls.
- [Case-by-case comparison](codex-mcp-results/comparison.json), manifests, settings, scores and compact records retain both successful and failed results. Original events remain under `/Users/seyoung/workspace/benchmarks/codex-mcp-20261126`.

Reproduce with `python -m bench.accuracy.codex_mcp --help`, then the existing
`bench.accuracy.evaluate score` command with the same DBs and official grader.
The extracted-SQL diagnostic derives from those recorded answers, not a new run.

Validation: 239 tests passed, 1 skipped. Runner checks forbid counting unexecuted
SQL, non-MCP tools or a diagnostic-query fallback after clarification as MCP success.
117 changes: 117 additions & 0 deletions bench/accuracy/IMPROVEMENT_RESULTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Accuracy investigation and incomplete follow-up

**The requested 95% on both benchmarks was NOT reached.** This PR contains
verified implementation fixes and all measured experiments, not a claim of
successful benchmark improvement. It remains draft pending a complete replay.

| Benchmark | Previous complete baseline | Completed intermediate replay | Latest revised product |
|---|---:|---:|---|
| Spider 2.0-Lite SQLite 135 | 81/135 (60.00%) | 78/135 (57.78%), regression | Full-v3 interrupted; no score |
| BIRD Mini-Dev SQLite 500 | 434/500 (86.80%) | Full-v2 interrupted; no score | Full-v3 interrupted; no score |

Spider v2 used product `6f3baff`, Sol high reasoning, official schema metadata,
32 API attempts, 16,384 output tokens, no extra review. It had zero API errors
and 12 failed predictions, all retained in the denominator. **Do not call this
setting an accuracy improvement or replace the baseline with a best-of-runs score.**

Latest product `7a51b9f` additionally fixes unnecessary clarification and provides
an optional Responses API path. Its full-v3 runs were stopped after an isolated
API probe confirmed HTTP 429, code `credit_balance_exhausted`, type
`insufficient_quota`, with no Retry-After. This was account credit exhaustion,
not evidence of model failure or an ordinary transient request-rate limit.
The old retry logic treated it as a general RateLimitError and emitted many
failed attempts before diagnosis. No API calls are left running.

## Interrupted attempts (not accuracy)

| Run | Recorded / planned | Failed records | API error attempts |
|---|---:|---:|---:|
| bird-full-v2 | 421/500 | 102 | 190 |
| bird-full-v3 | 348/500 | 267 | 545 |
| spider-full-v3 | 35/135 | 35 | 70 |

All existing records are preserved. Missing/cancelled cases are not silently
removed or scored as successes. No partial-run percentage is published. Full-v3
increased concurrency to 12 per suite; this did not remedy the account quota.
Resumption requires restored API credits and a **fresh complete run**, not
cherry-picking successful answers from these attempts.

## Development experiments (all reported)

| Suite | Official metadata | Model | Initial output | After extra review |
|---|---|---|---:|---:|
| spider | False | sol-reviewed (high Chat) | 11/20 | 10/20 |
| spider | False | astra-reviewed (high Chat) | 11/20 | 10/20 |
| spider | True | sol-reviewed (high Chat) | 11/20 | 10/20 |
| spider | True | astra-reviewed (high Chat) | 11/20 | 11/20 |
| spider | True | sol-responses-max | 12/20 | Not run |
| spider | True | astra-responses-max | 9/20; 5 quota-related failures | Not run |
| bird | False | sol-reviewed (high Chat) | 19/20 | 19/20 |
| bird | False | astra-reviewed (high Chat) | 19/20 | 19/20 |
| bird | True | sol-reviewed (high Chat) | 18/20 | 18/20 |
| bird | True | astra-reviewed (high Chat) | 19/20 | 19/20 |
| bird | True | sol-responses-max | 17/20 | Not run |
| bird | True | astra-responses-max | 18/20 | Not run |

The BIRD 19/20 result is only a 20-question selection pilot: **not 95% over
BIRD500**. Spider Astra Responses was contaminated by credit exhaustion and is
not a fair model-quality comparison. All its failures remain in the denominator.
Review evaluates the initial and final answer of the same trajectory; initial
logs include later review costs and are not a no-review latency estimate.

Selections were frozen from the original development pilots before each full
run; no full-set score or per-question gold-selected answer routing was used.
V3 selected BIRD Astra high Chat with official metadata and Spider Sol max
Responses with metadata, both without review. Because an alternative trial was
quota-limited, this is provisional, not evidence of the optimal model.
Exact limits and source hashes are in each settings/selection file. Changes in
model, API, budgets and metadata prevent an isolated causal interpretation.

## Implemented fixes and evidence

- Preserve primary/composite foreign keys through SQLAlchemy reflection and the existing schema tool.
- Accept SELECT/WITH answers beginning with SQL comments; still reject writes.
- Supply optional pinned official schema descriptions/examples, without gold annotations.
- Check source columns, join multiplicity, aggregation grain, rate denominators, missing-value representations and exact output types.
- Eliminate clarification about background prose when the actual query already specifies its constraints. Real-API bird140 check: 1/1 correct. Undefined actor-ranking policy local195: still asks, officially 0/1.
- Add optional review and opaque Responses reasoning continuity; reuse the existing agent loop and provider retry budget. No frontend default change.
- After the quota incident, fail immediately on structured insufficient-quota/credit-exhausted errors, cancel queued/in-flight batch tasks, and persist an aborted status. Ordinary rate limits retain bounded retries. Partial runs cannot be scored. This fix is unit-tested; a paid API replay is blocked by the exhausted account.

## Remaining work

[Baseline diagnosis](diagnostics/README.md) inventories all 120 original errors.
The completed Spider v2 still has 57 errors. Some are wrong SQL result semantics;
others are clarification about genuinely missing definitions. Those questions
remain incorrect under the official noninteractive benchmark. Increasing model
budget cannot supply an absent business policy. No ambiguity guard was disabled.

The entire old evaluation set has now been inspected, so subsequent same-set
scores are **development-exposed public regression scores**, not independent
holdout accuracy. Official graders, tolerances and reference answers are
unchanged. No benchmark gold was supplied to inference. No 95% Oracle,
Codex-MCP, production accuracy or memory-effect claim is justified.

Next: restore API credits, rerun quota-contaminated model comparison and then a
fresh frozen full 135/500 evaluation. Investigate residual semantic errors from
that complete run; validate future claims on independent data. This PR does not
promise that those steps alone will reach 95%.

## Evidence and reproduction

[Machine-readable report](improvement-results/report.json) records completed and
interrupted attempts. Every trial includes manifests/settings, available
per-case scores, compact records with SQL/answers/calls, and hashes of raw
transcripts/CSVs. Original full transcripts stay local under
`/Users/seyoung/workspace/benchmarks/accuracy-improvement-20261126`.
All recorded `ingest_doc` audits were empty; no file reads through that tool were
observed. The harness is not an OS sandbox, so this is an input/audit claim, not
an OS isolation guarantee.

Use the [benchmark CLI](README.md#reproduce), copied profile/selection files,
matching pinned DBs and fresh output directories. Never overwrite these
attempts or combine their correct answers. All API tasks were stopped on quota
exhaustion; no unattended paid work remains.

Validation: **237 passed, 1 skipped**, changed-code Ruff and whitespace checks.
[Implementation verification](diagnostics/VERIFICATION.md).
[Draft PR #321](https://github.com/CausalInferenceLab/Lang2SQL/pull/321).
62 changes: 62 additions & 0 deletions bench/accuracy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,65 @@ configuration. Changing the model, prompt, budget or source creates a new
experiment; historical scores under different configurations are not paired
improvement measurements. `--split all` is for a new explicitly reported full
public-dev run, not a way to hide development-set selection.


## Accuracy improvement experiment

See [diagnostics](diagnostics/README.md) for all baseline errors and the new
protocol. Old holdout questions have now been inspected: subsequent replays are
**development-exposed public-set results**, not independent held-out accuracy.

New optional flags (baseline defaults remain unchanged):

```sh
# Choose the appropriate pinned schema map for the suite.
--schema-docs bench/accuracy/bird-schema.json
--schema-docs bench/accuracy/spider2-schema.json
# Number of additional measured SQL-review turns; 0 by default.
--review-rounds 1
```

Review uses the existing agent loop and the same total API/time budget. It does
not see gold, and the last answer is scored even if review makes it worse. A
clarifying/non-SQL answer is never overridden to force a prediction. Schema maps
contain official metadata/examples only; their exact file hashes are validated
before any model call and recorded in settings. Optional context changes are
reported as part of the treatment, not attributed solely to model or prompt.


An optional profile `"api": "responses"` (see `models-responses.json`) compares
Responses with Chat Completions. It retains provider-returned opaque reasoning
items across tool calls for the exact message prefix and tool definitions, with
`store=false`; it does not add provider types to the core domain or enable a
second retry loop. The cache is bounded by the case call budget and is never
shared between cases. Profile settings and returned/replayed item counts are
recorded. Higher reasoning effort is an experiment, not an assumed improvement.
The production frontend/provider default is unchanged.


Latest outcome: [investigation and incomplete follow-up](IMPROVEMENT_RESULTS.md).
The 95% target was not reached; full-v3 stopped on account credit exhaustion.
Structured account-quota errors now abort the batch without retrying every
remaining question. Ordinary transient rate limits keep the configured bounded
retry. An aborted/partial run cannot publish an accuracy score.


## ChatGPT-authenticated Codex MCP experiment

[Same-question comparison and limitations](CODEX_MCP_RESULTS.md).
The real production MCP path can be evaluated without loading an API key:

```sh
PYTHONPATH=src:. uv run python -m bench.accuracy.codex_mcp \
--root "$SPIDER" --db-dir "$BIRD_DB" \
--manifest bench/accuracy/bird-manifest.json \
--schema-docs bench/accuracy/bird-schema.json \
--split development --output "$RUN"
```

Use the matching Spider manifest/schema map and DB directory for Spider. Requires
Codex CLI ChatGPT login. A final SQL block counts as MCP success only if the same
SQL actually ran through the production `run_sql` tool. Missing definitions are
not silently seeded or bypassed. The default model is left to Codex; no resolved
model identifier is asserted. Internal API calls are not observable, so report
CLI invocations and captured usage separately from API-harness measurements.
Loading