WorkflowForgeAI Agent and Workflow Laboratory
WorkflowForgeAgentsshortfall
Home
WorkflowForge · AI Agent and Workflow Laboratory © 2026Built by Shivang GitHub
Agents
Agent

shortfall

aicreditsgpt-4o-minitemp 0max 1200 tokensagents/shortfallcustom result view

Audits short payments from B2B customers: matches bank credits to invoices, checks every deduction against your documents and drafts disputes.

Open in Playground

README

agents/shortfall/README.md

Shortfall

Short-payment and deduction audit for Indian B2B suppliers.

When a customer pays less than the invoice, the gap is a mix of tax withheld (TDS), fair claims, and deductions you could push back on: rate differences, shortages, scheme claims, display fees, penalties, late cash discounts. Shortfall works out where every rupee went, checks each deduction against your own documents, and drafts the dispute emails. A person reviews and sends them; the agent never sends anything.

For: accounts-receivable teams at mid-size manufacturers, brands and distributors selling to modern trade, quick commerce, distributors and corporates, and the CA firms that keep their books.

Try it

  • Demo: run with the prompt demo, or Extra inputs {"demo": true}. It audits a bundled, fictional month for "Demo Foods Pvt Ltd": three customers, three payment advices (one arriving as raw text), five bank credits, delivery documents and trade terms. About 9 LLM calls.
  • Paste a payment advice as the prompt. Shortfall reads it, checks that its figures add up and classifies each deduction. Add open_invoices and evidence in Extra inputs to get invoice matches and verdicts too.
  • Full audit: send your data as Extra inputs (JSON). Every key is optional, but you need or .

Output schema

