An intelligent pipeline that automates the lifecycle of invoice processing. This system uses a local LLM (Llama 3.2 via Ollama) or xAI/OpenAI-compatible APIs to handle data extraction, inventory validation, and risk-based payment approvals.
- Multi-Agent Architecture: Modular agents for Ingestion, Validation, Approval, and Payment.
- Duplicate Detection: Uses
invoice_idas a primary key to prevent double processing of the same invoice. - Fuzzy Item Matching: Automatically corrects typos in invoice
items (e.g., "WidgtA" → "WidgetA") using
diffliband AI. - Inventory Check: Real-time stock validation against a local SQLite database.
- Structured Logging: Appends every transaction to a single
transaction_history.jsonfile. - Excel Reporting: Automatically converts JSON logs into a clean
audit_report.xlsxfor financial review.
- Python 3.8+
- Ollama: Download and install Ollama.
- Local LLM: Pull the model by running:
ollama run llama3.2:1bClone the repository and install the required Python libraries:
pip install ollama pdfplumber pandas openpyxl python-dotenv openaiCreate a .env file in the root directory to store your API keys
securely (this file is ignored by Git):
XAI_API_KEY=your_xai_api_key_here
Before running the pipeline for the first time, initialize your inventory database:
python tools/database.pyThis creates acme_inventory.db with default stock for WidgetA,
WidgetB, and GadgetX.
To process an invoice, run the main.py script and provide the path to
your PDF:
python main.py --invoice invoices/sample_invoice.pdf- Ingestion: Reads PDF and converts text to JSON.
- Duplicate Check: Rejects the file if the
invoice_idalready exists in logs. - Validation: Verifies item names and stock levels.
- Approval: Checks if the amount exceeds the $10,000 threshold for manual critique.
- Payment: Simulates a banking transaction and updates the Excel audit report.
agents/: Logic for ingestion, validation, and approval.tools/: Database management, LLM client, and structured logger.logs/: Contains thetransaction_history.jsonandaudit_report.xlsx.main.py: The central coordinator for the entire system.
Your .env file and logs/ folder are listed in the .gitignore to
prevent sensitive API keys or transaction data from being pushed to
GitHub.