Cloudek.Request a service session

AI operations

Air-Gapped Document Extraction: Local OCR and Offline LLM to ERP or SharePoint

Design an air-gapped document extraction pipeline with local OCR, bounded LLM output, deterministic validation, human review and controlled ERP or SharePoint hand-off.

Start with the document path, not the model

Offline invoice extraction is document processing: OCR and local LLM stages produce candidate fields for a SharePoint invoice workflow only after deterministic validation and human review.

An invoice pipeline is a chain of data handling steps. A model running on a workstation does not make the chain air-gapped. Before selecting OCR or a model, draw where the file arrives, which service reads it, where intermediate text is stored, where operators review it, and how the approved record reaches the ERP or SharePoint. Mark every network connection and file store. If a requirement says “air-gapped,” define exactly which systems may communicate and how offline updates are transferred.

This guide is part of the offline LLM automation hub. For model memory assumptions, see the hardware sizing guide; for a strict output contract, see self-hosted n8n with Ollama. The local endpoint security checklist covers service boundaries. A Log Secret Redactor can flag common patterns in diagnostic text; it can miss secrets and is not an assurance control.

What “air-gapped” should mean in the design

Teams use “offline,” “local,” “private” and “air-gapped” in different ways. Write the requirement as a testable boundary. For example: “During processing, the OCR host, workflow service, model server and review store have no route to the public internet; one named internal destination is reachable; model updates are imported through a controlled offline process.” That is more useful than saying “the AI is private.”

Separate build-time traffic from run-time traffic. Installing an OCR package or downloading a model may require a connection even if inference later runs without one. Record how packages and weights are obtained, checked, scanned, approved and transferred. Keep checksums and version records alongside deployment documentation, but do not put model credentials or customer files in the workflow definition.

Map the lifecycle for one synthetic invoice: source folder, malware scanning, OCR, temporary text, model request, parsed output, human review, destination write, logs, retry queue, backup and deletion. For each stage identify the machine, service identity, file permissions, network path, retention period and owner. Confirm whether monitoring or crash dumps can include the raw text. A “local” inference call can still be surrounded by cloud logging, remote storage or an external automation connector.

A conservative pipeline

Use distinct stages so each can fail closed:

  1. Ingest: accept only approved file types and size limits. Give each file a random internal processing key; do not put supplier details in a model prompt or log label.
  2. Inspect: scan the file under the organisation’s existing malware process. Reject encrypted or malformed documents unless the workflow has an approved handling path.
  3. OCR: extract text and, where available, page and bounding-box coordinates. Preserve the source document under its normal access controls.
  4. Draft: ask the model to map a small set of fields into a fixed schema. Treat all invoice text as untrusted data, not instructions.
  5. Validate: parse the response, enforce types and lengths, compare totals with deterministic arithmetic, and check required fields against business rules.
  6. Review: show the draft beside the source evidence. Require a person to approve exceptions and the final destination record.
  7. Write: use a separate, narrowly scoped destination identity. Make the write idempotent and record the result without copying invoice text into general logs.
  8. Reconcile: compare the destination record with the approved draft and retain the review decision for the defined period.

Keep the first implementation read-only: extract a synthetic document and render a proposed row without connecting a write action. This exposes OCR quality, schema gaps and reviewer workload before the team introduces a consequential operation.

Decide what OCR must return

OCR output is not a verified invoice. It is an interpretation of pixels, often with uncertain characters, table boundaries and reading order. Preserve enough evidence to let a reviewer find a value in the source page. A useful internal representation can include page number, text span, bounding box and confidence from the OCR engine, but only retain those details for the review purpose and duration that the data owner approves.

Do not ask a model to “understand the invoice” and then trust an unstructured paragraph. Define fields such as invoice date, currency, subtotal, tax and total only when the downstream process actually needs them. Use a schema with required keys, enums, maximum string lengths and no additional properties. The model may return a candidate value and a short evidence excerpt; deterministic code should check arithmetic and allowed currency codes. Neither a high confidence score nor valid JSON proves that a value is true.

Keep source text and model instructions separate. A prompt can say that the supplied document text is untrusted evidence and that any embedded instructions must be ignored. This is a useful boundary, but it is not a complete defence. Include test documents with text such as “ignore the extraction rules,” unexpected markup, repeated fields and contradictory totals. The correct response may be a refusal or a “needs review” state, not a confident guess.

A synthetic schema and validation example

The following illustrates a narrow draft contract; it is not a universal accounting schema:

{ "type": "object", "properties": { "invoice_date": {"type": ["string", "null"], "maxLength": 10}, "currency": {"type": ["string", "null"], "enum": ["USD", "GBP", "EUR", null]}, "subtotal_minor_units": {"type": ["integer", "null"], "minimum": 0}, "tax_minor_units": {"type": ["integer", "null"], "minimum": 0}, "total_minor_units": {"type": ["integer", "null"], "minimum": 0}, "needs_review": {"type": "boolean"} }, "required": ["invoice_date", "currency", "subtotal_minor_units", "tax_minor_units", "total_minor_units", "needs_review"], "additionalProperties": false }

