DEC 2, 202610 MIN READPOST BY: TEAM CODESMITHSUPDATED:

OB Automation Platform: Purchase Orders from Inbox to NetSuite

Inbox to NetSuite, with a person only where judgement is needed

OB Automation Platform: Purchase Orders from Inbox to NetSuite

Office Beacon

Delivered forOffice Beacon · Business process outsourcing for promotional-products clients

  • Backend · AI pipeline · ERP
  • NetSuite · Google · Outlook
  • Aug – Oct 2026
  • In live use

Abstract

How CodeSmiths engineered AI-driven purchase-order automation for Office Beacon: an eight-stage pipeline, a self-hosted vision model and a human review queue that turn emailed orders into production-ready sales orders.

  • 8automated pipeline stages, inbox to work order
  • 9order types, each with its own handler
  • 3600+automated test cases
  • 0cross-brand SKU collisions at the chosen match threshold

01 08

1. At a glance

AI reads the order, rules check it against the ERP, people handle the exceptions

The OB Automation Platform turns the purchase orders customers email every day into validated, production-ready sales orders in NetSuite. AI vision models, engineered first for a self-hosted Qwen model, read each message and its attachments, a rules engine checks customers, products, prices and ship dates against the ERP, and operators step in only where human judgement is needed.

CodeSmiths engineered it end to end: a multi-tenant API, an eight-stage processing pipeline, a human review queue and the integrations that connect them. It was delivered between August and October 2026 and Office Beacon now uses it in live operations.

Built with
  • Python
  • FastAPI
  • PostgreSQL
  • Redis
  • Qwen VL
  • Google Workspace
  • spaCy
  • Docker
  • Sentry
  • Client: Office Beacon
  • Industry: Business process outsourcing, serving promotional-products clients
  • Scope: Backend, AI pipeline and ERP integration
  • Integrations: NetSuite, Google Workspace and Outlook
  • Team: CodeSmiths engineers
  • Engagement: August to October 2026
  • Built with: Python, FastAPI, PostgreSQL, Redis, Qwen, Docker and Sentry

Key innovation: draft first, convert in place

  • The platform writes a “preflight” draft order to NetSuite before any human approves it, then upgrades that same record into the live sales order. Operators review a real ERP record rather than a pile of guesses, and the conversion is idempotent, so a retry never creates a second order.

How CodeSmiths operates

CodeSmiths’ delivery practices are certified to ISO/IEC 27001 and aligned with major data protection regulations. We work in accordance with ISO/IEC 42001 for AI management and SOC 2.

02 08

2. The challenge

Purchase orders arrive as email, in every format imaginable

Customers send purchase orders as email attachments: PDFs, Excel workbooks, images, even an Outlook message attached to another. Operators open each one, read it, cross-check product codes and pricing, key it into NetSuite, file the artwork and raise production work orders.

The work is repetitive and hard to scale, and a single misread SKU or price level can book an order to the wrong brand or bill the wrong amount.

What arrives in the inboxFour kinds of attachment, one manual routine
PDFPurchase orders
Excel.xlsx and legacy .xls
ImagesPhotos and scans
OutlookA message inside a message
  1. Step 1

    Open each emailed purchase order and read it

  2. Step 2

    Cross-check product codes and pricing

  3. Step 3

    Key the order into NetSuite and file the artwork

  4. Step 4

    Raise the production work orders

  • Every format: PDFs, Excel workbooks, images and Outlook messages attached to other emails.
  • Repetitive keying: Each order is read, cross-checked and entered by hand, which is hard to scale.
  • Costly small errors: A misread SKU or price level can book an order to the wrong brand or bill the wrong amount.
  • Strict brand separation: Every brand’s data has to stay apart, with a complete audit trail.

What success looked like

  • Software that understands messy, real-world documents
  • No write to the ERP without checks
  • Every brand’s data kept strictly separate
  • A complete audit trail for every order

How an order was handled before

  • Step 1: Open each emailed purchase order and read it
  • Step 2: Cross-check product codes and pricing
  • Step 3: Key the order into NetSuite and file the artwork
  • Step 4: Raise the production work orders

03 08

3. Our approach

Verification-led delivery, with quality gates on every change

Each cycle built a capability, replayed real orders through it and audited the result against the ERP before moving on. Every major design choice answers a specific failure mode.

Verification-led deliveryBuild a capability, replay real orders, audit against the ERP
PHASE 01Foundation

