Intelligent Invoice Reimbursement

Scores invoices against HR policy in parallel processes, then answers questions over the verdicts with metadata filters.

LLM / RAG2025All work

Fig. 01InvoiceReimburse, policy upload and invoice analysis.
InvoiceReimburse, policy upload and invoice analysis.

What it is

What it does

Upload an HR policy and a ZIP of employee invoices; every invoice comes back classified Fully Reimbursed, Partially Reimbursed or Declined with a written justification. Both the raw text and the verdict land in ChromaDB, so a follow-up chatbot can answer audit questions like 'which of Amit's invoices were declined in March?' in plain language.

Why it exists

My first reimbursement audit was a zip of 30 PDFs and a policy doc no one had read. I built this so a zip goes in and a clear 'reimbursed / partial / declined + why' comes out, and the whole trail stays searchable afterwards. No spreadsheet archaeology.

3
Status classes
3
Metadata filters
2
Docs per invoice

Repo Amit-kr26/Intelligent-Invoice-ReimbursementDemo intelligent-invoice-reimbursement.onrender.com/Stack FastAPI · LangChain · Gemini 2.5 Flash · ChromaDB

Hosted on a free tier, so the demo may take about 60s to wake on first load.

Build6decisions

How it is built

Batch ZIP intake

POST /analyze-invoices/ validates the policy (.pdf/.docx) and invoice ZIP extensions, extracts to data/<employee>/ and walks it recursively for PDFs.

Process-per-invoice

A ProcessPoolExecutor fans out one analyze_single_invoice future per file; each subprocess re-instantiates its own Gemini client and Chroma handle to stay multiprocessing-safe.

Strict three-key verdicts

An LLMChain over gemini-2.5-flash must emit reimbursement_status (enum), reason and invoice_date. Fenced-JSON regex parsing degrades gracefully to a raw-output record when the model misbehaves.

Double-sided indexing

Each invoice produces two Chroma documents (invoice_text and analysis_result) under deterministic IDs with employee, status, reason, date, filename and type metadata.

Filtered RAG chatbot

A LCEL chain ({context: retriever | format_docs} | prompt | llm) backs POST /chatbot/, supporting exact-match metadata filters on employee_name, reimbursement_status and invoice_date.

Thoughtful little UI

Vanilla HTML/JS with marked-rendered bot replies, a regex-tokenised JSON syntax highlighter, toast notifications and persisted dark/light themes.

How the pieces connect

Ingest and analyse Index and query Policy + ZIP upload FastAPI multipart Policy text PDF or DOCX Process pool one future per PDF Gemini 2.5 Flash reason + 3 statuses Embeddings 001 models/embedding-001 FastAPI /chatbot query + 3 filters Chroma retriever metadata filter ChromaDB 2 docs per invoice LCEL chain context + question Markdown + JSON download, copy indexed as two documents per invoice one process per invoice