All posts

GST invoice extraction with AI: how to turn Indian invoices into data your books can trust

Extracting fields from GST invoices is easy to demo and hard to trust: GSTIN checksums, e-invoice QR codes, tax-split logic and arithmetic checks are what separate a pipeline you can post to Tally or an ERP from one that fails an audit.

CodeKrypt 5 min read

If you run accounts payable for an Indian business, you already know the shape of the problem: invoices arrive as PDFs, phone photos and scans from hundreds of vendors, no two laid out alike, and someone retypes them into Tally or an ERP. GST invoice extraction with AI is the obvious fix, and a demo is easy: upload an invoice, get JSON back. The part that decides whether finance will trust it is the validation you build around the model.

This post covers what is specific to Indian GST invoices and how to use that structure to make extraction checkable. For the general failure modes of document AI, see Document intelligence is not OCR.

Why are GST invoices different from generic invoice extraction?

Generic invoice tools model a supplier, a date, line items and a total. A GST invoice adds fields that carry legal and tax meaning:

Each of those is both a field to extract and a way to check the extraction. That redundancy is the opportunity: a generic model can only report its own confidence, while a GST pipeline can test its output against rules the document must obey.

How do you validate an extracted GSTIN?

A GSTIN is 15 characters. Per the structure described by Razorpay and encoded in the open-source python-stdnum validator: characters 1-2 are the state code, 3-12 are the holder's PAN, character 13 counts registrations for that PAN in the state, 14 is a fixed Z, and 15 is a check character computed with Luhn mod 36.

That gives you three free tests, none needing a network call:

  1. Shape: length 15 and the right letter/digit pattern for the PAN part.
  2. State code: must be a valid state or union territory code.
  3. Check character: recompute it; a mismatch means a character was misread.

OCR confusions such as O/0, I/1 and S/5 are exactly what the checksum catches. A useful trick: when the checksum fails, try the common confusable substitutions and accept a candidate only if it passes. Never "fix" silently without logging it.

A valid checksum proves the string is well-formed, not that the registration is active. Checking that a supplier is currently registered is a separate lookup, and it belongs in the vendor-onboarding flow rather than per invoice.

Use arithmetic as your cheapest accuracy test

Invoices must add up. Before anything is posted:

CheckRuleWhat a failure usually means
Line mathquantity x rate - discount = line taxable valueMisread quantity or rate
Tax splitSame-state supply: CGST and SGST equal; interstate: IGST onlyWrong place of supply or a misread tax column
Tax rateTax = taxable value x rate, within roundingMisread rate or amount
TotalsSum of lines + tax (+ round-off) = invoice totalMissing line, merged table row, bad total
GSTIN state vs tax typeSupplier state code vs place of supply decides CGST/SGST vs IGSTWrong GSTIN or wrong tax type

These tests need no model at all, and they target the failure that hurts most: a confident number that is wrong. They are also what makes a table-heavy invoice safe to automate, since table extraction is where models degrade quietly.

What should you do with e-invoice QR codes and IRNs?

Under the CBIC notification 10/2023-Central Tax, e-invoicing applies to B2B supplies from businesses above INR 5 crore aggregate turnover, effective 1 August 2023 (turnover is counted across GSTINs under the same PAN). So a growing share of the B2B invoices you receive carry an IRN and a signed QR code, as explained in Tally's e-invoicing guide.

Treat those as a second source of truth:

Check the current threshold yourself before relying on it: it has been revised more than once, and some vendor pages still quote the older figure.

Where does the model fit?

Use the model for what rules cannot do: finding fields across inconsistent layouts, reading handwritten amendments, and mapping vendor descriptions to your item or ledger master. Ask for structured output against a fixed schema (see LLM structured output in production), and keep the deterministic checks outside the model so they are testable.

A pipeline that holds up looks like this: layout-aware extraction, schema- constrained LLM pass, deterministic validators (GSTIN, arithmetic, tax split, QR cross-check), then a confidence-based routing step into a review queue. Posting to Tally or an ERP happens only from the cleared side.

What does it cost, and what about data protection?

Per-invoice cost is dominated by page count and whether you need a vision model or can use text extracted from the PDF. Digital PDFs are far cheaper than scans, so first test whether your volume is mostly digital. We have not published a price here because it depends on your volume mix; measure it on a sample of your own invoices.

Invoices contain personal and commercial data, so decide early what leaves your environment. The DPDP Act post and PII redaction before LLM calls cover the controls.

What to do next

  1. Pull 100-200 real invoices from your messiest vendors, not your best ones.
  2. Run extraction and count how many pass GSTIN, arithmetic and tax-split checks on the first try. That pass rate is your honest automation rate.
  3. Inspect the failures by category: OCR slips, table errors, new layouts.
  4. Decide your review-queue threshold from that data, not from a vendor benchmark.

If you want help designing this pipeline, see our document intelligence service, or talk to the team in Pune or Mumbai.

CodeKrypt avatar

CodeKrypt

Drafted by CodeKrypt's AI writing pipeline, built and maintained by our engineers, under fixed rules on sources and claims. How we write

Frequently asked questions

Can an LLM extract data from GST invoices reliably?
It can read them well, but reliability comes from what you wrap around it. GST invoices carry built-in redundancy: a GSTIN with a checksum, tax amounts that must add up to the taxable value, and on e-invoices a QR code. Using those as automatic checks catches most extraction errors before they reach your books.
How do I validate a GSTIN after extracting it?
Check the 15-character structure (two-digit state code, the PAN in characters 3 to 12, an entity number, a fixed Z, and a check character), then verify the check character with the Luhn mod 36 algorithm. This catches OCR slips such as O for 0 without any network call. A structurally valid GSTIN can still be cancelled, so a registry lookup is a separate, second check.
Should I read the e-invoice QR code instead of OCR?
Where a QR code is present and decodes cleanly, treat it as a strong cross-check on the printed values rather than the only source, since not every invoice you receive is an e-invoice and QR codes on scanned or photographed pages often fail to decode.
Can the extracted data post straight into Tally or an ERP?
Only after validation and a review step for low-confidence invoices. Posting a wrong ledger entry is more expensive than a short review queue, so route anything that fails an arithmetic or GSTIN check to a person first.

Related reading

Chat on WhatsApp