How to Build an Invoice OCR Review Agent

How to Build an Invoice OCR Review Agent

Aident AI

An ivory invoice form passes through a cobalt scan plane into a jade tray with two reviewed evidence tiles.

How to Build an Invoice OCR Review Agent

An invoice OCR agent should extract candidate fields from one authorized image, attach the source text used for each field, run deterministic accounting checks, and write the result to a review queue. It should not approve an invoice, create a payment, or post to a ledger. The safe pattern is OCR proposes, rules check, a human decides.

This guide uses Aident Loadout to discover a current DeepSeek OCR Action and a Lark Base record Action. The same operating contract works with another OCR provider or review system as long as the agent preserves source evidence and stops before a financial side effect.

Define the Boundary Before You Connect Anything

Separate the workflow into four stages:

Stage

Input

Output

Allowed side effect

Capture

One authorized invoice image

Stable source record

None

Extract

Image URL

Raw machine-readable text

None

Validate

Raw text and approved reference data

Candidate fields plus exceptions

None

Review

Reviewed candidate record

Human decision

Write to the review queue only

Payment, vendor creation, purchase-order changes, and ledger posting stay outside this agent. Those actions need their own authorization, schema inspection, preflight, and approval boundary.

The distinction matters because OCR recognizes text; it does not prove that an invoice is legitimate, unique, mathematically consistent, matched to a purchase order, or safe to pay.

Set Up Aident Loadout

Give your agent the canonical setup instruction exactly as written:

Follow https://aident.ai/SETUP.md

Then confirm authentication and connected accounts:

aident account auth status
aident vault vault --action status

Discover the current Actions by job rather than copying names from an old run:

aident capabilities search \
  --queries '["extract text from one reviewed invoice image","create one record in a Lark Base review queue"]' \
  --types '["action"]'

Copy the exact names returned by discovery. Inspect both live schemas before building a payload:

aident capabilities get \
  --name "<current OCR Action>" \
  --parts '["description","inputSchema","outputSchema","examples"]'

aident capabilities get \
  --name "<current Lark Base record Action>" \
  --parts '["description","inputSchema","outputSchema","examples"]'

On August 11, 2026, the discovered DeepSeek OCR Action was read-only, accepted one imageUrl, and preflighted at zero Aident credits. The Lark record Action accepted a Base app token, table ID, and top-level field object; it also preflighted at zero credits, but remained a write that required explicit acknowledgement. These are dated observations, not permanent pricing or schema guarantees.

Step 1: Create an Authorized Intake Record

Do not let the agent crawl an inbox, drive, or shared folder for arbitrary invoices. Start from a reviewed intake record:

{
  "sourceId": "invoice-intake-2026-0042",
  "imageUrl": "<short-lived-authorized-image-url>",
  "receivedAt": "2026-08-11T16:00:00Z",
  "expectedVendorId": "vendor-018",
  "purchaseOrderId": "PO-2041",
  "retentionClass": "finance-7y",
  "reviewQueue": "accounts-payable"
}

The URL must be accessible to the selected Action without making a private invoice permanently public. Use a short-lived authorized URL and retain the stable internal sourceId for audit and deduplication. Do not put a provider credential, email cookie, local path, or long-lived sharing link in the prompt.

If the source is a multi-page PDF while the inspected Action accepts only an image URL, stop and choose a compatible current Action or create one authorized image per page. Do not assume an image-only contract will preserve page order or tables from a PDF.

Step 2: Preflight and Extract Raw Text

Preflight validates the exact input and reports the Aident credit estimate without dispatching the OCR provider:

aident capabilities preflight \
  --name "<current OCR Action>" \
  --input '{"imageUrl":"<short-lived-authorized-image-url>"}'

Stop if the input is invalid, the estimate is unavailable or above your ceiling, the required connection is not the one you reviewed, or the source URL is no longer authorized. A failed preflight is evidence to fix the boundary, not permission to call the provider directly.

After a valid preflight, execute the exact same bounded read-only input once. Store the returned raw text before asking a model to normalize fields. The official DeepSeek OCR model documentation distinguishes OCR prompts from document-to-Markdown prompts; the live Aident Action schema is still the authority for what this workflow can send.

Step 3: Extract Candidate Fields With Source Evidence

Convert the raw OCR output into candidates, not final accounting facts. Each value needs the source span that supports it:

{
  "field": "invoiceTotal",
  "candidateValue": "1188.40",
  "currency": "USD",
  "sourceText": "TOTAL USD 1,188.40",
  "sourceId": "invoice-intake-2026-0042",
  "confidence": "review_required",
  "validationIssues": []
}

