# Validated Table & Invoice Extractor for AI Agents (`geeky_goth_gamer/validated-table-invoice-extractor`) Actor

Extract typed tables and structured invoice or receipt fields from PDF, HTML, Markdown, CSV or text, then verify the arithmetic (line totals, GST, balance due, AU ABN checksum) so agents do not invent numbers. $0.005 inline or $0.01 per PDF page or URL.

- **URL**: https://apify.com/geeky_goth_gamer/validated-table-invoice-extractor.md
- **Developed by:** [Chris Day](https://apify.com/geeky_goth_gamer) (community)
- **Categories:** AI, Developer tools, Business
- **Features:** Limited permissions, Single-tenant, Server interface
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 1,000 extract inlines

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Validated Table & Invoice Extractor for AI Agents

Give this Actor a **PDF, HTML, Markdown, CSV or text** document — inline, as base64, or from a public URL — and it returns **typed tables** and, when the document looks like an invoice or receipt, **structured fields plus an automatic accounting-math check**. Line totals, GST, discounts, shipping, balance due and Australian ABN checksums are verified so a language model does not have to invent or silently accept a bad total.

It does **not** call a language model. Extraction and checks are deterministic.

### When an AI agent should use this

Use `geeky_goth_gamer/validated-table-invoice-extractor` when:

- You have a tax invoice, receipt or statement and must extract vendor, dates, line items, GST and totals with arithmetic you can trust.
- You need a typed table (currency, dates, numbers) from a PDF, HTML (`colspan`/`rowspan`), Markdown pipe table or CSV, including column sums.
- You want a clear `isValid` flag and plain-English `anomalies` when qty × unit price, the GST roll-up, or an ABN checksum is wrong.

Don't use it for:

- Handwritten scans or photos that are not already a selectable-text PDF.
- Inventing missing fields; absent values are `null` and the related check is `skipped`.
- Private, intranet or metadata URLs (they are rejected).

**Example input:**

```json
{
  "mode": "auto",
  "expectedCurrency": "AUD",
  "content": "TAX INVOICE\nHobart Office Supplies Pty Ltd\nABN: 51 824 753 556\nInvoice Number: INV-2026-1042\n...\nSubtotal: $150.00\nGST Amount: $15.00\nTotal: $165.00\n"
}
```

**Output:** One dataset item with `tables` (typed rows, `columnTypes`, sums) and, when invoice cues are present, `invoice` (vendor, tax id, dates, line items, totals) plus `validation`: `isValid`, `confidence`, per-check `status` (`pass` / `fail` / `skipped`) with `expected` / `actual` / `delta`, and `anomalies`.

**Cost:** $0.005 per inline HTML/Markdown/CSV/text extraction; $0.01 per PDF page extracted or per fetched URL. Invalid input is not billed. Apify also charges the standard $0.00005 Actor-start fee on ordinary runs.

**Call it from an agent:**

- Apify MCP server: add `https://mcp.apify.com/?tools=geeky_goth_gamer/validated-table-invoice-extractor` to your MCP client; the tool is `geeky_goth_gamer--validated-table-invoice-extractor`. Or use `call-actor` with `"actor": "geeky_goth_gamer/validated-table-invoice-extractor"`.
- Standby HTTP: `POST https://geeky-goth-gamer--validated-table-invoice-extractor.apify.actor/extract` (also `POST /extract-invoice`, `POST /extract-tables`) with `Authorization: Bearer YOUR_TOKEN` and the input JSON. `GET /health` is a liveness check.
- Python: `ApifyClient(token).actor("geeky_goth_gamer/validated-table-invoice-extractor").call(run_input=...)`, then read `client.dataset(run["defaultDatasetId"]).list_items().items`.
- HTTP run: `POST https://api.apify.com/v2/acts/geeky_goth_gamer~validated-table-invoice-extractor/run-sync-get-dataset-items?token=YOUR_TOKEN` with the input JSON as the body.

### Why this exists

Agents misread invoice columns, invent GST and miss a bad total. This Actor loads the document (SSRF-safe URL, inline text or base64, with size and PDF page caps), extracts typed tables, pulls structured invoice fields when cues exist, and runs explicit arithmetic checks including the Australian ABN weighted checksum (mod 89).

### Input

| Field | Default | Notes |
|---|---|---|
| `mode` | `auto` | `auto`, `invoice` or `tables`. Standby routes set this for you. |
| `content` | (one source) | Inline HTML, Markdown, CSV/TSV or text. |
| `sourceUrl` | (one source) | Public `http(s)` URL. |
| `fileBase64` | (one source) | Base64 PDF or text (`data:` prefix accepted). Optional `filename` / `mimeType`. |
| `expectedCurrency` | (none) | e.g. `AUD`. Used for currency consistency. |
| `mathTolerance` | `0.02` | Absolute currency tolerance (two cents). |
| `maxPages` | 25 | PDF page cap, hard maximum 50. |
| `timeoutSeconds` | 30 | Download time limit. |
| `maxFileSizeMb` | 10 | Download / decoded size cap (max 20). |

### Output

The default dataset holds one envelope (`status`, `mode`, `source`, `tables`, `invoice`, `validation`, `billed`).

Invoice `validation.checks` include `line_item_multiplication`, `line_items_sum_to_subtotal`, `subtotal_tax_discount_shipping_to_total`, `balance_due_check`, `currency_consistency` and `abn_checksum` (when an AU ABN is present). `isValid` is true only when every applicable check passes within `mathTolerance`.

### Standby / Server mode

When started through Apify's server interface (`APIFY_META_ORIGIN=STANDBY`), the Actor listens on `APIFY_CONTAINER_PORT` / `ACTOR_WEB_SERVER_PORT` (default 8080) and handles:

- `GET /health` — liveness
- `POST /extract` — auto mode
- `POST /extract-invoice` — invoice mode
- `POST /extract-tables` — tables only
- Any request carrying the `x-apify-container-server-readiness-probe` header is answered immediately with HTTP 200 and body `ok`

Standby URL: `https://geeky-goth-gamer--validated-table-invoice-extractor.apify.actor`

### Pricing

| Event | Price | When it is charged |
|---|---|---|
| `extract-inline` (primary) | **US$0.005** | One successful inline HTML, Markdown, CSV or text extraction. |
| `extract-document` | **US$0.01** | One PDF page extracted, or one fetched URL (HTML/CSV/text). A 3-page PDF charges 3. |
| `apify-actor-start` | US$0.00005 (Apify default) | Once when a standard run starts. |

Failed input and failed fetches are not billed. Your maximum cost per run is respected.

### Safety

URL fetches are SSRF-safe: only `http`/`https` on standard ports, every redirect hop is re-validated, and private, loopback, link-local, CGNAT and cloud-metadata addresses are blocked. Downloads, decoded base64 and PDF page counts are capped. Malformed PDFs return a clear error.

### Limitations

- Image-only (scanned) PDFs without a text layer will yield few or no fields.
- Ambiguous date numbers are read day-first (AU/UK).
- Complex multi-table invoices may attach line items to the first table that looks like a line-item list.
- Tax identifiers other than an 11-digit Australian ABN are captured but not checksum-validated.

# Actor input Schema

## `mode` (type: `string`):

"auto" (default) extracts typed tables and, when invoice cues exist, structured invoice fields plus math checks. "invoice" always runs invoice extraction and verification. "tables" returns typed tables only. Standby routes set this for you.

## `content` (type: `string`):

Optional. HTML, Markdown, CSV/TSV or plain text. Do not also pass sourceUrl or fileBase64. Max 1,000,000 characters.

## `sourceUrl` (type: `string`):

Optional. Public http(s) URL of a PDF, HTML, CSV/TSV, Markdown or text file. Private, loopback and metadata addresses are rejected.

## `fileBase64` (type: `string`):

Optional. Base64-encoded PDF, HTML, CSV/TSV or text (a data: URL prefix is accepted). Decoded size is capped (default 10 MB).

## `filename` (type: `string`):

Optional. Helps detect the format of fileBase64 or inline content (e.g. invoice.pdf, rates.csv).

## `mimeType` (type: `string`):

Optional. Alternative format hint, e.g. application/pdf or text/html.

## `expectedCurrency` (type: `string`):

Optional 3-letter code (AUD, USD, NZD, EUR, GBP). Used for the currency-consistency check.

## `mathTolerance` (type: `number`):

Absolute currency tolerance for arithmetic checks (default 0.02, i.e. two cents).

## `maxPages` (type: `integer`):

Only the first N pages of a PDF are read. Default 25, hard cap 50.

## `timeoutSeconds` (type: `integer`):

Download time limit when sourceUrl is set.

## `maxFileSizeMb` (type: `integer`):

Larger downloads or decoded files are rejected. Default 10 MB, maximum 20 MB.

## Actor input object example

```json
{
  "mode": "auto",
  "content": "TAX INVOICE\nHobart Office Supplies Pty Ltd\nABN: 51 824 753 556\nBill To: Acme Analytics Pty Ltd\nInvoice Number: INV-2026-1042\nIssue Date: 1 Nov 2026\nDue Date: 30 Nov 2026\nPayment Terms: Net 30\nCurrency: AUD\n\n| Description | Qty | Unit Price | Amount |\n|---|---:|---:|---:|\n| A4 copy paper (carton) | 3 | 24.50 | 73.50 |\n| Blue ink pens (box) | 5 | 8.00 | 40.00 |\n| Desk organiser | 2 | 18.25 | 36.50 |\n\nSubtotal: $150.00\nGST Amount: $15.00\nTotal: $165.00\n",
  "expectedCurrency": "AUD",
  "mathTolerance": 0.02,
  "maxPages": 25,
  "timeoutSeconds": 30,
  "maxFileSizeMb": 10
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "mode": "auto",
    "content": `TAX INVOICE
Hobart Office Supplies Pty Ltd
ABN: 51 824 753 556
Bill To: Acme Analytics Pty Ltd
Invoice Number: INV-2026-1042
Issue Date: 1 Nov 2026
Due Date: 30 Nov 2026
Payment Terms: Net 30
Currency: AUD

| Description | Qty | Unit Price | Amount |
|---|---:|---:|---:|
| A4 copy paper (carton) | 3 | 24.50 | 73.50 |
| Blue ink pens (box) | 5 | 8.00 | 40.00 |
| Desk organiser | 2 | 18.25 | 36.50 |

Subtotal: $150.00
GST Amount: $15.00
Total: $165.00`,
    "expectedCurrency": "AUD"
};

// Run the Actor and wait for it to finish
const run = await client.actor("geeky_goth_gamer/validated-table-invoice-extractor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "mode": "auto",
    "content": """TAX INVOICE
Hobart Office Supplies Pty Ltd
ABN: 51 824 753 556
Bill To: Acme Analytics Pty Ltd
Invoice Number: INV-2026-1042
Issue Date: 1 Nov 2026
Due Date: 30 Nov 2026
Payment Terms: Net 30
Currency: AUD

| Description | Qty | Unit Price | Amount |
|---|---:|---:|---:|
| A4 copy paper (carton) | 3 | 24.50 | 73.50 |
| Blue ink pens (box) | 5 | 8.00 | 40.00 |
| Desk organiser | 2 | 18.25 | 36.50 |

Subtotal: $150.00
GST Amount: $15.00
Total: $165.00
""",
    "expectedCurrency": "AUD",
}

# Run the Actor and wait for it to finish
run = client.actor("geeky_goth_gamer/validated-table-invoice-extractor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "mode": "auto",
  "content": "TAX INVOICE\\nHobart Office Supplies Pty Ltd\\nABN: 51 824 753 556\\nBill To: Acme Analytics Pty Ltd\\nInvoice Number: INV-2026-1042\\nIssue Date: 1 Nov 2026\\nDue Date: 30 Nov 2026\\nPayment Terms: Net 30\\nCurrency: AUD\\n\\n| Description | Qty | Unit Price | Amount |\\n|---|---:|---:|---:|\\n| A4 copy paper (carton) | 3 | 24.50 | 73.50 |\\n| Blue ink pens (box) | 5 | 8.00 | 40.00 |\\n| Desk organiser | 2 | 18.25 | 36.50 |\\n\\nSubtotal: $150.00\\nGST Amount: $15.00\\nTotal: $165.00\\n",
  "expectedCurrency": "AUD"
}' |
apify call geeky_goth_gamer/validated-table-invoice-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,geeky_goth_gamer/validated-table-invoice-extractor"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/Sfyh3kEJHILMCefVS/builds/DQs5dTpl1JgTQJbD7/openapi.json
