WorkDTC E-commerce6 min read

Keeping Contribution Margin Honest by Extracting Landed Cost From Messy Documents

An LLM reads supplier invoices, freight and customs bills, 3PL fee schedules, and processor statements into the cost model, so contribution margin reflects true landed cost without manual data entry, even as tariffs and freight move.

A contribution-margin model is only as honest as its cost inputs. This brand's landed costs, supplier invoices, freight forwarder bills, customs and duties, 3PL fee schedules, processor statements, arrived as a pile of mismatched PDFs and got keyed in by hand or estimated. So COGS and landed cost were stale, and with tariffs and freight moving, margin was quietly wrong.

Client profile
A DTC e-commerce brand, ~$30M revenue, importing goods with volatile freight and duties
Industry
DTC E-commerce
Region
North America / UK

01 The Challenge

The margin model was running on cost data that was stale and partly guessed

QuarterlyLanded-cost refresh, partly estimatedWhile tariffs and freight moved monthly

The contribution-margin build made CAC, payback, and margin trustworthy, but only down to the quality of the cost inputs. Those inputs were the worst-structured data in the business: a supplier's commercial invoice in one layout, a freight forwarder's bill in another, a customs entry with duty lines, a 3PL fee schedule, a payment processor statement. Finance keyed in what they could and estimated the rest, quarterly. With tariffs and freight rates swinging, the landed cost behind each SKU drifted from reality, and the margin numbers drifted with it.

The margin model deserved better fuel.

02 The Approach

Extract every cost document to the line item, allocate it to SKUs, reconcile before it counts

The governing rule: every cost document is extracted to line-item granularity, allocated to the right SKUs and shipments (freight and duty spread correctly), and three-way matched against the purchase order and receipt before it updates the cost model, with a human clearing exceptions.

Two decisions made it reliable. First, structured extraction that carries provenance. Every figure returns the page it came from, so an exception is traceable. Second, a real allocation step: freight and duty are not per-SKU on the document, so the model allocates them across the shipment by weight or value into a true landed cost per SKU. We did not let extracted numbers flow straight into margin. The three-way match gates them, and mismatches go to a person.

What we deliberately did not do: no auto-posting to the GL, no replacing the AP process, and no trusting a number that did not reconcile.

03 The Build

Read the documents, allocate the costs, gate on the match

Cost documents land from suppliers, freight forwarders, customs, the 3PL, and the payment processor. Claude Haiku 4.5 (vision) extracts each one to structured line items, returning the source page per value. Claude Opus 4.8 handles the harder reasoning: allocating freight and duty across SKUs into landed cost, and resolving ambiguous or non-standard documents. A three-way match compares extracted costs against the purchase order and receipt; clean matches update the cost model, exceptions go to a TypeScript review console for a person to clear. The reconciled landed costs feed the contribution-margin model in BigQuery via dbt, so margin reflects current, real cost.

It feeds the BigQuery and dbt margin model directly, so corrected costs flow straight into contribution margin instead of waiting for the next manual refresh.

  • Python
  • Claude Haiku 4.5
  • Claude Opus 4.8
  • TypeScript
  • BigQuery
  • dbt
  • GCP

04 The Results

Margin that tracks real cost, in days

DaysTo refresh true landed costDown from a quarterly, partly-estimated process

Landed cost is now extracted and allocated to the SKU and refreshed in days, not quarters, so when tariffs or freight move, contribution margin moves with them instead of lagging a quarter behind. Every cost document is read automatically, and the three-way match catches supplier and freight overbilling that used to slip through. Finance spends its time clearing real exceptions, not keying invoices, and the margin model finally runs on cost data it can trust.

05 What's Next

Accurate cost as the foundation under every margin decision

With landed cost current and trustworthy, the margin model can drive sharper decisions: SKU-level profitability, pricing under tariff changes, and margin-aware bidding fed back into the attribution loop. The hard part, getting clean cost data out of messy documents, is automated.

Consumer Goods (CPG)6 min read

Recovering Retail Deductions at 70% Win Rate With LLM Document Intelligence

An agent that reads every cryptic retailer deduction, checks it against your order-to-cash record, and assembles the dispute, so the invalid ones stop being silently written off.

70%Win rate on disputed deductions
  • Document Intelligence
  • Haiku 4.5
  • Opus 4.8
  • Deductions
Read

Dental6 min read

Every Marketing Source and Patient Outcome in One Dashboard You Can Just Ask

Meta, Google, Search Console, GA4, and Dentally unified into one live custom dashboard, with an LLM that answers plain-English questions tied to booked patients and treatment.

8 hrs/weekReclaimed from manual reporting
  • Marketing Dashboard
  • BigQuery
  • LLM Analytics
Read

Engineering edge,
without hiring a team.

Numbers you can trust, operations that run themselves, all built into your stack and owned by you. Tell us where you want the edge, and we'll build it.

Have a project in mind?

  • Quick response

    You'll hear from an engineer the same working day, not a sales sequence.

  • Clear next steps

    A short call, then a plan, and we start with Proof Week or a full build.

  • Fixed fee first

    A fixed fee agreed before anything starts, for Proof Week or the full build.