Require source text for vendor name, invoice number, invoice date, currency, subtotal, tax, total, purchase-order reference, and every line item the workflow will retain. If the OCR output does not support a field, return null and add a missing-field issue. Do not infer a tax, repair an unreadable invoice number, or copy a vendor ID from memory.

The inspected Action returns machine-readable text, not a guaranteed field-level confidence or bounding-box contract. Do not invent confidence percentages. A simple state such as review_required, source_verified, or rejected is more honest until another inspected Action supplies stronger evidence.

Step 4: Run Deterministic Checks

Use code or spreadsheet formulas for checks that should not depend on model judgment:

  1. Parse dates and amounts under an explicit locale and currency.

  2. Verify that subtotal plus tax and adjustments equals the stated total within the approved rounding tolerance.

  3. Compare the invoice vendor with the expected vendor record.

  4. Check the purchase-order reference and approved amount when a purchase order exists.

  5. Search the review ledger for a duplicate vendor, invoice number, currency, and total tuple.

  6. Flag a missing invoice number, unreadable total, unsupported currency, first-time vendor, duplicate candidate, or arithmetic mismatch.

Do not transform a failed check into a plausible correction. Preserve both values and route the exception to a person.

Step 5: Write One Review Record to Lark Base

Create the Base and its fields manually first. A practical table keeps:

Field group

Recommended fields

Provenance

Source ID, source link, received time, OCR run time

Candidate data

Vendor, invoice number, date, currency, subtotal, tax, total

Matching

Expected vendor, purchase order, duplicate key, check results

Review

Status, exception reasons, reviewer, reviewed time, decision

Preflight one representative record before any write:

aident capabilities preflight \
  --name "<current Lark Base record Action>" \
  --input '{"appToken":"<reviewed Base>","tableId":"<review queue>","fieldsJson":{"Source ID":"invoice-intake-2026-0042","Review status":"unreviewed"}}'

Show the reviewer the exact destination, fields, exceptions, and quoted cost. Execute only after explicit acknowledgement, using the identical reviewed payload and --acknowledgementScope once. Start with one record. Batch writes only after the table mapping and exception behavior have been verified.

The Lark write is a review-queue mutation, not an invoice approval. Keep Review status at unreviewed and prohibit the agent from setting a payment or ledger state.

Step 6: Review Against the Original Image

The reviewer should see the original invoice beside the candidate record. Verify:

  • vendor identity and remittance details;

  • invoice number, date, and currency;

  • every amount and the arithmetic check;

  • purchase-order and receiving evidence;

  • duplicate-search result;

  • each exception and missing field; and

  • the source link, retention class, and access scope.

A correction should preserve the original candidate, corrected value, reviewer, time, and reason. Those records reveal whether failures come from image quality, OCR, normalization, vendor layout, or the matching rules.

Common Failure Modes

The OCR output looks complete, so the agent approves it

Completeness is not legitimacy or accounting accuracy. Keep approval and payment outside the OCR workflow.

The agent silently fills missing fields

A plausible invoice number or tax amount has no evidentiary value. Return null, preserve the source text, and flag the field.

A private invoice is uploaded to a permanent public URL

Use an authorized short-lived transfer path. Preserve only the stable source reference required by the retention policy.

A low-risk read becomes an unreviewed write

Treat OCR extraction and Lark record creation as separate Actions. Inspect, preflight, and authorize each boundary independently.

The first successful invoice becomes the batch template

Test clean scans, rotated images, low contrast, multiple currencies, duplicate invoice numbers, missing purchase orders, and arithmetic mismatches before increasing the batch size.

A Reusable Agent Prompt

Follow https://aident.ai/SETUP.md

Build a review-only invoice OCR workflow for the authorized intake manifest.

1. Confirm Aident authentication and Vault status.
2. Discover current Actions for OCR from an image URL and for creating a Lark
   Base review record. Inspect both schemas and preflight exact inputs.
3. Process only the reviewed short-lived image URLs in the manifest.
4. Preserve raw OCR text. Extract candidate fields only when source text
   supports them; otherwise return null and an exception.
5. Run deterministic date, arithmetic, vendor, purchase-order, and duplicate
   checks. Never repair a failed check by guessing.
6. Show me the exact Lark destination, payload, exceptions, and quote.
7. After my explicit acknowledgement, write one record with status unreviewed.
8. Do not approve an invoice, create a vendor, post a ledger entry, schedule a
   payment, expose credentials, or make a source file public.
9. Return the source ID, Action receipts, validation results, review record ID,
   cost, and every field that still needs a person

