Table of contents :

When OCR Becomes Part of the Pipeline

100-days-of-chunking-with-llamaparse-and-undefined-017

Table of contents :

WooCommerce document workflows often begin with files that were never designed for software: scanned supplier invoices, photographed packing slips, legacy product catalogs, warranty forms, and return documents saved as image-only PDFs. In those cases, OCR is not a convenience added before search. It is an ingestion stage that directly affects extraction, chunking, retrieval, and automation quality.

Why OCR changes the shape of a document pipeline

A text-native PDF usually exposes characters, reading order, page boundaries, and sometimes table structure. An image-only PDF exposes pixels. OCR must infer the characters and their positions before a parser can create a usable representation.

That inference introduces several failure modes:

  • Characters can be substituted, such as 0 for O or 1 for I.
  • Columns can be read in the wrong order.
  • Table rows can collapse into a single text stream.
  • Headers, footers, and page numbers can be repeated in every extracted segment.
  • Handwritten notes, stamps, checkboxes, and low-contrast text may be omitted entirely.

For an agency building a retrieval or automation feature for WooCommerce, these are not merely presentation defects. An OCR error in a SKU, quantity, price, tax rate, or order number can cause an incorrect inventory update or an unreliable support response.

Place OCR before structural parsing and chunking

A practical pipeline should treat OCR as an explicit decision point rather than silently applying it to every file:

  1. Classify the input. Determine whether the file contains a usable text layer, embedded images, scanned pages, or a mixture of all three.
  2. Parse text-native content. Preserve the original text layer where it is reliable.
  3. OCR only the pages that require it. A mixed PDF may contain selectable text on the first pages and scanned appendices later.
  4. Retain layout and page metadata. Coordinates, page numbers, tables, and section boundaries help downstream processing.
  5. Normalize and validate the extracted representation. Do not remove useful uncertainty before a business rule can inspect it.
  6. Chunk after structure has been recovered. Chunks should represent invoices, line-item groups, policy sections, or product records rather than arbitrary OCR output.

LlamaParse can be used as the document parsing layer in this workflow, with OCR enabled or selected for documents that need it. The exact option names and supported modes depend on the installed client and service version, so production code should pin the client version and verify the resulting page and table metadata against representative files.

Use document classification to control cost and risk

OCR can be more expensive and less predictable than extracting an existing text layer. A simple classifier can inspect each page before parsing. Useful signals include the amount of selectable text, the ratio of image area to page area, page dimensions, and whether the extracted text contains plausible words.

For example, a supplier invoice may be routed as follows:

  • A digitally generated PDF with a valid text layer goes through normal parsing.
  • An image-only page goes through OCR.
  • A page with both selectable text and a scanned signature is parsed for text while the image is retained as an attachment.
  • A page with very low OCR confidence is sent to a review queue instead of being used for an inventory mutation.

This approach reduces unnecessary OCR calls and makes the decision auditable. Store the selected mode, parser version, OCR engine configuration, and source file hash alongside the extracted document.

Chunk according to WooCommerce business objects

After OCR, avoid splitting solely by character count. A line item may contain a SKU, description, quantity, unit price, discount, and tax information that must remain together. Separating those fields can make retrieval appear successful while producing an unusable answer.

For an invoice, a useful hierarchy is:

  • Document chunk: supplier, invoice number, invoice date, currency, and totals.
  • Line-item chunks: SKU, product name, quantity, unit price, discount, tax, and line total.
  • Exception chunks: handwritten adjustments, damaged-goods notes, shipping discrepancies, or approval comments.

For a product catalog, preserve each product record as a unit where possible. Its title, SKU, attributes, dimensions, pack size, and compliance notes should not be distributed across unrelated chunks. If a product description is too large, split it at semantic boundaries while copying the SKU and product identifier into every child chunk as metadata.

Keep OCR provenance with every chunk

OCR-derived text needs stronger provenance than ordinary copied text. A useful chunk record might contain fields like these:

{
  "text": "SKU AX-104, quantity 12, unit price 18.50",
  "source_file": "supplier-invoice-4821.pdf",
  "page": 2,
  "document_id": "invoice-4821",
  "block_type": "line_item",
  "extraction_method": "ocr",
  "parser_version": "pinned-version",
  "ocr_confidence": 0.93,
  "bbox": [72, 314, 522, 348],
  "review_required": false
}

