Introduction

An AI agent becomes useful in finance and accounting when it can work with the data and business tools that employees already use. These tools may include spreadsheets, accounting systems, databases, document repositories, market data services, and internal approval platforms. The agent does not become reliable simply because it can call a tool. Reliability depends on selecting the correct source, validating the returned data, preserving traceability, and respecting the user’s access rights.

A practical design treats every external system as a controlled tool with a clear contract. The contract should state what the tool does, which inputs it accepts, what output it returns, whether the operation only reads data or changes data, and which roles may use it. For example, a spreadsheet reader may return invoice rows, while an accounting-system tool may retrieve posted journal entries. A write operation such as posting an adjustment should require stronger controls than a read operation such as checking an account balance.

This lesson focuses on the connection layer between the agent and business data. It covers structured tool calls, validation, reconciliation, audit records, and access control. It does not cover training a language model, designing a complete enterprise identity platform, or replacing an organization’s accounting policy with autonomous decisions.

Architecture diagram showing an AI agent connected to a spreadsheet reader, accounting system, database, and external data source, with a validation layer, permission checks, and an audit log between the agent and each tool

Tool Contracts and Data Boundaries

A tool contract gives the agent a narrow and predictable interface. Consider a spreadsheet-reading tool that receives a workbook identifier, a worksheet name, and a range. Its result should identify the source, return the requested rows in a structured format, and report errors separately from business data. The agent should not be allowed to infer that a missing value means zero, or that a worksheet with a similar name is automatically the correct source.

The following example shows a local, runnable tool simulation. It uses in-memory data to demonstrate the control pattern without pretending to connect to a particular vendor API. The input is a request containing a permitted workbook, worksheet, and range. The output is either validated rows or a clear error object.

python
from typing import Any
SPREADSHEETS = {
"close-pack-2025-03": {
"Invoices": [
{"invoice_id": "INV-1001", "vendor_id": "V-10", "amount": 1250.00, "currency": "USD"},
{"invoice_id": "INV-1002", "vendor_id": "V-11", "amount": 900.00, "currency": "USD"},
]
}
}
def read_spreadsheet(workbook_id: str, worksheet: str, start_row: int, end_row: int) -> dict[str, Any]:
if workbook_id not in SPREADSHEETS:
return {"ok": False, "error": "WORKBOOK_NOT_FOUND"}
if worksheet not in SPREADSHEETS[workbook_id]:
return {"ok": False, "error": "WORKSHEET_NOT_FOUND"}
if start_row < 0 or end_row < start_row:
return {"ok": False, "error": "INVALID_RANGE"}
rows = SPREADSHEETS[workbook_id][worksheet]
selected = rows[start_row:end_row]
return {
"ok": True,
"source": f"spreadsheet:{workbook_id}/{worksheet}",
"rows": selected,
}
result = read_spreadsheet("close-pack-2025-03", "Invoices", 0, 2)
print(result)

For this example, a successful result contains the source identifier and two invoice records. Invalid workbook names, worksheet names, or ranges return explicit errors. In a production integration, the same contract would also need authentication, request timeouts, rate-limit handling, schema versioning, and protection against retrieving more data than the user needs. The agent should receive only the fields required for the task, especially when spreadsheet files contain payroll, bank, or personally identifiable information.

Validation and Reconciliation

Tool output is not automatically trustworthy just because it came from an internal system. A spreadsheet may contain duplicated invoice identifiers, text where a number is expected, a missing currency, or an amount with an unexpected sign. A database may contain a valid record from the wrong accounting period. Validation should occur before the agent summarizes data or recommends an action.

A useful validation process checks structure first and business meaning second. Structural checks confirm that required fields exist and have acceptable types. Business checks confirm rules such as a positive invoice amount, an approved currency, a matching entity, or an accounting date inside the requested period. The agent should report exceptions explicitly instead of silently correcting them.

python
from decimal import Decimal, InvalidOperation
def validate_invoice_rows(rows: list[dict[str, object]]) -> list[dict[str, object]]:
errors = []
seen_ids = set()
allowed_currencies = {"USD", "EUR", "GBP"}
for index, row in enumerate(rows):
invoice_id = row.get("invoice_id")
amount = row.get("amount")
currency = row.get("currency")
if not invoice_id:
errors.append({"row": index, "field": "invoice_id", "error": "REQUIRED"})
elif invoice_id in seen_ids:
errors.append({"row": index, "field": "invoice_id", "error": "DUPLICATE"})
else:
seen_ids.add(invoice_id)
try:
if Decimal(str(amount)) <= 0:
errors.append({"row": index, "field": "amount", "error": "MUST_BE_POSITIVE"})
except (InvalidOperation, TypeError):
errors.append({"row": index, "field": "amount", "error": "NOT_NUMERIC"})
if currency not in allowed_currencies:
errors.append({"row": index, "field": "currency", "error": "UNSUPPORTED"})
return errors
validation_errors = validate_invoice_rows(result["rows"] if result["ok"] else [])
print({"valid": not validation_errors, "errors": validation_errors})