Success means every candidate field is traceable to raw OCR text, deterministic checks are reproducible, one explicitly acknowledged review record reaches the intended Lark table, and no financial action occurs.

Measure source coverage, fields corrected per invoice, exception rate by vendor, duplicate detection, review time, and credits per accepted record. Do not optimize for a high extraction rate if it comes from filling unsupported fields.

For the broader connection and approval model, read How to Connect Claude Code and Codex to Real-World Tools. Pair this workflow with AI Agent Cost Guardrails and How to Give AI Agents API Access Without Exposing Keys.

Set up Aident Loadout and build one review-only invoice OCR run.

Sources

Home

Home

Home

Integrations

Integrations

Integrations

Vault

Vault

Vault

Audit

Audit

Audit

Arana Grande

Arana Grande

Arana Grande

Free

Free

Free

30-day audit summary

30-day audit summary

30-day audit summary

Daily action-call volume and the latest receipts from the Loadout audit trail.

Daily action-call volume and the latest receipts from the Loadout audit trail.

Daily action-call volume and the latest receipts from the Loadout audit trail.

View Audit

View Audit

View Audit

Loadout usage

Loadout usage

Loadout usage

617 action calls in the last 30 days

617 action calls in the last 30 days

617 action calls in the last 30 days

May 19 - Jun 17

May 19 - Jun 17

May 19 - Jun 17

10 active days

10 active days

10 active days

Less

Less

Less

More

More

More

Recent activity

Recent activity

Recent activity

Latest action-call receipts from connected agents

Latest action-call receipts from connected agents

Latest action-call receipts from connected agents

Apr 23, 09:23 AM

Apr 23, 09:23 AM

Apr 23, 09:23 AM

Shopify

Shopify

Shopify

Creates Or Updates An Asset For A Theme

Creates Or Updates An Asset For A Theme

Creates Or Updates An Asset For A Theme

Success

Success

Success

Apr 23, 09:21 AM

Apr 23, 09:21 AM

Apr 23, 09:21 AM

Shopify

Shopify

Shopify

Update Products Param Product Id

Update Products Param Product Id

Update Products Param Product Id

Success

Success

Success

Apr 23, 08:53 AM

Apr 23, 08:53 AM

Apr 23, 08:53 AM

Shopify

Shopify

Shopify

Update Products Param Product Id

Update Products Param Product Id

Update Products Param Product Id

Failed

Failed

Failed

Apr 22, 22:13 PM

Apr 22, 22:13 PM

Apr 22, 22:13 PM

Shopify

Shopify

Shopify

Create Product Image

Create Product Image

Create Product Image

Success

Success

Success

Apr 22, 22:12 PM

Apr 22, 22:12 PM

Apr 22, 22:12 PM

Shopify

Shopify

Shopify

Create Product Image

Create Product Image

Create Product Image

Success

Success

Success

Connected integration coverage

Connected integration coverage

Connected integration coverage

162

162

162

of 753 accessible connected

of 753 accessible connected

of 753 accessible connected

Callable actions

Callable actions

Callable actions

1,126

1,126

1,126

Vault credentials

Vault credentials

Vault credentials

8

8

8

Explore what's possible

Explore what's possible

Explore what's possible

See all Integrations

See all Integrations

See all Integrations

Google Ads

Google Ads

Google Ads

All available Goolge Ads tools via...

All available Goolge Ads tools via...

All available Goolge Ads tools via...

X (twitter)

X (twitter)

X (twitter)

All available X tools via...

All available X tools via...

All available X tools via...

Github

Github

Github

All available Github tools via...

All available Github tools via...

All available Github tools via...

Notion

Notion

Notion

All available Notion tools via...

All available Notion tools via...

All available Notion tools via...

Slack

Slack

Slack

All available Slack tools via...

All available Slack tools via...

All available Slack tools via...

Firecrawl

Firecrawl

Firecrawl

All available Firecrawl tools via...

All available Firecrawl tools via...

All available Firecrawl tools via...

753 integrations are available for loadouts.

753 integrations are available for loadouts.

753 integrations are available for loadouts.

The one tool

for every tool

your agent needs.

Give any AI agent real capabilities in seconds. Connect 1,000+ tools once, skip the setup headache, and let your agents execute.

Try Aident Loadout

Give your Agent real capabilities in minutes. Connect 1,000+ tools, and let your agents execute.

Try Aident Loadout

Give your Agent real capabilities in minutes. Connect 1,000+ tools, and let your agents execute.

Try Aident Loadout

Give your Agent real capabilities in minutes. Connect 1,000+ tools, and let your agents execute.