# Guide for AI agents

This page is written for the agent. It describes the workflow that gives correct results and the checks to run before telling a user that a statement was converted.

## 1. Choose the path

| Situation | Use |
| --- | --- |
| The PDF is a file on the user's machine and you can run local MCP servers | Local server, `convert_statement` with `path` |
| The PDF is at a URL you can share | Hosted server or REST API with `file_url` |
| You hold the bytes and have no URL | REST API with multipart, or `file_base64` for small files |
| The user said the file is confidential or must stay local | Local server only. Do not send it to the hosted API. |

Sending a statement to the hosted API uploads the user's financial data to Extractivio's servers. If the user has not clearly asked for the conversion, confirm before sending.

## 2. Call with the right arguments

- Pass `date_order`. Use `mdy` for statements from the United States and `dmy` for other countries. If you do not know the country, infer it from the bank name or the currency, and otherwise leave it out.
- Leave `format` as `json` unless the user asked for a specific file. JSON is the only format that includes the balance check and warnings.
- Use `store: true` only if the user wants to retrieve the result later.
- One PDF per call. For several statements, call once per file and keep the results separate.

## 3. Check the result before using it

Run these checks in order.

1. **Error?** If the call failed, read the code. `scanned_pdf`: tell the user the PDF is a scan and needs OCR, or suggest the AI extraction option in the web app. `unreadable_pdf`: ask for a version without a password. `download_failed`: the link is not publicly reachable. Do not retry the same input.
2. **Empty?** If `transactions` is empty, the layout was not understood. Say so. Do not invent rows from your own reading of the PDF and present them as the tool's output.
3. **Balance check.** Compare `balance_check.reconciled` with `balance_check.checkable`.
   - Equal and greater than zero: amounts and signs are consistent with the statement.
   - Lower: some rows are wrong. Report how many. One failure in a statement with several accounts is expected at the account boundary.
   - `checkable` is zero: nothing could be verified. Say that the result is unverified.
4. **Warnings.**
   - `year-inferred`: check that the year fits the statement period. For a statement covering December and January, fix the year on one side yourself and tell the user.
   - `unsigned-amounts`: the signs are not reliable. All amounts are negative. Either ask the user which rows are income, or classify them from the descriptions and state clearly that you did.
   - `card-convention`: purchases are negative and payments positive. Mention it.
5. **Sanity.** Dates should fall in one statement period. If months look swapped (for example everything is on the 1st to the 12th of different months), call again with the other `date_order`.

## 4. Report to the user

Always include, in plain words:

- How many transactions were extracted and the date range.
- The balance check result, for example "all 41 balances reconcile" or "no running balance on this statement, so the amounts could not be verified".
- Any warning and what you did about it.
- A reminder to review the data before using it for accounting or tax.

Example:

> I extracted 42 transactions from 1 to 31 March 2026 (USD). All 42 running balances reconcile, so the amounts and signs match the statement. The statement prints dates without a year; I used 2026, which matches the statement period. Please review before importing.

## 5. Working with the data

- Amounts are already signed. Sum them directly: the total is the net change of the account. Do not flip signs for credit card statements.
- The opening balance is the first row's `balance` minus its `amount`. The closing balance is the last row's `balance`.
- `currency` can be `null`. Do not assume USD; ask or infer from the bank.
- Descriptions are raw statement text. If you categorise or clean them, keep the original available.
- The result has no account number, holder name or statement period. If you need them, read them from the PDF yourself and label them as your own reading.

## 6. Producing files for accounting software

- QuickBooks: `format: "qbo"`. Xero: `format: "xero"`. Quicken: `format: "qfx"`. Anything else: `csv`.
- Before giving a `.qbo`, `.qfx` or `.ofx` file to a user, run `validate_ofx` on it, and on any such file the user says will not import.
- QBO and QFX files use placeholder account details and a generic bank id. Tell the user they may be asked to choose the bank and account during import.

## 7. Quota and pacing

- Each page costs one unit of the monthly quota. Call `get_usage` before converting a large batch, and tell the user if the batch will not fit.
- Stay under 60 calls a minute. On `rate_limited`, wait 60 seconds.
- On `quota_exceeded`, stop. Do not loop.

## Do not

- Do not present a result with a failed or absent balance check as verified.
- Do not fill gaps with guessed transactions.
- Do not send statements the user did not ask you to process, and do not send them to the hosted API when they asked for local processing.
- Do not put the API key in code you show the user, in files you commit or in messages.
- Do not give tax or accounting advice on the basis of an unreviewed extraction.

## System prompt snippet

Paste this into an agent's instructions when it has the Extractivio tools:

```
You can convert PDF bank and credit card statements with the Extractivio tools.
- Prefer the local tool (path) for files on disk; use the hosted tool (file_url) for files online.
- Pass date_order="mdy" for US statements and "dmy" otherwise when you know the country.
- Amounts are negative for money out and positive for money in, including on credit cards.
- After every conversion, compare balance_check.reconciled to balance_check.checkable and
  read warnings. Tell the user the transaction count, date range, balance check result and
  any warning. If the balance check fails or is absent, say the result is not verified.
- Never invent transactions. If nothing is extracted or the PDF is a scan, say so.
- Remind the user to review the data before using it for accounting or tax.
```
