Grounded document extraction. Every value ships with its verbatim quote + page + bbox — or it doesn't ship.
*Output of `-F "annotate=true"`: every cited value highlighted. Table rows cited per-cell.*Local machinery resolves everything nameable for $0; the model only sees the residue (sellers, skills, clauses). A small model exposes gaps instead of papering over them — each gap becomes a deterministic fix.
- Measured: gpt-6-luna seller/name/title/skills 97–100% on real CVs, all grounded, ~$0.0013/doc.
- Limits: inferred dates ("end of calendar year" → 12/31) need judgment; 200-page SEC nuance exceeds small-model discipline.
deep=trueor a bigger model covers it; the ledger prices it exactly. - Rule: never upgrade the model to fix what an anchor can fix. Eval fails first, machinery second, model last.
Three tiers, cheapest first. Each tier only sees what the previous couldn't cite:
flowchart LR
D[PDF/DOCX] --> P[parse: pages + tables + bboxes]
P --> L[local / table / pii: $0]
L -->|unmatched| S[small model: $0.001/doc]
S -->|miss or ungrounded + escalate| B[big model: metered]
B --> H[honest null, never invented]
- Local (
local,table,piisources) resolves everything nameable: dates, totals, sections, sweeps, rows. $0. - Small (
MODEL, default gpt-6-luna;source: llm-small) takes the residue: sellers, skills, clauses. Single targeted pass. - Big (
MODEL_BIG, unset by default;source: llm-big) fires only on fields flagged"escalate": truethat come back missed or ungrounded. deep=truewidens the small pass to all unmatched fields; it does not trigger big-tier (big needsescalate+ a miss regardless).- Every tier answers to the same grounding gate, and
meta.costitemizes each call by model.
Four strategies per field, declared in the pack — not chosen at runtime:
| strategy | cost | source values |
what it does |
|---|---|---|---|
local |
$0 | local |
fuzzy anchor search → span → normalize → ground. Dates, totals, sections, law. |
table |
$0 | table |
header match → rows as items with per-cell bboxes. Line items. |
pii |
$0 | pii |
full-doc sweep, all occurrences + bboxes. Emails, phones, SSNs, cards, IBANs. |
llm |
metered | llm-small, llm-big |
single pass for what can't be named: sellers, skills, clauses. Verified locally, same gate. |
No value bypasses grounding. grounded: false means flagged, never silently trusted.
pip install -r requirements.txt
python api.py
curl -X POST -F "file=@invoice.pdf" -F "pack=invoice" http://localhost:5000/analyzeOr the CLI (same core, no server):
pip install -e . # exposes the `qleric` command
qleric invoice.pdf --pack invoice
qleric resume.pdf --pack resume --deep --annotate -o out.json
qleric --smoke # import every module + keyless query per packDocker: docker build -t qleric . && docker run -p 5000:5000 -e API_KEY=... qleric
{
"fields": {
"total_amount": {
"value": "$1,240.00", "verbatim": "Total Due $1,240.00",
"page_number": 1, "bbox": [[x0, y0, x1, y1]],
"grounded": true, "source": "local"
}
},
"meta": {"format": "PDF", "pages": 1, "grounding_rate": "4/8",
"cost": {"calls": 1, "prompt_tokens": 1436,
"completion_tokens": 179, "cost_usd": 0.000323},
"retrieval": {"budget": 12000, "chars": 1436, "fallback": false,
"fields": {"seller": {"keys": 2, "windows": 1, "sent": 1}}}}Works with no keys: LLM fields return value: null + note: "No API key...".
Copy example.env → .env and add API_KEY to enable them. No hosted key, no signup.
-F "pack=resume|pii|contract", -F "deep=true" (LLM over all unmatched — small pass only; local sections that miss stay missed, big tier still needs escalate + a miss), -F "annotate=true" (highlighted PDF).
api.pyis a dev server. For anything networked:gunicorn api:appbehind auth + reverse proxy — it spends your LLM key per request. Python:from qleric import parse, query; query(parse(data, "pdf"), INVOICE_FIELDS).
| mode | key | use |
|---|---|---|
| Offline (default) | none | parse, local spans, tables, highlights, MCP tools |
| BYOK | API_KEY + MODEL (+ BASE_URL) |
any OpenAI-compatible endpoint — Claude, OpenAI, Gemini, Ollama. Single pass, locally verified. |
| MCP (experimental) | none in our process | python -m qleric.mcp: read_pages, find_quote, annotate — stdio smoke-tested, no real client yet. Your assistant reasons, our core grounds. |
No hosted key, no vendor SDK. Keys never logged, .env gitignored.
meta.cost on every response: calls, tokens in/out, USD. Keyless runs are $0 by construction (no LLM called).
| run | calls | tokens in/out | cost |
|---|---|---|---|
| 8 CUAD, luna-only (Nov 12) | 8 | 59,703 / 2,210 | $0.0103 |
| 127 mixed, luna-only (Nov 11, pre-retrieval baseline) | 127 | ~50k / ~19k | ~$0.01 |
| 90-case corpus, keyless (all runs) | 0 | 0 / 0 | $0 |
| 5 CUAD escalation, sparse ctx (Nov 12) | 10 | 69,709 / 7,195 | $0.0851 — 0 additional closes |
| 8 CUAD escalation, dense retrieval (Nov 13, historical snapshot n=8) | 16 | 37,854 / 7,566 | $0.0634 — then-current: termination 62→88%, non-compete 100% (small sample; current blind numbers in Evals table below) |
| The two escalation rows are the thesis in numbers: a big model on a raw dump closes nothing; the same model on dense retrieval converts. Retrieval, not reasoning. |
Seeded synthetic corpus (evals/generate.py) + private real-doc validation:
| suite | result |
|---|---|
| 105 synthetic (invoice / resume / PII / contract) | 100% offline fields incl. 15 governing-law cases with incorporation decoys, 0 false grounds |
| 537-case corpus, key live (Nov 16) | 536–537/537 (luna on llm-strategy fields; single flapping miss across runs, 0 false grounds, 0 errors); invoice seller now 30/30 keyed (was 28/30: Source-header decoy + role-swap fixed), buyer 25/25; keyless-only baseline 400/537 |
| CUAD contracts (public clause truth) | agreement 58%, law 94/97 keyless on 100 unseen (97%, blind seed 7) renewal 54/99 keyless blind (55%, seed 7) (R1-era 69-71% not reproducible), notice-period 77/93 keyless, cap-on-liability 84/96 (FP=12, FN=0, recall probe 248/260 Yes), liquidated-damages 93/96 (FP=0), insurance 90/96 (FP=3, recall 144/159 Yes), anti-assignment 92/96 (FP=1), covenant-not-to-sue 90/96 (FP=1), non-disparagement 94/96 (FP=0), no-solicit employees 94/96 (FP=0), license 78/96 (precision .91), MFN local 94/96 blind (recall probe 13/25 Yes), non-compete 86/96 field blind (harness recall 100%, 12/12), agreement/effective/expiration dates 51/89, 36/83, 9/93 (filing-flood + 19xx + month-word + value-first fixes; computed term-end dates flagged computed; expiration truth 54% computed from term + 22% perpetual; template truths skipped as ungradeable), exclusivity LLM 58%, termination-for-convenience 71/96 keyless blind (74%, seed 7) vs 64% majority; Yes/No flags grade correct nulls as hits |
your docs (python -m evals.validate_real) |
real CVs: 100% offline. Drop PDFs in samples/real/ + truth in evals/real_truth_local.py — both gitignored, nothing leaves your machine |
Misses feed back into the generator or pack anchors. No false grounds recorded to date.
meta.retrieval on every response: windows hit/sent per field, chars, fallback flag. Tune with python3 evals/retrieve.py <doc> <pack> <field> — ranked windows, visual iteration on retrieve keywords. Small model + dense context beats big model + dump (13× cost, 0 closes — see Cost).
qleric/ingest/— portable intake:parse(+pdf,docx),types,provenance,columns,ocr,images,scripts;documentsis a backward-compat shimqleric/layout/— portable sections:find_section,split_sentences,windows,types; stdlib only, scorer injectedqleric/— core:grounding(prove it),local(spans),highlight(bboxes),lm(BYOK),costs(ledger),mcp(tools)qleric/packs/—invoice,resume,pii,contractevals/—generate.py,eval.py,bench_ingest.py,validate_real.py,validate_field_blind.py(blind protocol, value+flag modes),real_truth.py(your template)tests/—test_ingest.py,test_layout.py(hermetic circuit, no CUAD/network)api.py— stateless Flask;samples/golden/— hand-checked demo docs;samples/corpus/— 90-case synthetic eval set (real/is gitignored private docs)
