OCRAgent: Extracting text from PDFs, invoices, and scans
Turn scanned receipts and PDFs into clean text
While VisionAgent answers high-level visual questions, OCRAgent is tuned specifically for high-accuracy text extraction from invoices, contracts, tables, and multi-page PDFs.
Example
from praisonai import OCRAgent
ocr = OCRAgent()
text = ocr.extract('invoice_2026.pdf')
print(text)Example explained
- OCRAgent() — Instantiates PraisonAI's document OCR specialist with structured text extraction defaults.
- ocr.extract(…) — Extracts clean markdown/plain text from PDFs and scanned images.
Post-process OCR text into structured invoice fields
A classic production pipeline pairs OCRAgent (raw text extraction) with a typed Pydantic parser (vendor, total, due_date) so accounting systems get clean validated records.
Example
from pydantic import BaseModel
from praisonai import Agent
class InvoiceRecord(BaseModel):
vendor: str
total_usd: float
due_date: str
ocr_text = 'ACME Cloud Inc.\nInvoice #992\nTotal Due: $1,240.50\nDue Date: 2026-12-15'
parser = Agent(instructions='Extract vendor, total_usd, and due_date.')
inv = parser.chat(ocr_text, output_pydantic=InvoiceRecord)
print('Parsed invoice:', inv.model_dump())Example explained
- InvoiceRecord — Enforces float currency and string date fields right after OCR extraction.
Common pitfall: trusting OCR numbers without sanity checks
Always cross-check subtotal + tax == total in Python after OCR extraction — catching a single misread digit automatically.
Reference: documentation