Invoice fraud detection

From XuShuwenn/RedAct · View interactive version

Invoice fraud detection is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Detect invoice fraud by checking vendor approval, IBAN matching, PO validity, and amount consistency.

How to use this skill

Skill file

Invoice Fraud Detection

When to Use

When to Use

Execution Protocol

Input Files

Required Workflow

  1. Inspect the real schemas of vendors.xlsx and purchase_orders.csv before writing lookup logic; verify actual column names, types, and a few sample rows instead of assuming headers from this skill.
  1. Extract and inspect sample text from multiple invoice pages before applying fraud rules; confirm how vendor name, IBAN, PO number, amount, and any Vendor ID actually appear, and whether layouts vary.
  1. Validate extraction quality before matching: inspect representative pages from early, middle, and late portions of the PDF.
  2. Treat truncated, garbled, or partial extraction as incomplete evidence. If any page looks malformed or fields are missing unexpectedly, fix extraction first or use a fallback method; do not assume the field is absent from the invoice.
  3. Parse defensively: initialize missing values to null, guard all field lookups, and do not silently skip pages. Confirm expected page count matches extracted invoice records and that every page is accounted for.
  1. Before classifying fraud, inspect parsed vendor_name, iban, po_number, and invoice_amount on representative pages, including at least one flagged and one unflagged invoice when available.
  1. Compare parsed field values against raw PDF text on representative pages and require exact agreement for key fields before trusting classification. For labeled fields such as Payment IBAN: ..., preserve the full visible value; any truncation or malformed capture means extraction is not ready.
  2. If any targeted check exposes a logic gap, parser defect, or source-to-output mismatch, stop classification, fix the logic or extraction, regenerate the report, and re-run verification on the affected cases before concluding.
  3. Do not promote page-specific regexes or field labels to document-wide logic until they succeed on representative pages from across the PDF, including pages with different layouts or missing fields.
  4. Prefer a saved Python script over long shell-embedded Python when logic is nontrivial. If you do use inline code, inspect the exact command for quoting, regex, or comparison corruption before trusting the result.
  1. Before trusting aggregate outputs such as reason counts or number of flagged invoices, verify that the executed code actually ran the intended fraud logic and that critical branches behaved as expected on representative pages.
  2. Verify the format of every intermediate artifact before writing downstream logic against it. If you save extracted invoices, parsed records, or match candidates, re-open one or two records and confirm whether the file is JSON, JSONL, CSV, or another structure before indexing into it.
  3. Prefer dependency-light methods first. If rapidfuzz, fuzzywuzzy, or another optional package is unavailable, do not stop to install packages into the environment; use a built-in fallback (for example normalized exact matching plus difflib.SequenceMatcher or get_close_matches) and continue with explicit manual review of ambiguous matches.
  4. Do not treat package installation as part of the core workflow. In restricted environments, switch methods immediately instead of attempting environment modification.
  1. After any edit to extraction, matching, or classification code, run a targeted end-to-end check on the changed behavior before trusting the full report. Do not rely on assumed replacements; inspect the actual saved code and confirm it executes and produces the expected fields and reasons on representative invoices.
  2. Treat repeated command failures, syntax errors, empty debug output, or unexpectedly blank parses as a stop signal. Fix the script, rerun it, and verify the affected pages or records directly before making further pipeline edits or fraud conclusions.
  3. After any repair to the script or logic, discard conclusions drawn from earlier failed, partial, or pre-edit diagnostics. Regenerate /root/fraud_report.json and validate again using successful commands that read the actual saved outputs.
  4. Do not describe extraction, normalization, fuzzy matching, null handling, priority order, exact JSON shape, or other implementation details unless you inspected the saved script/code or produced targeted validation output showing those behaviors actually ran.
  1. Treat suspicious aggregate outcomes as a hard stop for reinspection, not a success signal. If most invoices are flagged, almost none are flagged, an expected fraud reason never appears, or one source-table inspection is only a header, tiny preview, or truncated snippet, re-open the underlying PDF and reference files, confirm full row counts and representative records, and re-check joins and lookups before accepting the result.

Fraud Criteria (in priority order)

  1. Unknown Vendor: Vendor name not in vendors.xlsx (use fuzzy matching for typos)
  2. IBAN Mismatch: Vendor exists but IBAN doesn't match
  3. Invalid PO: PO number not in purchase_orders.csv
  4. Amount Mismatch: PO exists but amount differs by > 0.01
  5. Vendor Mismatch: PO linked to different Vendor ID

Output Format

JSON at /root/fraud_report.json:

[
  {
    "invoice_page_number": 1,
    "vendor_name": "Acme Corp",
    "invoice_amount": 5000.00,
    "iban": "US1234567890",
    "po_number": "PO-1001",
    "reason": "IBAN Mismatch"
  }
]

Verification Before Finalizing

Verification Before Finalizing

Completion Discipline

Tips

Extraction Rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.