Validating Structured Extraction: Code First, Judgment Second
Updated 2026-09-22
The scenario
An LLM extracts structured data from documents — invoices, contracts, forms — into JSON. Your code already validates the shape: required fields present, dates parse, totals are numbers. But shape validation is blind to meaning: a plausibly-formatted date that's the signature date instead of the effective date, a total that's actually the subtotal, a counterparty name pulled from the footer instead of the header. These errors parse perfectly and corrupt downstream systems silently.
Why Jev fits
"Does this extracted value correctly reflect the source document?" is a judgment call, not a parsing problem — and it's exactly the kind of closed question (yes/no per field, or a confidence score per record) a judgment-only model answers cheaply. The division of labor is clean: code checks what code can prove, Jev judges what requires reading comprehension, and neither pretends to do the other's job.
Judgment design example
Structured input per extracted record:
| Field | Example |
|---|---|
source_excerpt | relevant passage from the document |
extracted_fields | { "effective_date": "2026-03-01", "total": 14250.00, "currency": "USD" } |
schema | expected fields and types |
extraction_confidence | the extractor's own score, if any |
Judgments to define:
- Noul per critical field: "Does the excerpt support
effective_date = 2026-03-01?" → any high-value field failing sends the record to review. - Noul per record: "Is this extraction as a whole faithful to the source?" → cheap gate for the common case where you only need record-level pass/fail.
- Score (optional): "Extraction quality 1–5" → records at 1–2 go to human review, 3 gets a second extraction attempt with a different prompt, 4–5 flows through.
Where the LLM sits
Upstream, as the extractor — and occasionally downstream, as the fixer. The pipeline is: LLM extracts → code validates shape → Jev judges faithfulness → only failures loop back to the LLM with the specific field flagged. The expensive re-extraction happens on the small failing fraction, not the whole corpus. This is confidence gating applied to extraction instead of routing.
Watch-outs
- Judge against excerpts, not whole documents. Context is limited (reported 64k tokens, with the longest single question capped at 32k) — pass the relevant passage plus the extracted fields, not the full contract.
- Code stays the first gate. Never spend judgment calls on records that fail schema validation; reject those in code for free.
- Judgment is not proof. A Noul "yes" means the model believes the field is faithful. For money-moving fields, sample-audit the passers too — independent early testing suggests real-world accuracy runs below official claims and varies by task.
Sources
- jev101.com — application-scenario coverage of structured extraction (结构化抽取) pipelines as a judgment-model workload.
- jevai.wiki — API reference (state + typed questions request shape) and model pages.
- learnjev.com — Concepts: System One and the Three Primitives — the judgment-not-generation framing this pattern depends on.
- "Jev explained in 7min" — Caleb Writes Code — the "new paradigm" overview: typed decisions as a function call.
Unofficial fan-made handbook. Not affiliated with TypeSafe AI or jev.com.
Related Guides
Document Triage: Type and Urgency on Two Axes
Sort inbound documents — contracts, invoices, resumes, tickets — by type with Choice and by urgency with Score, so each document class gets its own downstream pipeline and deadline.
Intent Classification: The Front Door of a Chatbot
Classify user messages into intents (and urgency) before any LLM touches them — so simple requests get cheap handlers and only genuinely open-ended messages reach the expensive model.
RAG Reranking: Filtering Retrieval Results by Relevance
Use Jev-style Noul judgments to batch-score retrieved chunks for relevance and keep only the top-k — so the LLM answers from signal, not from whatever the vector search coughed up.
Support Ticket Routing with a Judgment-Only Model
Route support tickets to billing, technical, account, or sales with Jev-style Choice judgments — plus spam filtering and urgency scoring so humans only see what matters.