CORAA
Blog/AI in Audit

Choosing an AI Model to Write Audit Analytics Code: Excel, SQL and Python

How to test an AI model that writes Excel formulas, SQL and Python for audit tests, and the checks that catch wrong code before it reaches a working paper.

CCORAA Team12 October 20265 min read

Code written by an AI model can run without error and still answer the wrong question. For audit tests, choose the model and workflow that make the logic easy to read and easy to check, not the one that produces the longest script. An unchecked formula that quietly drops 400 rows is worse than no test.

Last reviewed: 17 October 2026. Facts checked. No model comparison or benchmark is claimed, and none was looked up. The checks below are general analytics practice, tested against nothing outside the examples described in the text.

What auditors ask these models to do

  • Duplicate invoice and payment checks across vendors and dates.
  • Gaps and duplicates in a sequence of voucher or invoice numbers.
  • Ageing of receivables and payables from a ledger extract.
  • Joining a payroll file to an HR master to find leavers still paid.
  • Journal entry filters: weekends, round amounts, late postings. For the audit reasoning, see journal entry testing.

If you are starting out on the tooling itself, audit data analytics: where to start covers the basics.

How AI-written audit code goes wrong

  1. Silent row loss. An inner join drops unmatched records, which are often the exceptions you want.
  2. Wrong matching rule. "Duplicate" may be treated as same invoice number only, missing same amount with a different number.
  3. Date handling. Day-month swaps and text dates that sort as text.
  4. Blank and zero handling. Empty cells treated as zero, or excluded.
  5. Rounding and tolerance. A match that ignores paise differences, or one that demands exactness when it should not.
  6. Invented columns. A formula that refers to a field the file does not have, or to a function that does not exist in your Excel version.
  7. Unexplained logic. Long code that nobody on the team can read.

A test set for code

You can test a model's code without any benchmark, using a small file where you know the answer.

1. Build a seeded file of about 200 rows. Plant known exceptions: three exact duplicates, two near-duplicates (same amount and vendor, different invoice number), one gap in the voucher sequence, two weekend postings, one blank amount and one negative amount. Write down the exception list before any model sees the file.

2. Give each model the same plain-language request. Describe the columns and the test. Ask it to explain the logic in steps before giving the code.

3. Run the code and compare. Count planted exceptions found, extra rows flagged, and rows lost between input and output. Check that input rows equal output rows plus excluded rows, and that excluded rows are listed.

4. Change the data and rerun. Add a few rows with edge cases, such as dates in another format. Code that only works on the sample file is not reusable.

5. Ask for a second opinion on the code. Paste the code into a different model or a fresh session, and ask what could go wrong. Treat that as extra input, not as proof.

6. Compare readability. Score each: could a colleague understand it in ten minutes? Comments, clear names and short steps count.

Excel, SQL or Python

Tool Where AI help is strongest Watch for
Excel Formulas such as lookups and conditional counts Functions that depend on the Excel version; formulas that are hard to audit once nested
SQL Joins, grouping and filters on a ledger extract Join type and null handling
Python Larger files and repeated tests Library versions, and code only one person understands

Use the simplest tool that the reviewer can follow. A clear spreadsheet formula beats a clever script that nobody reviews.

Controls for any generated code

  • Keep the exact prompt, the code and the output together in the working paper.
  • Run a completeness check: rows in equals rows tested plus rows excluded.
  • Tie totals to the source report, such as the trial balance.
  • Re-perform the key test by a second method on a small sample.
  • Do not paste client data into a tool you have not cleared. Mask names, PAN and GSTIN, and use a tiny sample while you build the logic. DPDP-safe prompt templates show masking patterns.
  • Record the model name and date; see model versioning and change control.

Judgement on choosing

Pick the model whose code finds the planted exceptions, loses no rows without saying so, and explains itself plainly. Repeat the seeded-file test every few months, because models are updated and results shift.

Frequently Asked Questions

Can I trust AI-generated formulas for audit tests?

Only after testing on data where you know the answer, plus a completeness check on row counts.

Do I need to know Python to use AI for audit analytics?

No, but you or a reviewer must understand what the code does. If nobody can, use a simpler tool.

Should the prompt and code be kept in the file?

Yes. Together with the output, they let a reviewer re-perform the test.

Topics
ai audit analytics codechatgpt excel formulas for auditorsai sql for auditpython for audit aiai generated code audit testingllm data analytics internal audit
Share

Statutory facts on this page are checked against their sources, and the page says where it relied on secondary reporting. How we verify · Report an error

← Back to all articles
Part of a topic hub
AI in audit and assurance: tools, models, risks and controls →
Every guide, template and free tool on this topic in one place, with FAQs.
Keep reading

More in ai in audit.

Built for India · DPDPA compliant

Ready to automate your audit work.

See how Coraa reduces audit engagement time by 60%, from ledger scrutiny to working papers, all from one Tally import.

Run one complete audit free