Case study · AI document extraction

Freight ReaderTeaching a Document Pipeline to Read What It Had Never Seen

A cargo booking platform priced each shipment from an uploaded document. When a supplier sent a quotation, its AI pipeline returned zeros. We rebuilt it so the model reads and the code computes.

Booking document check
Supplier quotationUploaded with a booking · 3 of 3 runs identicalVerified
Packages205
Total volume19.33 CBM
Total weight1,463.5 kg
The model reads The code computes
Client
International cargo booking platform
Reads
Packing lists and supplier quotations
Pulls out
Packages, weight and volume (CBM)
Tested on
34 scenarios, five file formats

Product renamed. We do not name the client or its platform. Screens are illustrations, not screenshots.

01The problem

What Broke, and Why

The pipeline worked well on packing lists. One quotation showed where it would break.

  1. 01

    Numbers that set the price

    Package count, weight and volume decide what a shipment costs.

  2. 02

    A quotation, not a packing list

    No weight or CBM column, just one free-text cell per row.

  3. 03

    Zeros, and different zeros

    Each run returned different zeros. One invented 113 packages.

  4. 04

    Confident and wrong

    A prompt fix gave 1.76 CBM against a true 19.33, and passed validation.

02What we built

Five Stages, Each One Testable

One long prompt became five stages, each tested on its own.

  • Structure-Preserving Parsing

    Spreadsheets keep their real grid: merged cells, columns and blanks.

  • Archetype Classification

    A cheap call identifies the document shape first.

  • Specialist Extraction

    A short prompt per shape reads facts only. No arithmetic.

  • Calculation in Code

    Unit conversion and every multiplication, in unit-tested code.

  • Verification

    Density checks and cross-checks, so the numbers agree with each other.

  • Unknown Means a Person

    A document that matches no known shape goes to a person.

03How it works

From Upload to Priced Booking

What happens between a customer uploading a document and the booking getting its numbers, and what happens when a document matches nothing the system knows.

Freight Reader extractionFrom upload to the numbers that price a booking
  1. CustomerTriggerDocument uploaded with a bookingPacking list or supplier quotation
  2. ParserSystemStructure keptReal grid: merged cells, columns and blanks
  3. AI modelAI stepDocument shape identifiedOne cheap routing call
  4. AI modelAI stepFacts read, nothing calculatedOnly values it can literally see
  5. CodeSystemTotals calculatedUnit conversion and every multiplication, unit tested
  6. VerificationSystemNumbers checkedDensity, cross-checks, omissions flagged
  7. BookingResultPackages, weight and volumeReady to price the shipment

Workflow from a real project, simplified

04Inside the product

Inside the Pipeline

The document that broke the old pipeline, and what each stage does with it.

Supplier quotation · one product row

Packing column, as sent

1pc/opp
60pcs/inner box
120pcs/ctn    28*26*16CM    G.W.:11kgs

No weight column. No CBM column. Three units in one cell.

BeforeAfter
Packages 0 (unstable) 205
Total volume 0 19.33 CBM
Total weight 0 1,463.5 kg
Run to run varied identical, 3/3

Before and after. The quotation that broke the old pipeline: one free-text cell per row, and the numbers before and after the rebuild. Illustration.

05Challenges and solutions

What Was Hard, and How We Solved It

Three things that had to be true before the numbers could price a booking.

  1. 01

    Values That Have to Be Worked Out

    Challenge

    Cartons, volume and weight had to be derived from one free-text cell.

    Solution

    The model reads “120pcs/ctn” and “28*26*16CM”. Code does the maths.

  2. 02

    A Prompt Too Long to Pay Attention

    Challenge

    One 5,000 word prompt read and calculated, and got worse with every new document type.

    Solution

    A routing call picks the shape and a short prompt reads it. Tokens fell from 5,729 to 1,422.

  3. 03

    Right Numbers for the Right Reasons

    Challenge

    A figure can be well formed and still ten times off.

    Solution

    Verification found 18 items at 250 g in a 5.5 kg carton: the extra kilogram is packaging.

06How we delivered

How We Got There

From a pipeline that worked on what it knew to one built for the next document it has never seen.

  1. Baseline

    One prompt across 34 scenarios and five file formats, until a quotation returned zeros.

  2. Diagnosis

    Prompt fixes gave confident wrong answers. The arithmetic had to leave the model.

  3. Rebuild

    Five stages. Exact on the quotation and identical across three runs.

07Proof

Exact, Stable and 75% Cheaper

On the document that broke the old pipeline.

  • 205packages, exact
  • 19.33CBM total volume, exact
  • 1,463.5 kgtotal weight, exact
  • 75%fewer tokens per call
  • Identical results on 3 of 3 runs.
  • The model reads; code does every calculation.
  • Documents that match no known shape go to a person.

08Tech stack

What It Runs On

  • Next.js
  • NestJS
  • PostgreSQL
  • OpenAI
See more of our work

Tell Us What You Want to Grow. We Will Show You How to Build It.

Book a free 30 minute consultation with our team. No cost and no obligation.

1/5
What do you need help with?

Pick one

Takes about a minute. We use your details only to reply to you.