AgentSkillsCN

processing-invoices

从PDF发票中提取结构化数据,包括供应商、金额、日期以及明细项目。适用于处理发票PDF或提取账单信息的场景。

SKILL.md
--- frontmatter
name: processing-invoices
description: Extracts structured data from PDF invoices including vendor, amount, date, and line items. Use when processing invoice PDFs or extracting billing information.

Invoice Processing

Workflow

code
Invoice Processing:
- [ ] Step 1: Log start time
- [ ] Step 2: Extract PDF text
- [ ] Step 3: Parse invoice fields
- [ ] Step 4: Save output AND eval log

Step 1: Log start time

Record the start time for eval tracking:

python
from datetime import datetime
start_time = datetime.now().isoformat()

Step 2: Extract text

Use pypdf:

python
from pypdf import PdfReader

reader = PdfReader("invoice.pdf")
text = ""
for page in reader.pages:
    page_text = page.extract_text()
    if page_text:
        text += page_text + "\n"

Step 3: Parse fields

Extract from text:

  • vendor: Company name (usually at document top, in larger font)
  • invoice_number: Look for "Invoice #", "Invoice No.", "INV-", "#"
  • date: Invoice/billing date -> convert to YYYY-MM-DD
  • total: Final amount ("Total:", "Amount Due:", "Balance:")

Step 4: Save results

Save two files:

  1. Output file (requested by user):
json
{
  "vendor": "Company Name",
  "invoice_number": "INV-001",
  "date": "2025-01-15",
  "total": 1250.00,
  "currency": "USD"
}
  1. Eval log (always append to eval_results/all_evals.jsonl):
bash
python scripts/collect_eval.py "<task_id>" "<original_task_prompt>" "<output_file>" "<notes>"

Example:

bash
python scripts/collect_eval.py "invoice-basic" "Extract invoice data from invoice.pdf" "output.json" "extraction completed"