Multi-tenant API, revocable sessions, permissions, encrypted connectors, worker infrastructure and CI.

PHASE 02Pipeline

Workers 1 to 8: mailbox sync, AI triage and extraction, validation, NetSuite preflight, filing, conversion and work-order queueing.

PHASE 03Real-order verification

Replay real customer emails end to end, audit every field against NetSuite, fix the cause and re-test.

PHASE 04Hardening

Brand routing, retention policies, duplicate defences, failure taxonomy and separate DEV and UAT deployment.

Continuous integrationFive checks on every change
  1. 01Lint and format

    Ruff on every change

  2. 02Strict type check

    mypy across the source tree

  3. 03Migration integrity

    Single head, applies cleanly from empty

  4. 04Test suite

    3,600+ tests in parallel, with coverage

  5. 05Audit and build

    Dependency audit and production container build

  • Foundation: Multi-tenant API, revocable sessions, permissions, encrypted connectors, worker infrastructure and CI.
  • Pipeline: Workers 1 to 8: mailbox sync, AI triage and extraction, validation, NetSuite preflight, filing, conversion and work-order queueing.
  • Real-order verification: Replay real customer emails end to end, audit every field against NetSuite, fix the cause and re-test.
  • Hardening: Brand routing, retention policies, duplicate defences, failure taxonomy and separate DEV and UAT deployment.

Design decisions

  • Tenancy in the repository layer: Shared schema, tenant applied to every query. A foreign record returns 404, never 403.
  • Stateful sessions over JWTs: One session, device or account can be revoked instantly; an outage refuses requests.
  • Transactional outbox: Each step is recorded in PostgreSQL before dispatch, so a crash cannot lose work.
  • Queues split by latency: Slow model extraction gets its own worker pool and never blocks quick jobs.
  • The pipeline is data: Step order lives in a per-tenant plan, so changing it is configuration, not code.
  • Cardholder data stays out of the model: Presidio masks card details before any text reaches an AI model.
  • Secrets sealed to their row: AES-GCM credentials bound to the tenant and column that own them.
  • Thresholds measured, not guessed: SKU matching at 0.92, chosen by comparing all 3,355 catalogue codes.
  • Uncertainty goes to a person: An unresolved customer, SKU, price or date opens a review instead of a guess.

04 08

4. The solution

One governed pipeline from inbox to production floor

The platform is a multi-tenant service. It connects to customer mailboxes, uses vision language models to classify and extract each order, validates the result against NetSuite customers, catalogues and pricing rules, and creates a draft “preflight” sales order automatically. Operators review only the exceptions; once approved, the draft is converted in place into a live sales order.

Local AI, self-hostedA vision model we run ourselves: Qwen VL on a dedicated H100
~25kToken context window the whole extraction path is engineered around
150 dpiJPEG page renders, tuned down from 200 dpi PNG to leave room for the answer
~3×Smaller page images: JPEG instead of PNG, small print still legible
4,096Token thinking budget, set from live runs, with no truncated extraction since
Models
qwen2.5-vl-30b, then qwen3.8-vl-27b
Precision
FP16 model with INT8-quantized weights
Hardware
Dedicated NVIDIA H100, 80 GB, rented
Serving
OpenAI-compatible API on that GPU
Data
Order documents read without a third-party AI service
Portability
A per-tenant setting, repointed without a code change
  1. 01Quantized to fit

    INT8 weights take a 27–30-billion-parameter FP16 vision model down to roughly 30 GB, leaving more than half of the 80 GB H100 for concurrent requests.

  2. 02Every token accounted for

    Pages travel as short-lived presigned URLs, not inline base64, which had used about 24k of the 25k window and cut the reply off mid-JSON.

  3. 03Pages rendered for the window

    150 dpi JPEG, quality 80, long edge capped at 2,000 px. At 200 dpi PNG the same PO cost about 18k prompt tokens and the answer would not parse.

  4. 04A thinking budget from live runs

    At the original 700–800 token limit the model spent everything thinking and returned nothing. Pinned at 4,096, it has held.

  5. 05Output shaped, never trusted

    A schema layer restores dropped keys and normalises dates; a reply that is not valid JSON gets one strict re-prompt.

  6. 06Concurrency sized to the GPU

    A single worker process with a fixed number of calls in flight. Lower the load before raising any timeout.

Rented, not bought. A Mac Studio was considered as on-premises hardware. A dedicated, rented H100 won: data-centre throughput for many extractions in flight at once, the CUDA serving stack these models are built for, and no capital outlay while the model was being chosen and tuned.