the final answer must be JSON matching this schema
{
  "$defs": {
    "AdviceResult": {
      "properties": {
        "advice_id": {
          "title": "Advice Id",
          "type": "string"
        },
        "customer": {
          "title": "Customer",
          "type": "string"
        },
        "date": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Date"
        },
        "reference": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Reference"
        },
        "total_net": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Total Net"
        },
        "source": {
          "enum": [
            "structured",
            "extracted",
            "unreadable",
            "inferred_from_credit"
          ],
          "title": "Source",
          "type": "string"
        },
        "bank_credit_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Bank Credit Id"
        },
        "lines": {
          "items": {
            "$ref": "#/$defs/LineResult"
          },
          "title": "Lines",
          "type": "array"
        },
        "notes": {
          "items": {
            "type": "string"
          },
          "title": "Notes",
          "type": "array"
        }
      },
      "required": [
        "advice_id",
        "customer",
        "source"
      ],
      "title": "AdviceResult",
      "type": "object"
    },
    "CreditResult": {
      "properties": {
        "credit_id": {
          "title": "Credit Id",
          "type": "string"
        },
        "date": {
          "title": "Date",
          "type": "string"
        },
        "amount": {
          "title": "Amount",
          "type": "number"
        },
        "narration": {
          "title": "Narration",
          "type": "string"
        },
        "customer": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Customer"
        },
        "status": {
          "enum": [
            "matched_to_advice",
            "inferred_invoices",
            "ambiguous",
            "unexplained"
          ],
          "title": "Status",
          "type": "string"
        },
        "advice_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Advice Id"
        },
        "invoices": {
          "items": {
            "type": "string"
          },
          "title": "Invoices",
          "type": "array"
        },
        "inferred_tds": {
          "default": 0,
          "title": "Inferred Tds",
          "type": "number"
        },
        "alternatives": {
          "items": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "title": "Alternatives",
          "type": "array"
        },
        "note": {
          "default": "",
          "title": "Note",
          "type": "string"
        }
      },
      "required": [
        "credit_id",
        "date",
        "amount",
        "narration",
        "status"
      ],
      "title": "CreditResult",
      "type": "object"
    },
    "CustomerSummary": {
      "properties": {
        "customer": {
          "title": "Customer",
          "type": "string"
        },
        "short_received": {
          "title": "Short Received",
          "type": "number"
        },
        "statutory": {
          "title": "Statutory",
          "type": "number"
        },
        "statutory_at_risk": {
          "title": "Statutory At Risk",
          "type": "number"
        },
        "disputable": {
          "title": "Disputable",
          "type": "number"
        },
        "valid": {
          "title": "Valid",
          "type": "number"
        },
        "needs_human": {
          "title": "Needs Human",
          "type": "number"
        },
        "no_evidence": {
          "title": "No Evidence",
          "type": "number"
        },
        "findings": {
          "title": "Findings",
          "type": "integer"
        }
      },
      "required": [
        "customer",
        "short_received",
        "statutory",
        "statutory_at_risk",
        "disputable",
        "valid",
        "needs_human",
        "no_evidence",
        "findings"
      ],
      "title": "CustomerSummary",
      "type": "object"
    },
    "Draft": {
      "properties": {
        "kind": {
          "enum": [
            "dispute",
            "advice_request",
            "tds_followup"
          ],
          "title": "Kind",
          "type": "string"
        },
        "customer": {
          "title": "Customer",
          "type": "string"
        },
        "subject": {
          "title": "Subject",
          "type": "string"
        },
        "body": {
          "title": "Body",
          "type": "string"
        },
        "amount": {
          "title": "Amount",
          "type": "number"
        },
        "finding_ids": {
          "items": {
            "type": "string"
          },
          "title": "Finding Ids",
          "type": "array"
        },
        "attachments": {
          "items": {
            "type": "string"
          },
          "title": "Attachments",
          "type": "array"
        }
      },
      "required": [
        "kind",
        "customer",
        "subject",
        "body",
        "amount"
      ],
      "title": "Draft",
      "type": "object"
    },
    "EvidenceRef": {
      "properties": {
        "doc_id": {
          "title": "Doc Id",
          "type": "string"
        },
        "quote": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Quote"
        }
      },
      "required": [
        "doc_id"
      ],
      "title": "EvidenceRef",
      "type": "object"
    },
    "Finding": {
      "properties": {
        "finding_id": {
          "title": "Finding Id",
          "type": "string"
        },
        "advice_id": {
          "title": "Advice Id",
          "type": "string"
        },
        "customer": {
          "title": "Customer",
          "type": "string"
        },
        "invoice_no": {
          "title": "Invoice No",
          "type": "string"
        },
        "matched_invoice": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Matched Invoice"
        },
        "label": {
          "title": "Label",
          "type": "string"
        },
        "ref": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Ref"
        },
        "category": {
          "title": "Category",
          "type": "string"
        },
        "family": {
          "enum": [
            "statutory",
            "commercial",
            "unknown"
          ],
          "title": "Family",
          "type": "string"
        },
        "amount": {
          "title": "Amount",
          "type": "number"
        },
        "verdict": {
          "enum": [
            "disputable",
            "partly_disputable",
            "valid",
            "needs_human",
            "no_evidence",
            "recoverable_credit",
            "credit_mismatch"
          ],
          "title": "Verdict",
          "type": "string"
        },
        "disputable_amount": {
          "default": 0,
          "title": "Disputable Amount",
          "type": "number"
        },
        "reason": {
          "title": "Reason",
          "type": "string"
        },
        "evidence": {
          "items": {
            "$ref": "#/$defs/EvidenceRef"
          },
          "title": "Evidence",
          "type": "array"
        },
        "method": {
          "default": "rule",
          "enum": [
            "rule",
            "llm+rule",
            "none"
          ],
          "title": "Method",
          "type": "string"
        },
        "confidence": {
          "default": 1,
          "title": "Confidence",
          "type": "number"
        }
      },
      "required": [
        "finding_id",
        "advice_id",
        "customer",
        "invoice_no",
        "label",
        "category",
        "family",
        "amount",
        "verdict",
        "reason"
      ],
      "title": "Finding",
      "type": "object"
    },
    "LLMUsage": {
      "properties": {
        "calls": {
          "title": "Calls",
          "type": "integer"
        },
        "budget": {
          "title": "Budget",
          "type": "integer"
        },
        "skipped": {
          "title": "Skipped",
          "type": "integer"
        },
        "failures": {
          "items": {
            "type": "string"
          },
          "title": "Failures",
          "type": "array"
        }
      },
      "required": [
        "calls",
        "budget",
        "skipped"
      ],
      "title": "LLMUsage",
      "type": "object"
    },
    "LineResult": {
      "properties": {
        "invoice_no": {
          "title": "Invoice No",
          "type": "string"
        },
        "matched_invoice": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Matched Invoice"
        },
        "match": {
          "enum": [
            "exact",
            "fuzzy",
            "gross_mismatch",
            "not_found"
          ],
          "title": "Match",
          "type": "string"
        },
        "gross": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Gross"
        },
        "deductions_total": {
          "default": 0,
          "title": "Deductions Total",
          "type": "number"
        },
        "net": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Net"
        },
        "arithmetic": {
          "enum": [
            "ok",
            "mismatch",
            "derived"
          ],
          "title": "Arithmetic",
          "type": "string"
        }
      },
      "required": [
        "invoice_no",
        "match",
        "arithmetic"
      ],
      "title": "LineResult",
      "type": "object"
    },
    "Totals": {
      "properties": {
        "short_received": {
          "title": "Short Received",
          "type": "number"
        },
        "statutory": {
          "title": "Statutory",
          "type": "number"
        },
        "statutory_at_risk": {
          "title": "Statutory At Risk",
          "type": "number"
        },
        "commercial": {
          "title": "Commercial",
          "type": "number"
        },
        "disputable": {
          "title": "Disputable",
          "type": "number"
        },
        "valid": {
          "title": "Valid",
          "type": "number"
        },
        "needs_human": {
          "title": "Needs Human",
          "type": "number"
        },
        "no_evidence": {
          "title": "No Evidence",
          "type": "number"
        },
        "unexplained_credits": {
          "title": "Unexplained Credits",
          "type": "number"
        },
        "unexplained_credit_count": {
          "title": "Unexplained Credit Count",
          "type": "integer"
        }
      },
      "required": [
        "short_received",
        "statutory",
        "statutory_at_risk",
        "commercial",
        "disputable",
        "valid",
        "needs_human",
        "no_evidence",
        "unexplained_credits",
        "unexplained_credit_count"
      ],
      "title": "Totals",
      "type": "object"
    }
  },
  "properties": {
    "company": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Company"
    },
    "demo": {
      "default": false,
      "title": "Demo",
      "type": "boolean"
    },
    "totals": {
      "$ref": "#/$defs/Totals"
    },
    "customers": {
      "items": {
        "$ref": "#/$defs/CustomerSummary"
      },
      "title": "Customers",
      "type": "array"
    },
    "findings": {
      "items": {
        "$ref": "#/$defs/Finding"
      },
      "title": "Findings",
      "type": "array"
    },
    "advices": {
      "items": {
        "$ref": "#/$defs/AdviceResult"
      },
      "title": "Advices",
      "type": "array"
    },
    "credits": {
      "items": {
        "$ref": "#/$defs/CreditResult"
      },
      "title": "Credits",
      "type": "array"
    },
    "drafts": {
      "items": {
        "$ref": "#/$defs/Draft"
      },
      "title": "Drafts",
      "type": "array"
    },
    "warnings": {
      "items": {
        "type": "string"
      },
      "title": "Warnings",
      "type": "array"
    },
    "llm": {
      "$ref": "#/$defs/LLMUsage"
    }
  },
  "required": [
    "totals",
    "customers",
    "findings",
    "advices",
    "credits",
    "drafts",
    "warnings",
    "llm"
  ],
  "title": "AuditReport",
  "type": "object"
}

