Zero validation errors and wrong invoice totals

L3SeniorDebug10 minDebuggingDesign review

RolesLLM Product EngineeringAI Evaluation and ReliabilityCustomer AI Deployment

The question

An extraction pipeline with strict schema enforcement has reported zero validation errors for a month. A finance review finds that a share of the extracted invoice totals do not match the source documents, and that a status field often holds a value that is allowed by the enum and wrong for the document. The engineers say the schema guarantees correctness. What do you tell them, and what do you build?

Answer it first, aloud or on paper. Then open the answer.

The answer

Show short answer

Schema enforcement guarantees shape, not truth. A total with the right type and the wrong number passes every format check, and an enum member can be allowed and still be the wrong one. Build a semantic eval: a labeled set of documents with gold records, exact match and field-level accuracy per field, plus a confidence signal from repeated extraction or token probabilities that sends low-confidence fields to human review.

Show full answer

The failures a schema cannot see

The structured outputs lesson lists them even with enforcement on:

FailureExampleWhy the schema passes it
Invented valuethe text says one amount and the record holds anotherright type, wrong content
Enum confusionthe model picks an allowed member that does not fit the documentthe member is in the set
Array lengthtoo many or too few line itemsnot every provider enforces the item bounds at decode time
Optional omissiona field left out when it was inconvenientoptional means allowed to be absent

The constrained decoding lesson adds two causes that make the values worse: a grammar too strict for missing data, which pushes the model to invent, and a decision field placed before the reasoning.

What to build

  1. A labeled set. The lesson's exercise uses 50 documents with hand-labeled records. Label real invoices, including the hard cases.
  2. Field-level metrics. Exact match on the record, accuracy per field, and type compliance as a sanity row that should sit near 100 percent.
  3. A confidence per field. Run the extraction three times and measure agreement, or read the token probabilities, and flag the fields that disagree.
  4. A review queue. Low-confidence records go to a human before they reach accounting.
  5. Schema repairs. Put a reasoning field ahead of the status, give enum members descriptions that make their meaning explicit, and add a null or an "other" member if the source has cases that none of the members fit.

Why size does not fix it

The structured output lesson notes that grammar enforcement lets a small model beat a much larger one on structured tasks, because the format is decoupled from the model size. The values are not. Only a labeled eval tells you how often they are right.

Follow-ups

  1. L3SeniorWhich failure can a schema never see?

    Show expected answer

    a value with the right type and the wrong content, such as a total copied from the wrong line.

  2. L3SeniorHow do you get a confidence per field without a new model?

    Show expected answer

    run the extraction three times and measure agreement, or read token probabilities, and flag fields that disagree for review.

  3. L4StaffThe status enum has a member the model keeps picking wrongly. What are the candidate fixes?

    Show expected answer

    describe the members so their meaning is explicit, put a reasoning field before the status, and check whether the source has cases no member fits, which calls for a null or an "other" member.

  4. L4StaffWhat does the finished eval report look like?

    Show expected answer

    schema compliance near 100 percent as a sanity row, then exact match and field-level accuracy per field on the labeled set, with the hardest fields named.

Wrong answers

Show the wrong answers that interviewers hear
  • “Zero validation errors means zero extraction errors.”

    Validation checks shape; the review found value errors that no shape check can see.

  • “Switch to a bigger model and the values will be right.”

    Size changes the error rate, not the blind spot; without a labeled eval you cannot tell by how much.

  • “Add a tighter pattern to the total field.”

    A tighter grammar does not make the number true; a grammar too strict even pushes the model to invent one.

Taught in

The lesson structured outputs lists the failures that survive a schema and sets the labeled extraction eval, the lesson constrained decoding covers the strict grammar and field order causes, and the lesson structured output separates format reliability from model size.