← Work

Case study 01

Clarivo

Autonomous accounts payable: three-way matching and exception resolution with LLM agents.

Role
Backend and AI pipeline (team capstone, VIT Bhopal)
Period
2026
Stack
Django REST FrameworkAWS LambdaDocker · ECRS3DynamoDBWeaviateGeminiTesseract OCRGmail APIGCP Pub/Sub

Problem

Three-way matching compares a purchase order, a goods-received note and an invoice. Detecting a mismatch is routine; resolving it is where the manual work piles up. Clarivo targets mid-market Indian manufacturers and the accounting firms that serve them: it ingests documents from email, finds discrepancies with cited evidence, and closes the explainable ones without a human.

Architecture

Clarivo ArchitectureInvoices arrive by Gmail push notification, land in S3, are extracted by a containerized Lambda, indexed in Weaviate, judged by an LLM with cited evidence, verified by a grounding check, stored as case state, and served through a Django API to a dashboard and copilot. New evidence re-opens closed invoices.IngestExtract & storeIndex & retrieveReason & verifyServeembed01Gmail mailbox watchOAuth 2.002Pub/Sub pushtriggers a Django webhook03S3attachments land here04Lambda (container on ECR)native PDF parse, orTesseract OCR for scans05DynamoDBextracted text and fields06Weaviatechunks and embeddings07Hybrid searchBM25 + dense, token-budgeted08LLM verdictstructured JSON with citedevidence09Grounding checkevery cited figure verifiedagainst source10Case stateclean · flagged ·auto-resolved · needs info11Django REST APIaudit trail12Dashboard + RAG copilot
  • external
  • compute
  • store
  • llm
  • check
  • ui
  1. Ingest

    01

    Gmail mailbox watch

    OAuth 2.0

  2. 02

    Pub/Sub push

    triggers a Django webhook

  3. Extract & store

    03

    S3

    attachments land here

  4. 04

    Lambda (container on ECR)

    native PDF parse, or Tesseract OCR for scans

    embed

  5. 05

    DynamoDB

    extracted text and fields

  6. Index & retrieve

    06

    Weaviate

    chunks and embeddings

  7. 07

    Hybrid search

    BM25 + dense, token-budgeted

  8. Reason & verify

    08

    LLM verdict

    structured JSON with cited evidence

  9. 09

    Grounding check

    every cited figure verified against source

  10. 10

    Case state

    clean · flagged · auto-resolved · needs info

    ↺ new PO or delivery re-opens closed invoices

  11. Serve

    11

    Django REST API

    audit trail

  12. 12

    Dashboard + RAG copilot

Architecture as built. Dashed lines are feedback paths.

Key decisions

01

Reasoning over field matching

Field-by-field matching broke on informal and inconsistent documents. Each invoice is now judged by one LLM call over the related purchase orders, delivery notes and earlier invoices, returning a verdict with cited evidence.

02

Grounding stays in code

The model never grades itself. A deterministic check confirms each cited figure actually appears in the retrieved source; anything unverified is flagged for review instead of silently trusted.

03

Re-evaluate when evidence changes

Early on, an invoice that had been checked once was never looked at again. Now a new order or delivery from the same supplier re-opens matching invoices, so split-shipment overbills resolve themselves when the missing delivery arrives.

04

Containers for OCR

Tesseract's binaries do not fit in a Lambda zip package, so extraction ships as a container image on ECR. PDFs with a text layer skip OCR entirely.

05

Test data I had to author

I could not find a public dataset that links purchase orders, delivery notes, invoices and payments with planted discrepancies, so I wrote one by hand covering six error classes.

Where it falls short

  • Grounding verifies that cited figures exist in the source; it does not verify the model's conclusion. A wrong inference from correct figures still needs human review.
  • The evaluation set is hand-authored, so it checks for regressions rather than claiming real-world accuracy.