Skip to content
envexa

Engineering Case Studies

Concept case study: designing the review queue for a document-extraction pipeline

A concept case study on the human-in-the-loop design of an AI document pipeline: confidence routing, source highlighting, trade-offs and lessons.

By Envexa Engineering6 min read

This is a concept case study about our AI Document Intelligence prototype. It describes design decisions and trade-offs, not results from a client deployment.

The problem

Extracting fields from invoices and contracts with a language model is the easy half. The hard half is deciding what to do with the output you cannot fully trust. A pipeline that accepts everything produces silent errors; one that sends everything for review has automated nothing. The design question is how to route work so that people only look at what needs a person, and can decide in seconds.

Architecture in one paragraph

Uploads go to object storage and enqueue a job. A worker parses the document preserving layout, extracts fields against a per-document-type schema, validates them with deterministic rules, assigns a confidence score, and writes everything, including the source span for each value, to PostgreSQL. A review UI reads from the same tables. Approved data is exported or sent on by webhook.

Decision 1: route on evidence, not on the model's confidence alone

Model-reported confidence is poorly calibrated, so the routing score combines several signals: whether the value parsed into its expected type, whether cross-field rules hold (line items sum to the total, due date after issue date), whether the value appears verbatim in the source text, and the model's own confidence. Below a threshold, or on any failed rule, the field goes to review.

Decision 2: make verification a glance, not a task

The review screen shows the extracted value beside the document, with the source span highlighted. The reviewer confirms or corrects with one action. The cost of review is dominated by finding the evidence, so storing the source offset for every value is worth more than any amount of model tuning.

Decision 3: keep corrections as data

Every correction is stored with the original value, the new value and the document type. That gives you an evaluation set that grows from real mistakes, a way to measure accuracy per field, and, later, material to improve prompts or fine-tune with.

Trade-offs we accepted

  • Latency for accuracy. Validation and indexing run after extraction, so results appear in seconds to minutes, not instantly.
  • Per-type schemas over a universal extractor. More up-front work for each document type, in return for validation rules that actually catch errors.
  • One database for everything at first. Documents, fields, embeddings and audit logs share PostgreSQL. It is simpler to run and reason about, and can be split later if volume demands it.

Lessons we would apply in production

  1. Define the review threshold with the business, because it is a cost-versus-risk decision, not a technical one.
  2. Build the evaluation set before tuning, and report accuracy per field rather than a single average.
  3. Design the failure path first: what happens when parsing fails, a file is corrupt or a job times out.
  4. Log enough to answer "why was this value accepted?" months later, which is an audit requirement in many industries.

You can see the interface decisions in the interactive demo and the full structure in the concept project write-up.

Case studyDocument AIHuman in the loopArchitecture

Building something like this?

We are happy to review your architecture or help you build it.