Page cover image

Invoice AI

The Invoice AI Solution leverages advanced AI capabilities for parsing and analyzing invoice documents. It automates the extraction of key fields from uploaded invoices (images or PDFs) and performs anomaly detection using AI models. This solution streamlines invoice workflows, improves data accuracy, and flags irregularities for review.

This flow is useful for automatically analyzing invoice inputs, storing structured results, and identifying anomalies for further processing.

This template can be found in the Services Catalog under the following categories:

  • AI, Enrichment, Workflow Management


What's Included

  • 2 Flows

    • Invoice AI Web

    • Invoice AI Anomaly Detection

  • 2 Agents

    • HTTP Agent

    • Event Agent

  • 1 Object Type

    • Invoice AI Data

  • 1 Connection

    • Anthropic Claude API


What You'll Need

  • An API key for the Anthropic Claude API


Ideas for Using Invoice AI

Automated Invoice Processing

Use AI to extract structured invoice data (e.g., Vendor Name, Address, Service Date) and eliminate manual data entry tasks.

Financial Anomaly Detection

Leverage historical patterns to identify irregularities in invoice terms, amounts, or services, helping detect fraud or errors.

Vendor Payment Validation

Automatically validate vendor details against historical records to ensure consistency and prevent discrepancies.

Improved Financial Audits

Simplify audits by maintaining structured invoice records with flagged anomalies for rapid review and resolution.


Flow Overview

Invoice AI Web Flow

  • Flow Start: The flow begins when a user uploads an invoice file (image or PDF) through the web interface.

  • Convert File to Base64: Converts the uploaded file into a Base64 format for API compatibility.

  • Send to Claude API: Sends the file data and structured prompt to the Anthropic Claude API for parsing.

  • Extract and Store Data: Processes the API response, extracts key invoice fields, and stores them as structured records in the system.

  • Trigger Anomaly Detection: Sends the invoice record to the Invoice AI Anomaly Detection flow for anomaly analysis.

  • Error Handling: Captures and logs any errors during file upload, API calls, or record creation.

Invoice AI Anomaly Detection Flow

  • Flow Start: Triggered when a new invoice record is created.

  • Retrieve Historical Records: Searches for historical invoices from the same vendor for comparison.

  • Send to Claude API: Prepares the anomaly detection prompt and sends it to the Anthropic Claude API.

  • Parse API Response: Processes the API's anomaly response to identify and summarize anomalies.

  • Update Invoice Record: Patches the original invoice record with anomaly details and status.

  • Error Handling: Logs any errors encountered during anomaly detection or record updates.


Flow Details

Invoice AI Web Flow

  1. HTTP Input Node

    • Node: Web

    • Purpose: Receives uploaded invoice files (image/PDF) from the web interface.

  2. Convert File to Base64

    • Node: Convert to Base64

    • Purpose: Converts the uploaded file buffer to a Base64 string for API submission.

  3. Prepare Claude API Payload

    • Node: Prepare PDF/IMG for Claude

    • Purpose: Formats the data for the Anthropic Claude API. Example Code:

    msg.claudePrompt = {
        model: "claude-3-5-sonnet-20240620",
        messages: [
            {
                role: "user",
                content: [
                    {
                        type: "document",
                        source: { type: "base64", data: msg.payload.toString('base64') }
                    },
                    { type: "text", text: "Extract: Vendor Name, Address, Date, Amount, and Payment Terms." }
                ]
            }
        ]
    };
    return msg;
  4. Send to Claude API

    • Node: Send to Claude

    • Purpose: Submits the formatted payload to the Claude API and receives structured invoice data.

  5. Parse API Response

    • Node: Parse Response

    • Purpose: Extracts invoice fields (e.g., Vendor Name, Amount) from the Claude API response. Example Code:

    msg.payload = {
        vendorName: extractValue(text, 'Vendor Name'),
        invoiceAmount: '$' + extractValue(text, 'Invoice Amount').replace('$', ''),
        paymentTerms: extractValue(text, 'Payment Terms')
    };
    return msg;
  6. Create Invoice AI Record

    • Node: Create Invoice AI Record

    • Purpose: Saves the extracted data to the Invoice AI Data object type.

  7. Trigger Anomaly Detection

    • Node: Send for Anomaly Detection

    • Purpose: Sends the new record to the anomaly detection flow for analysis.

  8. Error Handling

    • Nodes: Catch, Error Log

    • Purpose: Captures and logs any errors during upload, API interaction, or record creation.


Invoice AI Anomaly Detection Flow

  1. Retrieve Historical Records

    • Node: Search Historical Invoices

    • Purpose: Fetches historical records for the vendor to identify patterns.

  2. Prepare Anomaly Detection Request

    • Node: Prepare for Anomaly Detection

    • Purpose: Structures a prompt comparing the current invoice to historical records. Example Code:

    const prompt = `Compare this invoice:\n${JSON.stringify(currentInvoice)}\nTo historical invoices:\n${JSON.stringify(historicalInvoices)}`;
    msg.payload = {
        model: "claude-3-5-sonnet-20240620",
        messages: [{ role: "user", content: prompt }]
    };
    return msg;
  3. Send to Claude API

    • Node: Send to Claude

    • Purpose: Submits the request for anomaly detection.

  4. Parse Anomaly Response

    • Node: Parse Response

    • Purpose: Extracts anomaly, anomalySummary, and anomalyStatus from the API response.

  5. Update Invoice Record

    • Node: Patch Invoice Record

    • Purpose: Updates the invoice record with anomaly details.

  6. Error Handling

    • Nodes: Catch, Error Log

    • Purpose: Logs errors for debugging.


Summary of Flow

  • Flow Start: Invoice files are uploaded through a web interface.

  • Data Preparation: Files are converted to Base64 and sent to the Claude API for parsing.

  • AI Processing: Structured invoice data is extracted and stored.

  • Anomaly Detection: Invoice records are analyzed for anomalies using historical data.

  • Error Handling: Errors are captured and logged for review.

Last updated

Was this helpful?