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

1 Comment

  • mikeholdorf's avatar
    mikeholdorf
    Brass 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!