Aident AI

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:
Then confirm authentication and connected accounts:
Discover the current Actions by job rather than copying names from an old run:
Copy the exact names returned by discovery. Inspect both live schemas before building a payload:
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:
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:
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:
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:
Parse dates and amounts under an explicit locale and currency.
Verify that subtotal plus tax and adjustments equals the stated total within the approved rounding tolerance.
Compare the invoice vendor with the expected vendor record.
Check the purchase-order reference and approved amount when a purchase order exists.
Search the review ledger for a duplicate vendor, invoice number, currency, and total tuple.
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:
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
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
DeepSeek OCR model documentation, official model card, accessed August 11, 2026
DeepSeek OCR source repository, official repository, accessed August 11, 2026
Automated Invoice Processing: A Step-by-Step Guide, Ramp, published July 16, 2026
What Is OCR AP Automation?, Lido, published July 8, 2026



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.