Evaluation

agents/shortfall/evaluation · 6 cases · suite shortfall_golden

Scores Shortfall audits against hand-labelled scenarios: each deduction's verdict, the rupees flagged as disputable, tax credit missing from Form 168, and how bank credits were allocated to invoices.

Not evaluated yet.

All suites

Past runs

standalone runs from the Playground · latest 50

No runs yet

Run this agent on its own in the Playground; every run shows up here with a replay.

Try it in the Playground
advices
bank_credits
KeyWhat it holds
advicesPayment advices: advice_id, customer, date, reference (UTR), total_net, and either lines (invoice_no, gross, net, deductions: [{label, amount, ref}]) or text (the raw advice, read by the LLM).
bank_creditsStatement rows: credit_id, date, amount, narration.
open_invoicesinvoice_no, customer, date, gross, taxable_value, optional items: [{sku, qty, rate, gst_rate}].
rate_contractsAgreed rates: customer, sku, rate, valid_from, valid_to.
evidenceDocuments as text: doc_id, kind (pod, grn, scheme, agreement, email, other), customer, optional invoice_no, text.
credit_notesCredit notes already booked: credit_note_no, customer, invoice_no, ref, amount.
tds_creditsRows from Form 168 (formerly 26AS), or GST TDS credit: customer, amount, kind (income_tax or gst). Leave it out and tax credits are reported as not yet verified.
customer_aliasesNames that differ across documents, e.g. {"Orbit Retail Pvt Ltd": ["ORBIT RETAIL PRIVATE LIMITED"]}.
companyYour company name, used in the email drafts.
optionsamount_tolerance (₹, default 1), date_window_days (10), tds_rates (fractions, default [0.001, 0.01, 0.02, 0.1]), max_llm_calls (12, at most 30), max_subset_candidates (16), lookback_days (180).

