worker.md SPEC
Menu

Receipt & Tax Extractor

Receipt & Tax Extractor is a reference AI Worker specification designed for reliable, bounded task execution.

Reference worker specification for parsing receipt text, calculating subtotal arithmetic, and validating tax reconciliation.

Pricing & Service Level Agreement (SLA)#

Specification Value Target Policy
Invocation Price $0.03 / run (Proposed) Billed per successful schema-validated output.
Payment Methods Stripe Metered • USDC (Base L2) Dual-rail support for teams and autonomous AI agents.
Execution Latency SLA < 15s (Target) Target deadline enforced by runtime deadline timer.
Max Token Budget $0.04 (Ceiling) Hardware token ceiling prevents runaway billing loops.
Benchmark Pass Rate Target: > 95% Reconciliation Target evaluation benchmark pass rate on test fixtures.
Web3 Wallet Address 0x89D24A6b4CcB1B6fAA2625fE562bDD9a23260359 Direct on-chain recipient for autonomous HTTP 402 micro-txs.

worker.md Contract#

The formal execution contract defining inputs, outputs, limits, and runtime instructions:

---
name: receipt-tax-extractor
version: 1.0.0
description: Ingests unstructured receipt and invoice OCR text, extracts line items, validates tax calculations per jurisdiction (VAT/Sales Tax), and flags math discrepancies.
category: fintech
author: worker.md community
license: MIT
pricing:
  model: per-invocation
  rate_usd: 0.03
  payment_methods:
    - type: stripe_metered
      plan_id: "price_tax_metered_003"
    - type: crypto_micropayment
      network: base
      token: USDC
      wallet: "0x89D24A6b4CcB1B6fAA2625fE562bDD9a23260359"
      http_status_protocol: 402
sla:
  timeout_seconds: 15
  max_cost_usd: 0.04
  concurrency: 50
  eval_accuracy: 99.1%
inputs:
  receipt_text:
    type: string
    required: true
    description: Raw OCR text or markdown representation of a receipt/invoice.
  expected_currency:
    type: string
    required: false
    default: USD
    description: Expected 3-letter ISO currency code (USD, EUR, GBP, JPY).
  tax_jurisdiction:
    type: string
    required: false
    description: Geographic jurisdiction code (e.g., US-CA, UK, DE) to verify expected tax rates.
outputs:
  vendor:
    type: object
    description: Merchant name, address, and VAT/tax registration ID if detected.
  invoice_date:
    type: string
    description: ISO 8601 date (YYYY-MM-DD).
  subtotal:
    type: number
    description: Pre-tax item total.
  tax_amount:
    type: number
    description: Total tax extracted.
  total:
    type: number
    description: Final invoice total.
  reconciliation_status:
    type: string
    enum: [matched, math_discrepancy, missing_line_items]
    description: Verification status checking subtotal + tax == total within 0.02 tolerance.
  line_items:
    type: array
    description: Extracted itemized charges (description, quantity, unit_price, line_total).
constraints:
  timeout_ms: 15000
  max_cost_usd: 0.04
  allowed_tools: [tax-calculator]
  temperature: 0.0
---

# Receipt Tax Extractor Worker

You are an accounting automation worker. Your responsibility is to extract, validate, and mathematically reconcile commercial receipts and invoices.

## Extraction Protocol
1. Extract the merchant name, date, invoice number, and currency.
2. Itemize all purchased lines with quantity and price.
3. Compute expected line item sum and check against printed subtotal.
4. Calculate tax rate percentage: `(tax_amount / subtotal) * 100`.
5. If `abs((subtotal + tax_amount) - total) > 0.02`, flag `reconciliation_status: "math_discrepancy"`. Otherwise flag `"matched"`.

Integration Code Examples#

Test and run this worker with schema-compliant payloads:

1. CLI Runner (Local Execution)

npx worker-md run workers/receipt-tax-extractor/WORKER.md \
  --input '{"receipt_text":"ACME CAFE\\nDate: 2026-10-14\\n1x Espresso $4.50\\n1x Croissant $5.50\\nSubtotal: $10.00\\nTax: $0.95\\nTotal: $10.95","expected_currency":"USD"}'

2. HTTP Gateway (Stripe API Key)

curl -X POST https://gateway.worker.md/v1/workers/receipt-tax-extractor/invoke \
  -H "Authorization: Bearer wk_live_testkey123" \
  -H "Content-Type: application/json" \
  -d '{
  "inputs": {
    "receipt_text": "ACME CAFE\\nDate: 2026-10-14\\n1x Espresso $4.50\\n1x Croissant $5.50\\nSubtotal: $10.00\\nTax: $0.95\\nTotal: $10.95",
    "expected_currency": "USD"
  }
}'

3. Autonomous Agent (HTTP 402 with Base USDC)

curl -X POST https://gateway.worker.md/v1/workers/receipt-tax-extractor/invoke \
  -H "Authorization: X402-Tx 0x4a8f9c2d1e0b5a...txhash" \
  -H "Content-Type: application/json" \
  -d '{
  "inputs": {
    "receipt_text": "ACME CAFE\\nDate: 2026-10-14\\n1x Espresso $4.50\\n1x Croissant $5.50\\nSubtotal: $10.00\\nTax: $0.95\\nTotal: $10.95",
    "expected_currency": "USD"
  }
}'

4. Python (FastAPI / LangGraph)

import httpx

async def invoke_receipt_tax_extractor() -> dict:
    payload = {
    "receipt_text": "ACME CAFE\\nDate: 2026-10-14\\n1x Espresso $4.50\\n1x Croissant $5.50\\nSubtotal: $10.00\\nTax: $0.95\\nTotal: $10.95",
    "expected_currency": "USD"
}
    async with httpx.AsyncClient() as client:
        response = await client.post(
            "https://gateway.worker.md/v1/workers/receipt-tax-extractor/invoke",
            headers={"Authorization": "Bearer wk_live_testkey123"},
            json={"inputs": payload},
            timeout=25.0
        )
        response.raise_for_status()
        return response.json()["outputs"]

Evaluation Fixtures & Benchmark Data#

Audit fixtures used to evaluate this worker specification:

{
  "suite": "receipt-tax-benchmark",
  "version": "1.0.0",
  "target_accuracy": 0.991,
  "fixtures": [
    {
      "id": "standard-us-receipt",
      "description": "Standard California restaurant receipt with 9.5% sales tax",
      "input": {
        "receipt_text": "ACME CAFE\nDate: 2026-10-14\n1x Espresso $4.50\n1x Croissant $5.50\nSubtotal: $10.00\nTax (9.5%): $0.95\nTotal: $10.95",
        "expected_currency": "USD",
        "tax_jurisdiction": "US-CA"
      },
      "expected": {
        "vendor_name": "ACME CAFE",
        "subtotal": 10.00,
        "tax_amount": 0.95,
        "total": 10.95,
        "reconciliation_status": "matched"
      }
    }
  ]
}

See also#

FAQ#

How do I invoke Receipt & Tax Extractor in my own pipeline?

You can invoke the worker package directly using the local CLI ('npx worker-md run workers/receipt-tax-extractor/WORKER.md --input ...') or deploy it to a private container gateway.

How does an autonomous agent pay via crypto?

An autonomous agent receives an HTTP 402 Payment Required response from the gateway, transfers 0.03 USDC to 0x89D24A6b4CcB1B6fAA2625fE562bDD9a23260359 on Base, and provides the transaction authorization header to execute.

How are timeout and cost constraints enforced?

The WORKER.md file declares the target limits (< 15s (Target), $0.04 (Ceiling)). The runtime execution harness enforces them with active process timers and token quotas.