How to Use AI to Categorize and Code Expenses Automatically
Let AI analyze expense descriptions and assign GL codes and categories.
What This Integration Does
Manual expense coding is one of the slowest parts of a finance team's week. Bookkeepers stare at a list of card transactions, look up vendor names, and pick the right GL code and department for each line. This workflow does that work in seconds by handing the description, vendor, and amount to an AI agent that already knows your chart of accounts.
The workflow runs either on demand from a webhook (every time a new card transaction hits your accounting system) or as a nightly batch over yesterday's unsorted transactions. Each run reads transactions, asks the AI to suggest a GL code, category, department, and confidence score, then either auto-applies the coding or routes it to a human for review based on the score.
Prerequisites
- A NetSuite connection (or other accounting system) with read access to expense transactions and write access to update them.
- A Knowledge collection seeded with your chart of accounts, department list, and any internal coding rules ("anything from AWS goes to
6230 - Cloud Infrastructure", etc.). - A Slack connection for routing low-confidence items to a review channel.
Step 1: Trigger
Add a Trigger node. Use Schedule for nightly batch coding (e.g., 02:00 daily), or Webhook if your accounting system can fire on new uncoded transactions. Batch mode is friendlier on token cost because you can group similar transactions in one prompt.
Step 2: Fetch Uncoded Transactions
Add a Connector node pointing at netsuite and pick the run-suiteql tool. Pull rows where the GL code is empty or flagged for review:
SELECT id, trandate, memo, amount, entity
FROM transaction
WHERE account IS NULL
AND trandate >= TO_DATE('{{ syncStart }}', 'YYYY-MM-DD')
Step 3: Knowledge Lookup for Coding Rules
Add a Knowledge node and query your chart-of-accounts collection with the transaction memo and vendor as the search text. The top few matches act as in-context examples for the AI in the next step and dramatically improve accuracy over a zero-shot prompt.
Step 4: AI Categorization with Structured Output
Add an Agent step that takes the transaction plus the Knowledge results as input. Configure structured output so the response always matches this shape:
{
"glCode": "string",
"category": "string",
"department": "string",
"confidence": "number"
}
Wrap this in a Loop so each transaction gets its own agent call, or batch 20 at a time for efficiency.
Step 5: Route by Confidence
Add a Condition node on {{ result.confidence }}. If confidence is at or above 0.85, route to the auto-apply branch. Otherwise, route to a slack send-message call into a #expense-review channel with the suggested coding and a link to the source transaction.
Step 6: Apply the Coding
On the auto-apply branch, add a Connector node pointing at netsuite using update-record. Set the account, department, and class fields on the transaction. Stamp a custom field like codingSource = "ai" so finance can audit what was machine coded versus human coded.
Tips
- Keep the confidence threshold conservative for the first month. 0.9 is a safe start; relax it once you've audited the auto-applied set.
- Cache vendor-to-code mappings in your Knowledge collection. The same coffee shop will show up again next week.
- Use math
sumto track total dollars auto-coded each run; surface this in your monthly close summary.
Common Pitfalls
- Drift in the chart of accounts. When finance adds a new GL code, refresh the Knowledge collection or the AI will keep suggesting the old closest code.
- Foreign currency amounts. Make sure your prompt clarifies whether the amount is in account currency or transaction currency; otherwise the AI will sometimes treat a 1,500,000 IDR line like a 1.5M USD line.
- Reimbursable employee expenses. These often need a different category and an employee link. Filter these out into a separate branch rather than letting the generic agent handle them.
Testing
Run the workflow once manually with a SuiteQL filter limited to a single day and 20 transactions. Open the run trace, inspect each AI suggestion, and compare against what a bookkeeper would have done. Tune the prompt and the Knowledge seed data before opening the schedule up to the full backlog.