Files (PDFs, scans, photos, CSV). Attach them in the Playground (Attach files) or upload them with POST /api/v1/files. Then refer to each by its id in one of three ways:

  • "advices": [{"advice_id": "...", "file_id": "<id>"}]
  • "evidence": [{"doc_id": "...", "kind": "pod", "customer": "...", "invoice_no": "...", "file_id": "<id>"}]
  • loose, in "files": ["<id>", ...]

Loose files are sorted automatically. A remittance or payment advice becomes an advice. Anything else becomes evidence, with its kind, customer and invoice numbers guessed from the file name and text.

PDF text is read directly. Images and scanned PDFs are read by the vision model, using at most half of max_llm_calls (up to 6 calls), and those calls count against the budget.

Amounts accept Indian formatting ("₹1,18,000.50"). Dates accept YYYY-MM-DD or day-first (24/06/2026, 24-Jun-2026).

A minimal run that needs one LLM call:

{
  "company": "Your Company Pvt Ltd",
  "open_invoices": [{"invoice_no": "T-501", "customer": "Tapti Retail", "taxable_value": 10000, "gross": 10500}],
  "advices": [{"advice_id": "TR-9", "customer": "Tapti Retail", "date": "2026-08-20", "lines": [
    {"invoice_no": "T-501", "gross": 10500, "net": 9440,
     "deductions": [{"label": "TDS", "amount": 10}, {"label": "Shortage 4 units", "amount": 1050}]}]}],
  "evidence": [{"doc_id": "POD-T501", "kind": "pod", "customer": "Tapti Retail", "invoice_no": "T-501",
                "text": "Delivered 40 units. Received in full, no damage or shortage."}]
}

What you get

The text answer says how much came in short, how it splits, and which items are the largest disputes. The structured output, shown in the run viewer, holds:

  • totals and customers: short-received, disputable, supported, needs review, no evidence, tax credit and tax credit missing.
  • findings: one per deduction, with its category, verdict, disputable amount, the reason, and the quoted document text it rests on.
  • drafts: a dispute email per customer (with the documents to attach), payment-advice requests for credits that couldn't be allocated, and TDS follow-ups. Nothing is sent.
  • credits, advices, warnings: how each bank credit was allocated, notes per advice, and anything that didn't add up.

Verdicts are Disputable, Partly disputable, Supported (accept and book it), Needs review, No evidence (nothing on file to contest it with), Tax credit (claim it in your returns) and Credit missing (deducted, but not in Form 168 or on the GST portal).