The input is a list of invoice dictionaries, and the output contains a Boolean validity result and any detected errors. Notice that the function does not decide what to do with an invalid invoice. It reports the issue so that a policy-aware workflow can route it to an accountant, request clarification, or stop before posting. This separation keeps validation rules testable and prevents a language model from inventing a correction.

Reconciliation adds a second source. For example, the agent may compare spreadsheet invoices with approved accounts-payable records. It should match on stable identifiers where possible, compare amounts using decimal arithmetic, and make currency and period explicit. A result should distinguish matched records, amount mismatches, records missing from one source, and records that could not be matched confidently.

Reconciliation table with spreadsheet invoice IDs on one side, accounting-system IDs on the other, matched rows in green, amount mismatches in amber, and unmatched records in red

Access Control and Traceability

Access control must be enforced by the tool layer and the connected systems, not only by instructions in the agent’s prompt. The tool should receive the user identity, role, tenant or legal entity, and requested operation. It should verify whether that identity may read the selected data or perform the requested write. A user who can ask for a report is not automatically authorized to approve a journal entry.

Separate read, prepare, and commit stages make financial workflows easier to control. The agent can read records and prepare a proposed reconciliation. A human or a dedicated approval service can review the proposal. Only an authorized commit operation should create a posting, update a vendor record, or change a payment status. For high-risk actions, use dual approval, transaction limits, and a clear confirmation that includes the exact target, amount, currency, and accounting period.

Traceability means that another reviewer can reconstruct what happened. An audit event should record the requesting identity, time, tool name, operation, input reference, result status, validation findings, and correlation identifier. Do not place full confidential rows into logs when a source reference, hash, or redacted summary is sufficient. Logs must also be protected against unauthorized modification and retained according to the organization’s policy.

The agent’s natural-language explanation should point back to evidence. Instead of saying that an invoice appears correct, it should state which source records were compared, which fields matched, and whether any exceptions remain. A citation to a workbook range, database query result identifier, or accounting document number makes the conclusion reviewable without exposing more data than necessary.

Common Failure Modes

One common failure is connecting the agent directly to a broad database and allowing it to generate unrestricted queries. This creates excessive data exposure and makes it difficult to prove why a result was produced. Use predefined operations or narrowly scoped query tools, parameter validation, row limits, and entity-level filters. Reject requests that attempt to bypass those boundaries.

Another failure is treating a spreadsheet as an authoritative accounting record in every situation. Spreadsheets are often useful working documents, but they may be stale, manually edited, or disconnected from posting status. The workflow should label each source by its authority and timestamp. When sources disagree, the agent should surface the conflict and identify the next review step rather than choosing silently.

A third failure is allowing a successful tool call to imply a successful business outcome. A system may return a technically valid response while the record is outside the reporting period, already posted, or subject to a segregation-of-duties restriction. Business validation and authorization must therefore happen after data retrieval and before any write operation.

Errors also need consistent handling. Authentication failures should stop the workflow and request reauthorization. Missing records should be reported as missing, not converted into zero values. Timeouts and rate limits may be retried under controlled rules, but a repeated failure should produce an incomplete result with a visible status. Ambiguous matches should be escalated, especially when they could affect financial statements or payments.

Practical Workflow and Summary

A dependable agent workflow begins by clarifying the user’s goal, legal entity, period, and requested operation. It then checks the user’s permissions, selects the smallest set of approved tools, retrieves data with source references, validates the schema and business rules, and compares sources when reconciliation is required. The agent produces a result with exceptions and evidence, then pauses before any controlled write or approval step.

For practice, imagine a user asking the agent to reconcile March invoices. The agent should identify the approved spreadsheet and accounting source, verify that the user may access both, retrieve only March records, validate identifiers, amounts, currencies, and status, and classify each result. It may prepare a reconciliation report, but it should not post adjustments merely because a mismatch exists. A human reviewer or approved workflow must decide how the mismatch is resolved.

The central principle is that tool access expands an agent’s capability and also expands its risk. Structured contracts, minimal permissions, explicit validation, source references, and audit events keep that capability bounded. When an agent cannot verify the source, permission, or business rule, the correct behavior is to stop, explain the uncertainty, and request an appropriate review rather than fabricate confidence.

Lesson practice

Lesson Checkpoint

Review what you learned and get feedback on your work.

0/1
Answered · 0/1