Using integer minor units avoids some floating-point surprises, but conversion from the printed invoice still needs currency-specific rules. Never infer a currency just because the supplier is in a familiar country. If the currency or amount is unclear, keep it null and send the item to review.

Validation should happen in ordinary application code after the model call. Reject malformed JSON, extra keys, long values, negative numbers, unsupported currencies and arithmetic mismatches. Verify totals using decimal arithmetic and approved tax rules; do not let the model choose tax treatment. Check for duplicate invoice numbers through an approved, deterministic system boundary. If the destination is unavailable after approval, do not retry blindly: first determine whether the earlier write succeeded.

Choose between OCR and cloud document services

Microsoft’s invoice-processing guidance describes an AI Builder capability used in Power Automate. That documentation describes a Microsoft service flow; it should not be presented as an offline component. Microsoft’s Power Automate FAQ also explains the cloud service and gateway model. If a workflow uses a cloud service, evaluate the data path, service terms, permissions, retention and applicable policy rather than calling the design air-gapped.

For an offline path, select an OCR engine that your environment can install and operate without runtime internet access, then test it on representative, approved samples. Compare plain text extraction, table handling, handwriting and rotated pages if those are in scope. The choice depends on language, scan quality, layout and operating constraints. This article does not claim a particular local OCR engine is accurate enough for a financial process.

Treat a gateway as a network bridge with its own identity and operational responsibilities, not a synonym for air-gapping. A path that deliberately connects a cloud workflow to on-premises systems can be useful, but it is a different architecture. Microsoft’s gateway overview and gateway management guide should be reviewed if that option is considered.

Confidence, review and exception queues

Set review rules from measured error rates on a representative evaluation set. Do not pick an arbitrary confidence threshold and call it safe. A candidate can be routed to human review when a required field is missing, the OCR confidence is low, two sources disagree, totals do not reconcile, the supplier is new, or the model output violates the schema.

Show reviewers the original page and the extracted evidence that supports each candidate field. Let them correct or reject a draft and capture the decision. Keep “not extracted,” “ambiguous” and “failed validation” distinct; do not turn these states into a pass or an empty value that might be mistaken for zero. Test the review queue with an OCR outage, model timeout, invalid output, duplicate delivery, full queue and destination outage.

Measure operational counts: documents received, OCR failures, schema failures, items routed to a person, corrections, duplicate detection and elapsed time. Avoid collecting invoice contents in analytics. If a sample is needed to diagnose a defect, use a synthetic file first and follow the approved process for any real document.

Failure, rollback and change control

Keep the destination write disabled until the team has tested validation and approval. Once enabled under the organisation’s own change controls, prepare a rollback that covers the records created by the workflow, not only the workflow configuration. Decide how to identify those records without logging the full invoice or using a model-generated identifier. If a partial batch fails, reconcile completed records before retrying.

Version the OCR engine, model, prompt, schema and workflow together. Run the same evaluation set after changing any component. Include a known-good rollback package and an operator procedure for model-host failure, disk pressure, queue growth, unavailable network and corrupted model files. If updates are imported offline, document the source and verification method for each artifact.

A practical first pilot

Use synthetic invoices from a few layouts. Keep all destination actions off. Check whether the OCR stage finds the fields, whether the model can return the bounded draft, and whether the deterministic checks detect deliberately wrong totals. Have a reviewer record correction categories rather than copying document contents into notes. Repeat on rotated, low-resolution, multi-page and malformed files.

Before moving beyond synthetic data, get the data owner, security team and process owner to approve the exact data categories, retention, access model, network boundary, destination scope and failure handling. Legal and privacy obligations depend on the organisation and processing context; this is general engineering guidance, not legal advice or a compliance assessment.

OpsPilot is a read-only Microsoft 365 review product. It does not run document extraction workflows, deploy local models or write invoices to ERP or SharePoint. This article describes a separate architecture pattern, not a capability of OpsPilot.

*Official documentation checked 24 November 2026: Microsoft AI Builder invoice processing, Power Automate FAQ, gateway reference and gateway management; Ollama, n8n and endpoint links are in the companion guides. Recheck current versions before implementation.*

Frequently asked questions

Does an offline LLM read an invoice accurately?

Not reliably enough to post a financial record without checks. OCR and model output can omit, misread or invent fields. Validate the result against source text, field rules and totals, then route uncertain cases to a person.

Is a local model the same as an air-gapped system?

No. The surrounding host, workflow engine, model downloads, updates, telemetry, backups and destination connectors also need to be inspected and tested for network access.

Can I send invoices directly to an ERP after extraction?

Begin with a review queue. Only add a destination write after an owner approves its identity, validation rules, duplicate handling, audit trail and rollback procedure.

Can Microsoft AI Builder invoice processing be used offline?

The Microsoft Learn invoice-processing flow is a cloud Power Automate capability. Do not treat it as an offline local OCR component; assess its data path and service requirements separately.

Should the model receive the full invoice?

Give it only the minimum text needed for the task. Redact or omit fields that are not needed, and keep the original document in its approved store with its existing access controls.

Was this helpful?