The bounding box is valuable when an operator needs to inspect the original page. The extraction method distinguishes OCR text from a native text layer, while the confidence and review flag allow downstream workflows to apply stricter rules to uncertain values.

Do not treat confidence as a universal truth

OCR confidence is usually a signal about recognition quality, not proof that a business value is correct. A neatly printed but incorrect SKU can receive a high confidence score. Conversely, a valid value with an unusual font can receive a lower score.

Combine OCR signals with domain validation:

  • Check whether a SKU exists in the WooCommerce catalog or the supplier mapping table.
  • Verify that quantities are positive integers when the document requires units.
  • Parse currency and decimal separators according to the supplier’s locale.
  • Recalculate line totals and compare them with the extracted totals within an explicit tolerance.
  • Compare the invoice number and supplier identity with the expected purchase order.

A disagreement should create an exception, not be silently corrected by an LLM or a post-processing script. Preserve the original OCR value, the normalized value, the validation rule, and the reason for the decision.

Handle tables as structure, not whitespace

Tables are one of the most important reasons OCR must be evaluated as part of the pipeline. A plain text result may contain every visible value but lose the relationship between columns. In an invoice, a quantity can become associated with the wrong SKU even though all numbers were recognized correctly.

When the parser provides table or bounding-box information, use it to reconstruct rows and columns. If the output is only text, use stable anchors such as SKU patterns, currency values, and repeated row geometry, then validate the resulting rows against the catalog.

Do not embed a flattened table without retaining the original row representation. A retrieval-friendly chunk can contain a readable form:

Invoice: 4821 | Supplier: Northwind Parts | Page: 2
SKU: AX-104 | Description: USB-C adapter | Quantity: 12 | Unit price: 18.50 | Tax: 10%

The same chunk should retain structured fields in metadata so an application can filter by SKU or invoice number without asking a language model to recover columns from prose.

Separate retrieval from write operations

OCR-backed search can support low-risk tasks such as locating a warranty clause or answering which page contains a supplier’s return policy. Write operations require a higher threshold. Creating a product, changing stock, updating a price, or marking an invoice as approved should require deterministic validation and, where appropriate, human review.

A useful policy is:

  • Use high-confidence, schema-valid values for read-only indexing.
  • Require catalog matching and arithmetic validation for proposed WooCommerce updates.
  • Require manual approval when key fields are missing, ambiguous, or inconsistent with the source document.
  • Log the source page and extracted region for every mutation.

This separation prevents a retrieval system from becoming an unobserved write system simply because the same chunks are used by both features.

Test with realistic agency datasets

OCR quality should be measured on the documents an agency actually receives, not only on clean sample PDFs. Build a test set containing skewed scans, multi-page invoices, different supplier templates, photographed documents, mixed-language content, stamps, handwritten corrections, and files with both text and image pages.

Measure field-level results for the values that matter to WooCommerce:

  • SKU and product identifier accuracy
  • Quantity and unit-of-measure accuracy
  • Currency, price, discount, and tax accuracy
  • Invoice and purchase-order number accuracy
  • Table row association accuracy
  • Page and bounding-box provenance availability
  • Percentage of documents routed to human review

Evaluate chunk retrieval separately from OCR extraction. A document can have acceptable field accuracy but poor retrieval if repeated headers dominate the chunks or if product identifiers are omitted from child chunks. Conversely, excellent retrieval does not make an extracted price safe to write to a store.

Operational safeguards for production

For a production ingestion service, retain the original file and an immutable processing record. Make parsing idempotent by using a source hash and a parser configuration hash. If OCR or chunking settings change, create a new processing version rather than overwriting the previous result.

Also monitor:

  • OCR fallback rates by supplier and document type
  • Low-confidence fields and manual correction rates
  • Unexpected changes in extracted line-item counts
  • Parser latency and per-page processing cost
  • Duplicate documents and repeated invoice numbers
  • Differences between extracted totals and validated totals

These metrics reveal template drift early. A supplier changing the position of a quantity column may not cause the parser to fail; it may cause it to return plausible but incorrect data. Monitoring validation exceptions and field distributions is therefore more useful than monitoring only whether a file produced text.

Trending posts
You might also like