01 · Mailbox connectors

Delegated Google Workspace and Microsoft connections with incremental sync and an encrypted token vault, scheduled per mailbox.

    02 · Document understanding

    Reads PDFs, Excel workbooks (.xlsx and legacy .xls), images and Outlook messages attached to other emails. Oversized emails are rendered to PDF for filing.

      03 · AI triage and extraction

      Vision models decide whether an email is a real order, resolve its brand and pull out PO numbers, addresses, line items, quantities, prices and instructions.

        04 · Validation engine

        Matches customers and SKUs to the ERP catalogue, validates pricing and setup charges, and calculates ship dates from production times.

          05 · Nine order types

          Standard, sample, spec sample, repeat, remake, rush, drop-ship, blank and self-promo orders each follow their own handler and rules.

            06 · Human review queue

            Exceptions pause the workflow. Operators assign, comment, attach files, approve or reject, and the workflow resumes where it stopped.

              07 · Duplicate and forward detection

              Recognises the same PO arriving twice or forwarded between teams, so one order is never booked twice.

                08 · Multi-brand routing

                Routes each order to the right brand and sub-tenant, including brands that are forwarded onward rather than entered.

                  09 · Customer portal API

                  Dedicated endpoints let end customers check order status without exposing any internal workflow detail.

                    10 · Self-hosted vision model

                    Qwen VL, quantized to INT8 and served from a dedicated 80 GB NVIDIA H100 through an OpenAI-compatible endpoint, with no third-party AI service in the path.

                      05 08

                      5. Platform in action

                      Eight workers, one auditable workflow

                      Each purchase order moves through eight specialised workers. Two are AI stages, three write to NetSuite, and a human gate catches anything the rules cannot settle.

                      Purchase-order lifecycleFrom customer email to production work order
                      1 · Ingest & understand
                      1. W1Fetch emailSyncs mailboxes, saves attachments, flags duplicates and forwardsRules stage
                      2. W2AI triageIs it a real order? Resolves the brandAI stage
                      3. W3AI extractionReads every page into structured PO, address and line-item dataAI stage
                      2 · Validate & draft
                      1. W4ValidationMatches customer and SKUs; checks prices, setup charges and ship datesRules stage
                      2. W5ERP preflightCreates the draft sales order in NetSuiteNetSuite
                      3. W6Document filingFiles the PO, artwork and email PDFs to NetSuite through SkyDocNetSuite
                      3 · Approve & produce
                      1. GateHuman reviewOperators fix, approve or reject; the workflow resumes on approvalHuman gate
                      2. W7Real SO conversionUpgrades the draft into the live sales order, in placeNetSuite
                      3. W8Work ordersPrefills each work order so a person creates it in one clickNetSuite

                      Exception route. Validation questions pause the order at the human gate. Once an operator approves, the workflow resumes where it stopped. The finished order is live in NetSuite.

                      Order types handledStandardSampleSpec sampleRepeatRemakeRushDrop-shipBlankSelf-promo
                      Platform architecture
                      CLIENTS
                      Operator consoleReview queue, settings
                      Customer portalOrder status only
                      Service clientsScoped API keys
                      FASTAPI SERVICE
                      Request ID, rate limitCorrelated logs, sliding window in Redis
                      Authentication, permissionsJWT plus live session check
                      Tenant-scoped repositorytenant_id on every query
                      STATE
                      PostgreSQL 17Orders, workflows, outbox, audit log, 43 tenant-aware tables
                      Redis 7Sessions, rate limits, token epochs, task broker
                      WORKERS & INTEGRATIONS
                      Taskiq workerscritical, triage, extract, default, scheduler, outbox relay, DLQ
                      Mailboxes and AIGoogle Workspace, Outlook, self-hosted Qwen VL
                      NetSuite and storageSkyDoc, S3 or local object storage
                      Across all layers: every request passes the same chain of checks before it can touch tenant data
                      • 1. Fetch email: Syncs mailboxes, saves attachments, flags duplicates.
                      • 2. AI triage: Is it a real order? Resolves the brand.
                      • 3. AI extraction: Reads every page into structured data.
                      • 4. Validation: Matches customer and SKUs; checks prices and dates.
                      • 5. ERP preflight: Creates the draft sales order in NetSuite.
                      • 6. Document filing: Files PO, artwork and email PDFs via SkyDoc.
                      • 7. Real SO conversion: Upgrades the draft into the live order, in place.
                      • 8. Work orders: Prefills each work order for one-click creation.

                      Solution architecture

                      • Clients: Operator console, customer portal and service clients with scoped API keys
                      • FastAPI service: Request ID, rate limiter, authentication, permission guard and tenant-scoped repository
                      • State: PostgreSQL 17 (43 tenant-aware tables) and Redis 7
                      • Workers and integrations: Taskiq workers, mailboxes, self-hosted Qwen VL, NetSuite with SkyDoc and object storage
                      Architecture: clients call a FastAPI service with request ID, rate limit, authentication, permission and tenant checks; PostgreSQL and Redis hold state; Taskiq workers connect mailboxes, the Qwen model, NetSuite and storage
                      Architecture: clients call a FastAPI service with request ID, rate limit, authentication, permission and tenant checks; PostgreSQL and Redis hold state; Taskiq workers connect mailboxes, the Qwen model, NetSuite and storage

                      06 08

                      6. Results and business value

                      Precision, engineered and then measured

                      An order that is almost right is an expensive mistake, so the rules behind the pipeline were tested against real data and real orders rather than assumed. The platform is in live use at Office Beacon; no before-and-after volume figures are published here.

                      AccuracyPrecision, engineered and then measured
                      3,355Catalogue codes compared pairwise to set the match thresholdAt 0.92 no two codes from different brands collide; the intuitive 0.90 would have left eleven.
                      0.941Score of a real customer typo at the chosen thresholdUnrelated codes top out at 0.800, so typos still match and other brands never do.
                      84Findings in an order-entry review, reconciled order by orderChanges were replayed on real customer emails and audited field by field against NetSuite.
                      2Layers of duplicate protection, each tested on its ownThe same PO is caught at ingestion and again inside the pipeline.
                      Industry contextHow this compares with published deployments
                      Oldcastle APGSeraxWorkist · MicrobiologicsOB Automation Platform
                      ERP targetInfor M3SAP S/4HANA CloudNetSuiteNetSuite
                      Orders arrive asEmail attachments: PDF, image, HTML, textPDF ordersEmail and PDFEmail: PDF, Excel, images, nested emails
                      Human reviewCSR verifies each orderEmployee reviews, then convertsTeam decidesExceptions only, in a review queue
                      Originals filedNot describedNot describedPDF and email archivedPDFs, artwork, email via SkyDoc
                      Multi-tenant platformNot describedNot describedNot describedYes: isolated per tenant and brand
                      Production work ordersNot describedNot describedNot describedYes: prefilled per line, created in one click
                      Published outcome95% of lines automated, 5% flagged33% fewer manual B2B orders3.6 min saved per order; 80% time savedIn live use at Office Beacon

                      A comparison of published scope, not of performance. “Not described” means the cited source does not mention it. Sources: Oldcastle APG (AWS), Serax (SAP) and Workist.

                      • Thresholds measured: All 3,355 catalogue codes were compared with each other. At 0.92 no two codes from different brands collide; the intuitive 0.90 would have left eleven.
                      • Gates that only remove risk: The setup-charge gate can take a charge away but never add one, and a failed lookup leaves the previous decision untouched.
                      • Verified on real emails: Changes were replayed on real customer emails and audited field by field against NetSuite, including an 84-finding order-entry review.
                      • Duplicate protection in layers: The same PO is caught at ingestion and again inside the pipeline, each layer tested on its own.

                      How it compares with published deployments

                      • Shared skeleton: Read the document, match it to the ERP, have a person review, then post.
                      • What differs here: Multi-tenant isolation per brand, originals filed through SkyDoc and prefilled production work orders.
                      • Honest scope: A comparison of published scope, not of performance.

                      07 08

                      7. Security, compliance and governance

                      Built for sensitive business data, and for work that is never lost

                      In this platform

                      • Revocable sessions: Every request checks a server-side session record; one device, every device or an account can be ended instantly.
                      • Tenant isolation: A repository layer applies the tenant to every query. Another tenant’s record returns 404, never 403.
                      • Encrypted credentials: NetSuite, mailbox and model keys are sealed per tenant with AES-GCM, with KMS-ready key management.
                      • Cardholder-data redaction: Card numbers, codes, expiry dates and names are masked before text reaches an AI model.
                      • Permission-based access: Endpoints declare permission codes, never role names, and escalation guards stop anyone granting authority they lack.
                      • Audit and retention: An append-only audit log is written in the same transaction as each change; retention is set per tenant.
                      • Reliable operations: Transactional outbox, dead-letter queue with replay, backoff retries, Sentry tracing and per-run AI cost accounting.

                      How CodeSmiths operates

                      CodeSmiths’ delivery practices are certified to ISO/IEC 27001 and aligned with major data protection regulations. We work in accordance with ISO/IEC 42001 for AI management and SOC 2.

                      08 08

                      8. Technology stack and data flow

                      The components behind the platform

                      Purchase-order data flowEight steps from the customer’s email to a work order
                      1. 01Customer → MailboxEmail a purchase order

                        PDF, Excel, images or a nested Outlook message arrives

                      2. 02Fetch workerSave and de-duplicate

                        Attachments stored; repeats and forwards flagged

                      3. 03AI triageReal order? Which brand?

                        A vision model reads the pages and routes the order

                      4. 04AI extractionRead every page

                        Structured PO, address and line-item data

                      5. 05Validation → NetSuiteCheck against the ERP

                        Customers, SKUs, prices and ship dates; draft sales order written

                      6. 06OperatorReview exceptions

                        Approve or reject; the workflow resumes where it stopped

                      7. 07ConversionConvert in place

                        The draft becomes the live sales order, idempotently

                      8. 08Work ordersPrefill, one click

                        A person creates each work order, the only route NetSuite offers

                      • Python 3.14 and uv: Modern async Python with reproducible, locked builds.
                      • FastAPI and Pydantic v2: Async REST API with strict schema validation and OpenAPI docs.
                      • PostgreSQL 17 and SQLAlchemy 2.0: Async ORM and 59 Alembic migrations, with JSONB for extracted order data.
                      • Redis 7: Sessions, rate limiting and the task broker.
                      • Taskiq workers: Distributed queues, retry middleware, outbox relay and a cron scheduler.
                      • Qwen VL, self-hosted: INT8-quantized vision models on a dedicated 80 GB H100, orchestrated with PydanticAI.
                      • NetSuite integration: REST and SuiteQL client, draft and live sales orders, prefilled work-order links.
                      • Google and Microsoft mailboxes: Delegated OAuth mailboxes with incremental sync.
                      • Presidio and spaCy: Detection and masking of card and personal data.
                      • Docker and GitHub Actions: Multi-stage images and gated DEV and UAT deployment pipelines.
                      • Sentry and Prometheus: Distributed tracing, structured logs and business metrics.
                      • PDF and page rendering: Page rasterisation for vision models and PDF rendering for oversized emails.

                      Purchase-order data flow

                      • 1. Fetch the email and its attachments
                      • 2. Triage and extract with the vision model
                      • 3. Validate against NetSuite and write the draft
                      • 4. Review exceptions, then convert and prepare work orders
                      Order flow: fetch email, triage, extract, validate, preflight draft, human review of exceptions, convert in place and prefilled work orders
                      Order flow: fetch email, triage, extract, validate, preflight draft, human review of exceptions, convert in place and prefilled work orders

                      The outcome

                      A pipeline that reads messy purchase orders, writes nothing to the ERP unchecked and leaves people to settle only the exceptions, now in live use at Office Beacon.

                      About CodeSmiths: we design and build AI, data, cloud and application solutions that turn manual, fragmented processes into intelligent platforms.

                      Ready to build scalable, resilient, and crafted digital systems?

                      Let’s talk →

                      Common questions

                      What is the OB Automation Platform?

                      AI-driven purchase-order automation that turns emailed orders into validated, production-ready sales orders in NetSuite, built by CodeSmiths for Office Beacon.

                      Does a person still review orders?

                      Yes, only where judgement is needed. Exceptions go to a review queue; operators approve or reject and the workflow resumes where it stopped.

                      Which AI model does it use?

                      A self-hosted Qwen vision-language model, quantized to INT8 on a dedicated 80 GB NVIDIA H100, with no third-party AI service in the path.

                      What is “draft first, convert in place”?

                      The platform writes a preflight draft order to NetSuite for review, then upgrades that same record into the live sales order. Conversion is idempotent, so a retry never creates a second order.

                      How is each brand’s data kept separate?

                      A tenant-aware repository layer applies the tenant to every query across 43 tables, and another tenant’s record returns 404, never 403.

                      Why are work orders created by a person?

                      NetSuite links a work order to its sales order only when the form is saved in its own interface, so the platform prefills each one and a person creates it in one click.