Blog Post

Azure Integration Services Blog
3 MIN READ

🧾 Automate Invoice data extraction with Logic Apps and Document Intelligence

shahparth's avatar
shahparth
Icon for Microsoft rankMicrosoft
May 12, 2025

📘 Scenario: Modernizing invoice processing with AI

In many organizations, invoices still arrive as scanned documents, email attachments, or paper-based handoffs. Extracting data from these formats — invoice number, vendor, total amount, line items — often involves manual effort, custom scripts, or brittle OCR logic.

This scenario demonstrates how you can use Azure Logic Apps, the new Analyze Document Details action, and Azure OpenAI to automatically convert invoice images into structured data and store them in Azure Cosmos DB.

💡 What’s new and why it matters

The key enabler here is the Analyze Document Details action — now available in Logic Apps. With this action, you can:

  • Send any document image (JPG, PNG, PDF)
  • Receive a clean markdown-style output of all recognized content
  • Combine that with Azure OpenAI to extract structured fields without training a custom model

This simplifies what used to be a complex task: reading from invoices and inserting usable data into systems like Cosmos DB, SQL, or ERP platforms like Dynamics. 

🔭 What this Logic App does

With just a few built-in actions, you can turn unstructured invoice documents into structured, searchable records. Here’s what the flow looks like:

📸 Logic App Overview

✅ Pre-requisites

To try this walkthrough, make sure you have the following set up:

  • An Azure Logic Apps Standard workflow
  • An Azure Cosmos DB for NoSQL database + container
  • An Azure OpenAI deployment (we used gpt-4o)
  • A Blob Storage container (where invoice files will be dropped)

💡Try it yourself

👉 Sample logic app

🧠 Step-by-Step: Inside the Logic App

Here’s what each action in the Logic App does, and how it’s configured:

⚡ Trigger: When a blob is added or updated

Starts the workflow when a new invoice image is dropped into a Blob container.

  • Blob path: the name of blob container

📸 Blob trigger configuration

🔍 Read blob content

Reads the raw image or PDF content to pass into the AI models.

  • Container: invoices
  • Blob name: dynamically fetched from trigger output response

📸 Read blob configuration

 

🧠 Analyze document details (✨ New!)

This is the core of the scenario — and the feature we’re excited to highlight.

The new “Analyze Document Details” action in Logic Apps allows you to send any document image (JPG, PNG, PDF) to Azure Document Intelligence and receive a textual markdown representation of its contents — without needing to build a custom model.

📸 Example invoice (Source: InvoiceSample)

💡 This action is ideal for scenarios where you want to extract high-quality text from messy, unstructured images — including scanned receipts, handwritten forms, or photographed documents — and immediately work with it downstream using markdown.

  • Model: prebuilt-invoice
  • Content: file content from blob
  • Output: text (or markdown) block containing all detected invoice fields and layout information

📸 Analyze document details configuration

 

✂️ Parse document

Extracts the "text" field from the Document Intelligence output.
This becomes the prompt input for the next step.

📸 Parse document configuration

 

💬 Get chat completions 

This step calls your Azure OpenAI deployment (in this case, gpt-4) to extract clean, structured JSON from the text- generated earlier.

  • System Message:
    You are an intelligent invoice parser. Given the following invoice text, extract the key fields as JSON. Return only the JSON in proper notation, do not add any markdown text or anything extra. Fields: invoice_number, vendor, invoice_date, due_date, total_amount, and line_items if available
  • User Message:
    Uses the parsed text from the "Parse a document" step (referenced as Parsed result text in your logic app)
  • Temperature: 0
    Ensures consistent, reliable output from the model

📤 The model returns a clean JSON response, ready to be parsed and inserted into a database.

📸 Get chat completions configuration

📦 Parse JSON

Converts the raw OpenAI response string into a JSON object.
Use a sample schema that matches your expected invoice fields to generate a sample payload.

  • Content: Chat completion outputs
  • Schema: Use a sample schema that matches your expected invoice fields to generate a sample payload.

📸 Parse JSON configuration

🧱 Compose – format for Cosmos DB

Use the dynamic outputs from Parse JSON action and construct the JSON body input to be passed into CosmosDB. 
📸 Compose action configuration

 

🗃️ Create or update item 

Inserts the structured document into Cosmos DB.

  • Database ID: InvoicesDB
  • Container ID: Invoices
  • Partition Key: @{body('Parse_JSON')?['invoice_number']}
  • Item: @outputs('Compose')
  • Is Upsert: true

📸 CosmosDB action configuration

 

✅ Test output

As shown below, you’ll see a successful end-to-end run — starting from the file upload trigger, through OpenAI extraction, all the way to inserting the final structured document into Cosmos DB.

📸 Logic App workflow run output

💬 Feedback

 Let us know what other kinds of demos and content you would like to see in the comments.

Updated May 12, 2025
Version 3.0

2 Comments

  • mikeholdorf's avatar
    mikeholdorf
    Copper Contributor

    This works great and I was able to get this running in minutes, so great job. One note, I did change the prompt because I tested with multiple invoices and the line items did not have common headings. This was causing the Parse JSON to fail, so I modified the prompt to always output the line items that match the JSON schema. I'm not able to test with multiple vendor Invoices and get the same results.  Thanks!