How it works

  1. Read the advices. Structured lines are used as given. Raw text goes to the LLM, which returns the advice as JSON. Every line must satisfy gross minus deductions equals net, and the lines must add up to the total. If they don't, the LLM gets one retry with the exact figures that failed; anything still off is flagged.
  2. Match. Advice lines to open invoices by normalised number (INV/26-27/0102 is the same as INV-102), then by running number plus amount. Bank credits to advices by amount, UTR, the customer's name in the narration (truncated names included) and date. A credit with no advice goes through a subset-sum search: which of that customer's open invoices, net of TDS at a few candidate rates, add up to it? One answer is reported as inferred, to confirm with the customer; several as ambiguous; none as unexplained.
  3. Classify. Keyword rules sort deduction labels into categories. Labels they don't recognise go to the LLM in one batched call.
  4. Statutory deductions. TDS, GST TDS and GST TCS are checked against the expected rates on the taxable or gross value, then reconciled against tds_credits per customer.
  5. Commercial deductions. A rule playbook per category. Duplicates (the same debit note or claim twice), returns against booked credit notes and rate differences against the rate contract are settled without the LLM. Shortage, damage, scheme, fee, penalty and cash-discount claims need a document: with none on file the verdict is No evidence. Otherwise the LLM answers one narrow question and quotes the document; a quote that isn't actually in the document makes the answer untrusted. A rule then turns the answer into the verdict, for example a discount taken on day 38 against a 15-day window is disputable.
  6. Draft. Emails are built from templates, so they are deterministic and cost nothing.

The LLM never decides a verdict on its own and never writes accounting entries. Calls run one at a time and stop at max_llm_calls; anything skipped is marked Needs review and listed in the warnings.

Keys

None of its own: it uses the platform's LLM access (aicredits, gpt-4o-mini). Without a working LLM, the rules-only checks (matching, duplicates, rate differences, returns, TDS) still complete, document checks become Needs review, and a run whose only input is a raw advice fails with the LLM error.

Limits

  • Indian rules are simplified. TDS rates are hypotheses you can change in options.tds_rates; GST TDS is checked at 2% (CGST Act s.51) and GST TCS at 0.5% or 1% (s.52). Tax credits are matched per customer, not per quarter.
  • No live connections. Data arrives with the run; there is no Tally, bank or mailbox integration, and nothing is sent or posted.
  • One run is one audit. Disputed claims are not tracked across runs yet.
  • Documents must be sent as text, so scanned PODs need OCR first.
  • How to book accepted deductions (a financial credit note or a GST credit note) is your accountant's call; the agent doesn't advise on it.
  • The demo month is fictional. No external data sources are used, so there are no licensing constraints.

Evaluation

evaluation/golden.json holds six hand-labelled cases. Three are settled by rules alone and should always score 1.0: a rate difference plus a claim deducted twice, bank credits without advices, and TDS missing from Form 168. Three exercise the LLM: a proof of delivery against a shortage claim, reading a pasted advice, and the full demo month. Metrics, each from 0 to 1: run_completed, verdict_accuracy, disputable_total, statutory_at_risk and credit_allocation. The offline tests also run every golden case (the LLM ones against a faithful fake), so the dataset can't drift from the code.

Use from a workflow

ShortfallAgent().audit(data, budget=..., gateway=...) audits exactly the data you pass, as a dict in the Extra inputs shape or as RunInputs. It never falls back to the demo month and doesn't parse a prompt. It raises AgentError for invalid inputs or nothing readable, and LLMError the same way a standalone run does.

Pass your own gateway (agent.gateway(budget)) to read its call count even if you cancel the audit on a timeout. The package's __init__ exports the pieces a workflow may reuse:

  • AuditReport and RunInputs;
  • LLMGateway with Answer;
  • grounded_doc (quote check);
  • the money and date parsers;
  • norm_invoice and CustomerBook.

workflows/bakaya_v1 uses it to find which deductions stay owed before it works out MSMED Act interest.

Not built yet

These need a platform design or owner-approved tables, so they are listed rather than built:

  • Tally connector: read open bills and post approved receipts and debit notes through Tally's XML interface, via a small service on the client's machine that only connects outbound.
  • Scheduled ingestion of the receivables mailbox and bank statements.
  • Dispute follow-up: track each disputed claim from sent to recovered or written off, with reminders. Proposed tables for review: shortfall_claims (one row per disputed deduction: customer, invoice, amount, status, amount recovered) and shortfall_claim_events (status changes and email activity).