From manual to automated: Building AI agents for procurement document processing

Table of contents

    From manual to automated: Building AI agents for procurement document processing

    Is your team drowning in procurement documents? Purchase orders, invoices, receipts, payments — hundreds of them flow through your system daily. Hours are spent manually matching invoices to purchase orders, chasing missing payments, and flagging exceptions.

    What if an AI agent could handle 70 percent of this work automatically, surfacing only the problematic documents that actually need human attention? That’s exactly what this post will explore using a procurement example.

    TL;DR

    AI agents can automate document processing through classification, data extraction, and three-way matching — while intelligently flagging exceptions for human review.

    The procurement document matching problem

    Procurement can follow many different processes, but this example will use a three-way matching process with the following document requirements:

    • Purchase order (PO) — What was ordered
    • Invoice — The amount the vendor is charging
    • Payment — What was paid

    Once an order is complete, all these documents should be present, and all the values must match. But things often go awry, and it takes human time to chase down vendors and buyers to sort out messes.

    It’s easy to see how this process breaks down quickly:

    • Documents arrive in different formats and layouts.
    • Reference numbers might be missing or inconsistent.
    • Amounts can vary due to shipping, taxes, or discounts.
    • Emergency purchases bypass normal PO processes.
    • Partial shipments create incomplete document sets.

    Humans are great at spotting these patterns, but it’s time-consuming and error-prone at scale.

    Enter AI agents with document processing superpowers

    By combining AI agents with document processing tools, it’s possible to automate most of this workflow while preserving human oversight for the tricky cases. For simple workflows that follow the correct procedure, a human shouldn’t have to be involved. Matches are made, and costs are checked and flagged as complete. If not, then call the human.

    The AI agent approach uses a three-stage pipeline:

    1. Upload and classification — AI determines a document type and extracts key data
    2. Three-way matching — With the extracted data, traditional programming logic matches related documents
    3. Exception handling — Surface discrepancies in documents and data for human review

    All this can be made simple using any AI agent framework combined with Nutrient Document Engine MCP Server(opens in a new tab).

    In the following sections, I’ll share an example of how to build an AI agent for procurement document processing using Nutrient Document Engine MCP Server and LangGraph.js(opens in a new tab). If you want to see the full example, you can find it in the examples section of Nutrient Document Engine MCP Server(opens in a new tab).

    Stage 1: AI-powered document classification

    To implement a classification AI agent, you need to read the content of a document. The first challenge you’ll hit is that documents can come in a variety of formats: PDFs, Office documents, and even images. At Nutrient, we want to take that worry off your hands and abstract file types away from your workflow. All you need is to use the extraction functions provided by the Document Engine MCP Server for your AI Agent.

    Using the LangGraph.js(opens in a new tab) agent framework, connect to the Document Engine MCP Server, filter for the exact tools required for classification, and create a ReAct agent with the following:

    // Create the client to connect to Document Engine MCP Server.
    const mcpClient = new MultiServerMCPClient({
    mcpServers: {
    documentEngine: {
    transport: "http",
    url: "http://localhost:5100/mcp",
    },
    },
    });
    // Filter for the extraction tools only.
    const relevantTools = await mcpClient
    .getTools()
    .then((tools) =>
    tools.filter(
    (tool) =>
    tool.name?.includes("extract_text") ||
    tool.name?.includes("extract_tables") ||
    tool.name?.includes("extract_key_value_pairs") ||
    tool.name?.includes("extract_form_data"),
    ),
    );
    // Create the ReAct agent with the filtered tools and prompt.
    const agent = createReactAgent({
    llm: model,
    tools: relevantTools,
    prompt: CLASSIFICATION_PROMPT,
    });

    The AI agent operates in a ReAct loop: It thinks about what to do, uses tools to extract information, observes the results, and repeats until it can confidently classify the document.

    For example, with an invoice, it might:

    1. Extract text to find the word “Invoice” or “Bill.”
    2. Look for structured data like invoice numbers and amounts.
    3. Check for PO references that link to other documents.
    4. Analyze the layout to confirm document type.

    In the full example, I ask the model to extract some information about the document and then request structured parsing to retrieve a JSON output like the following:

    {
    "type": "invoice",
    "confidence": 0.95,
    "extractedData": {
    "invoiceNumber": "INV-2024-0156",
    "poReference": "PO-2024-001",
    "vendor": "ACME Office Supplies Inc.",
    "amount": 17292.4,
    "date": "2024-01-15"
    }
    }

    The beauty of using an AI agent here is the adaptability. If all your documents used the exact same template, you could use heuristics to parse the document. But as I mentioned earlier, the documents you receive may not be in a single format, and even if they are, they may not display the information in a common format. AI agents can adapt to these variances and reactively extract data from structures they’ve never seen before.

    Stage 2: Intelligent three-way matching

    Once documents are classified and data is extracted, the matching logic kicks in. This is where we shift from AI reasoning back to traditional programming — because matching rules are well-defined business logic.

    The system uses a two-tier matching strategy, outlined below.

    Strategy 1: Reference number matching

    // Match by exact reference numbers (most reliable).
    for (const po of purchaseOrders) {
    const relatedInvoices = invoices.filter(
    (inv) => inv.extractedData.poReference === po.extractedData.poNumber,
    );
    const relatedPayments = payments.filter(
    (pay) =>
    pay.extractedData.invoiceReference ===
    relatedInvoices[0]?.extractedData.invoiceNumber,
    );
    if (relatedInvoices.length && relatedPayments.length) {
    // Perfect three-way match found.
    groups.push({
    po,
    invoice: relatedInvoices[0],
    payment: relatedPayments[0],
    });
    }
    }

    Strategy 2: Vendor and amount matching

    Here’s an example of matching invoices and purchase orders:

    // Fall back to vendor + amount matching with some hysteresis.
    const matchingInvoices = invoices.filter(
    (inv) =>
    inv.extractedData.vendor === po.extractedData.vendor &&
    Math.abs(inv.extractedData.amount - po.extractedData.amount) < 100, // Allow small variances
    );

    This applies to basic matching and works most of the time, but I’m sure there’s better business logic you could apply for your company!

    Stage 3: Exception handling that actually helps

    Here’s a super useful area where you can help initiate action more quickly. Because the matching logic defines what information is missing, it’s possible to provide actionable advice back to the user.

    Using the example dataset in the Document Engine MCP Server repository, you’ll end up with the following situations:

    Complete Match (70% of cases):
    - PO-2024-001 → INV-2024-0156 → PAY-2024-0089
    - All reference numbers align, amounts match (within tolerance)
    - Status: ✅ No action needed
    Emergency Purchase (Orphan Invoice):
    - Emergency HVAC repair: $3,572.25
    - No PO (after-hours emergency)
    - Status: ❌ Urgent review needed
    - Suggestion: "Create retroactive PO for emergency repair"
    Partial Shipment:
    - PO for 500 bearings → Invoice for 300 bearings
    - Amounts: $12,781.25 vs $7,490.62
    - Status: ⚠️ Partial delivery
    - Suggestion: "Awaiting remaining 200 bearings"

    The system surfaces exactly what information is missing and suggests what the next steps are. You could even take the agentic design a step further and perform those actions with AI if you have the right tools connected!

    Conclusion

    AI agents won’t replace your finance team, but they will transform how they work. By automating much of the manual document processing, your team can focus on the small percentage of problematic cases that actually require human judgment.

    The procurement example shows a clear path forward: Start with document classification, add intelligent matching, and design thoughtful exception handling. The result is a system that works with your team, not against them.

    Want to try it yourself? The complete example is available in the Nutrient Document Engine procurement example(opens in a new tab) — with sample documents, classification logic, and matching algorithms all ready for you to copy.

    Nick Winder

    Nick Winder

    Core Engineer

    When Nick started tinkering with guitar effects pedals, he didn’t realize it’d take him all the way to a career in software. He has worked on products that communicate with space, blast Metallica to packed stadiums, and enable millions to use documents through Nutrient, but in his personal life, he enjoys the simplicity of running in the mountains.

    Explore related topics

    FREE TRIAL Ready to get started?