An automated accounts payable system that processes invoices from email attachments, extracts structured data, matches against purchase orders, and manages vendor payments.
TMC-v1 transforms the traditional invoice processing workflow by automating every step from email intake to payment. The system monitors email accounts for invoice attachments, extracts invoice data with high accuracy, matches invoices to purchase orders, flags exceptions, and processes payments through Stripe integration.
This is a real solution to a real problem. Companies receive hundreds or thousands of invoices every month through email. Each invoice needs to be opened, reviewed, data entered into the system, matched to purchase orders, approved, and paid. This manual process takes days of employee time and introduces errors at every step.
The entire project stands on the accuracy and reliability of Landing AI's Document Processing Engine. Without Landing AI, this system would not work in production.
Invoice processing has always been difficult because invoices come in every format imaginable. Different vendors use different templates, different languages, different layouts. Some invoices are cleanly formatted PDFs generated from accounting software. Others are scanned images of handwritten forms or faxed documents that have been photocopied multiple times.
Traditional OCR tools fail on this variety. They might work well on one vendor's invoices but completely miss critical fields on another vendor's format. They struggle with tables, with multi-line addresses, with tax calculations that span multiple rows.
Landing AI handles all of this. The system processes invoices from vendors we have never seen before and extracts the data correctly. It understands that an invoice number might be called "Invoice #" or "Inv No." or "Factura" depending on the vendor. It recognizes line items even when they are formatted as tables, as lists, or as unstructured text blocks.
The OCR integration is straightforward but powerful. When an invoice file arrives, we pass it to Landing AI's Document Processing Engine with our schema definition:
def ocr_invoice_to_json(invoice_path: str) -> str | None: client = LandingAIADE() parse_response = client.parse(document=path, model="dpt-2-latest") schema = pydantic_to_json_schema(InvoiceExtract) extract_response = client.extract(schema=schema, markdown=parse_response.markdown) return extract_json_path
text
Landing AI returns structured JSON with every field we need. Vendor name, tax ID, invoice number, date, line items with quantities and prices, totals, payment terms, everything. The accuracy is consistently high across different invoice formats.
Our invoice schema defines exactly what we need from every invoice:
- Vendor information: name, tax ID, address
- Invoice metadata: invoice number, date, due date, PO reference
- Financial details: currency, subtotal, tax, shipping, discounts, total
- Line items: description, SKU, quantity, unit price, line totals, PO line references
- Payment information: bank account, SWIFT code, remittance reference
Landing AI fills all of these fields from the raw invoice document. The system handles complex scenarios like multi-page invoices, invoices with embedded tables, invoices in different currencies, invoices with partial line-item matches to purchase orders.
Here is what Landing AI's accuracy means in practice:
Time Savings: A typical company processing 500 invoices per month spends approximately 15 minutes per invoice on manual data entry and verification. That is 125 hours per month, or roughly three full-time employees. With automated extraction, that drops to perhaps 2 minutes per invoice for exception handling, saving over 100 hours monthly.
Error Reduction: Manual data entry has an error rate of 1-3% even with careful operators. On 500 invoices with an average of 20 data points each, that means 100-300 errors per month. These errors cause payment delays, vendor relationship issues, and accounting reconciliation problems. Automated extraction reduces errors to near zero.
Faster Payment Cycles: Manual processing means invoices sit in queues waiting for data entry. With automated extraction, invoices are processed within minutes of arrival. Vendors get paid faster, early payment discounts can be captured, and cash flow is more predictable.
Scale Without Headcount: As companies grow and invoice volume increases, they typically need to hire more AP staff. With automation, the same small team can handle 500 invoices or 5000 invoices without proportional headcount growth.
Invoice processing is a solved problem on the extraction side because of Landing AI. The technology works reliably in production. This is not a prototype or a concept demonstration. This is a system that can handle real invoice volume from real vendors tomorrow.
The accuracy of Landing AI's extraction is what makes the entire automated workflow possible. Purchase order matching depends on correctly extracted PO numbers and totals. Payment processing depends on correctly extracted bank details and amounts. Exception handling depends on having reliable data to flag mismatches. Every downstream feature in this system depends on the quality of the OCR layer.
Landing AI has made enterprise invoice processing automatable. That is the foundation this project builds on.
The backend handles all the processing logic:
- Email monitoring: IMAP client that checks configured email accounts on a schedule
- Document storage: Local file storage with organized vendor directories
- OCR processing: Landing AI integration for invoice data extraction
- Database operations: PostgreSQL for all structured data (invoices, POs, vendors, payments)
- PO matching: Automated matching logic with tolerance thresholds
- Payment processing: Stripe integration for vendor payments
- Chat/AI assistance: Claude integration for vendor-scoped queries about invoices and POs
The web interface provides:
- Dashboard: Overview stats, graphs, recent invoices
- Invoice management: View, search, and manage all invoices
- Exception handling: Review and resolve unmatched invoices
- Vendor management: Vendor profiles with invoice history
- Payment interface: Select invoices and process batch payments
- Chat interface: AI assistant for querying invoice and PO data
- invoices: All invoice records with extracted fields
- purchase_orders: PO records for matching
- vendors: Vendor master data
- payments: Payment transaction history
- chats/messages: Vendor-scoped conversation history
The system monitors email accounts and automatically downloads invoice attachments from configured vendor addresses. It identifies invoice files by content type and filename patterns, stores them in organized directories, and queues them for processing.
Landing AI OCR extracts all relevant data from invoice PDFs and images. The system handles invoices in multiple formats, currencies, and languages. Line items are extracted with full detail including quantities, prices, and SKU references.
Invoices are automatically matched to open purchase orders based on PO number, vendor, currency, and amount. The matching algorithm uses configurable tolerance thresholds to handle expected variations in shipping charges or partial deliveries.
Unmatched invoices, vendor mismatches, and invoices requiring manual review are flagged with specific status codes. The frontend provides tools to review exceptions, view source documents, and manually resolve issues.
The payment module integrates with Stripe to process vendor payments. Users can select multiple invoices, review totals by currency, and initiate payment with customer billing details. Payment status updates flow back to invoice records.
Each vendor has a chat interface powered by Claude. The AI assistant can answer questions about specific invoices, PO status, payment history, and vendor statistics. The chat uses @ mentions to reference specific invoices or POs, providing context-aware responses.
- Python 3.10+
- Node.js 16+
- PostgreSQL database
- Landing AI API key
- Stripe account (for payments)
- Claude API key (for chat features)
Install Python dependencies pip install -r requirements.txt
Create .env file with required configuration VISION_AGENT_API_KEY=your_landing_ai_key IMAP_HOST=your_email_host EMAIL_USERNAME=your_email EMAIL_PASSWORD=your_password DATABASE_URL=postgresql://user:pass@host/db STRIPE_API_KEY=your_stripe_key ANTHROPIC_API_KEY=your_claude_key CHECK_INTERVAL_SECONDS=300
text
cd frontend npm install npm start
text
The system includes Alembic migrations for database schema management. Run migrations with:
alembic upgrade head
text
Configure IMAP connection details and target sender addresses in .env:
IMAP_HOST=imap.gmail.com IMAP_PORT=993 EMAIL_USERNAME=ap@company.com EMAIL_PASSWORD=app_password TARGET_SENDERS=vendor1@example.com,vendor2@example.com
text
Landing AI configuration uses the DPT-2 model by default:
VISION_AGENT_API_KEY=your_api_key ADE_MODEL=dpt-2-latest ADE_ENVIRONMENT=production
text
Purchase order matching uses configurable thresholds:
amount_tolerance = 1.0 # absolute amount difference allowed percent_tolerance = 0.02 # 2% variance allowed
text
GET /api/invoices/recent?limit=10- Recent invoicesGET /api/invoices/<id>- Invoice detailGET /api/invoices/exceptions- Exception invoicesGET /api/invoices/payable- Payable invoices
GET /api/vendors- All vendors with statsGET /api/vendors/<id>- Vendor detailPOST /api/vendors- Create vendorDELETE /api/vendors/<id>- Delete vendor
POST /api/payments/create-intent- Create Stripe payment intentPOST /api/payments/confirm- Confirm paymentPOST /api/payments/cancel- Cancel payment
POST /api/vendors/<id>/chat/start- Start or resume chatGET /api/vendors/<id>/chat- List chats for vendorGET /api/vendors/<id>/chat/<chat_id>/messages- Get messagesPOST /api/vendors/<id>/chat/<chat_id>/messages- Send message
Use the upload interface to manually process an invoice:
- Navigate to
/upload - Select the vendor from the dropdown
- Choose the invoice file
- Upload and process
The system will extract invoice data with Landing AI, save it to the database, and attempt to match it to an open purchase order.
Exception invoices appear in the dashboard and can be filtered by status:
unmatched: No matching PO foundvendor_mismatch: Invoice vendor does not match PO vendorneeds_review: Manual review required
Select invoices for payment in the vendor or payment interface. The system groups invoices by currency and creates a Stripe payment intent. After customer approval and payment completion, invoice status updates to paid.
# Project Structure
tmc-v1/
├── app.py # Main Flask application
├── ocr_landingai.py # Landing AI OCR integration
├── invoice_schema.py # Pydantic schema for invoice extraction
├── invoice_db.py # Invoice database operations
├── po_matching.py # Purchase order matching logic
├── email_client.py # Email intake and processing
├── vendor_db.py # Vendor management
├── payments.py # Stripe payment integration
├── chat_db.py # Chat persistence
├── chat_llm.py # Claude chat integration
├── frontend/ # React web interface
│ ├── src/
│ │ ├── pages/ # Main application pages
│ │ ├── components/ # Reusable UI components
│ │ └── lib/ # Utilities and API client
│ └── package.json
└── requirements.txt # Python dependencies
Start the backend:
python app.py
Start the frontend:
cd frontend npm start
The application runs on http://localhost:3000 with API backend on http://localhost:5000.
The system includes invoice detector tests and can be tested with sample invoices from various vendors.
MIT License - see LICENSE file for details.
Built with Landing AI Document Processing Engine for accurate, reliable invoice data extraction at scale.