Maharjan Consulting
All articles
Artificial Intelligence

Taking LLM Document Extraction From Demo to Production

The gap between an impressive extraction demo and a reliable production system is engineering, not model access. Here's what actually closes it: schemas, evals, guardrails, and observability.

Sagun MaharjanApril 30, 20263 min read

An LLM that extracts fields from a document in a demo is easy. A system that does it reliably, at scale, on messy real-world inputs, without silently returning garbage — that's the hard part. The difference is not a better model. It's the engineering around the model.

Start with a schema, not a prompt

The first mistake is treating extraction as free-text generation. Define the exact output shape you need and force the model to conform to it.

  • Use structured output / tool-calling so responses are valid, typed JSON.
  • Validate every response against the schema before it enters your system.
  • Reject and retry on validation failure rather than parsing loosely.

A typed contract turns "usually right" into "provably well-formed."

Build an evaluation set before you build the pipeline

Without evals, you're tuning blind. Assemble a representative set of real documents with known-correct answers, and measure against it.

precision / recall per field  →  the metrics that actually matter

Every prompt change, model swap, or parameter tweak gets scored against the same set. This is what lets you improve deliberately instead of guessing.

Guardrails for the real world

Production inputs are adversarial by accident — blurry scans, unexpected layouts, missing fields.

  • Return explicit "not found" instead of hallucinating a plausible value.
  • Attach confidence and route low-confidence cases to human review.
  • Set hard limits on retries, tokens, and cost per document.

Human-in-the-loop is a feature, not a failure. The system's job is to handle the 90% confidently and escalate the rest.

Instrument everything

You cannot operate what you cannot see.

  • Log inputs, outputs, latency, and cost per request.
  • Track extraction accuracy over time, not just at launch.
  • Alert on drift — when accuracy or cost moves, you want to know before your users do.

Control cost and latency deliberately

Model choice is an engineering trade-off, not a default. Route simple documents to smaller, cheaper models and reserve the largest models for hard cases. Cache aggressively. Batch where you can. Predictable cost is a requirement, not a nice-to-have.

The path that works

Schema first. Evals second. Guardrails and observability throughout. Do that, and you get a system whose outputs you can build on — one that fails loudly instead of silently, costs what you expect, and improves measurably over time. That's what separates a demo from something a business can depend on.

Have a hard technical problem?

Every engagement begins with a free consultation. Tell me what you're working on and we'll figure out the right approach together — no obligation.