Hello! Welcome back to our module on "Applying AI Builder Models."
In our last session, we successfully built a Power Automate flow that integrated a custom document processing model. You learned how to trigger a flow from an event, use the AI Builder action to extract structured data from a form, and then use that data to create records in Dataverse, even handling table data with Apply to each loops.
Today, we'll continue working with AI Builder in Power Automate, but we'll switch our focus to a powerful prebuilt model. Our goal is to learn how to use the prebuilt text recognition AI model in a flow to extract text from an image.
This is different from what we did last time. The document processing model is designed for structured or semi-structured documents where you know what fields to expect (e.g., "Invoice Number," "Total Amount"). Text recognition, on the other hand, is about Optical Character Recognition (OCR). It extracts all printed or handwritten text it can find in an image or PDF, making it perfect for unstructured sources like a photograph of a whiteboard, a scanned letter, or a screenshot. This is a fundamental capability for digitizing information and is a key skill for the PL-400 exam.
1. Introducing the Text Recognition Model
The text recognition model is one of AI Builder's prebuilt models, meaning you can use it immediately without any training. It takes an image or PDF file as input and returns the text it finds.
To get started, we'll build a simple cloud flow that uses this model. The official Microsoft Learn documentation provides a clear, step-by-step guide for this.
Use the text recognition prebuilt model in Power Automate
The article 'Use the text recognition prebuilt model in Power Automate' from Microsoft Learn is the best place to start. It will walk you through creating the flow and adding the correct AI Builder action.
Please read the section 'Initialize the Power Automate cloud flow'. Follow the steps to create an 'Instant cloud flow' that is manually triggered and accepts a file as input. Then, add the 'Recognize text in an image or a PDF document' action from the AI Builder connector. Pay attention to how the 'File Content' from the trigger is passed to the 'Image' input of the AI Builder action.
As you saw in the guide, the initial setup is straightforward:
- Trigger: We use a manual trigger with a file input for easy testing. In a real-world scenario, this could be
When a new email arrives (V3)orWhen a file is created in a folder (SharePoint). - Action: The core of the flow is the
Recognize text in an image or a PDF documentaction. - Input: You provide the file content from your trigger to the
Imageparameter of this action.
Now, let's look at what the model gives back. As a developer, understanding the output structure is critical.
Understanding the Model's Output
The Text Recognition model returns a structured JSON object. The most important parts are:
results: An array where each item represents a page in the document.lines: Inside eachresultitem, there is alinesarray. Each item in this array is an object representing a single line of detected text.text: The actual string of text for that line.boundingbox: The coordinates of where the text was found in the image.
Power Automate also provides two convenient high-level outputs for simpler scenarios:
Full text of the documentFull text of the page
2. Processing Extracted Text in Your Flow
Once the AI model has run, you need to decide how to use the text it extracted. There are two main patterns for this.
Pattern 1: Using the Full Text
For simple use cases where you just need the entire block of text, you can use the Full text of the document dynamic content. This is the quickest way to get the result.
For example, you could extract all the text from an image and post it to a Teams channel for review.

This approach is best when you don't need to parse or analyze the text but simply want to store or display it as a whole.
Pattern 2: Processing Text Line by Line
For more advanced scenarios, you need to iterate through the text line by line. This is necessary when you're searching for specific information, need to reformat the output, or want to perform conditional logic on each line.
Since the lines output is an array, you'll use the Apply to each control, just as you did in the previous lesson for table data. Power Automate is smart enough to know that the model can return text from multiple pages, so it will often automatically create two nested loops for you: one for pages (results) and one for lines (lines).
The following article provides a concise example of this pattern.
PowerApps AI Builder: How to Leverage Image and Text ...
The article 'PowerApps AI Builder: How to Leverage Image and Text Recognition' by Satyam Singh Chauhan offers another practical example. We will focus on the Power Automate part, which showcases the line-by-line processing technique.
Please read the section 'Here is an example of how to use AI Builder for image and text recognition in a Power Automate flow'. Notice the use of the 'Apply to each' control on the 'Lines' field and the expression items('Apply_to_each')['Text'] used to access the text of the current line.
The general steps for this pattern are:
- Initialize a Variable: Before the loop, create a variable (e.g., a string or an array) to store the results you care about.
- Apply to each: Add an
Apply to eachcontrol and select thelinesoutput from the AI Builder action. - Process Each Line: Inside the loop, you have access to the
Textof the current line. You can:- Append it to a string variable.
- Use a Condition to check if it contains a keyword.
- Use expressions to transform it.
- Take Action: After the loop, use the processed data stored in your variable.
The image below shows a complete flow that recognizes text, processes it in a loop, and then sends an email—a common business automation pattern.

Test your understanding!
Imagine you are using the text recognition model to process images of shipping container doors. The container ID you need to extract is always on a line that starts with the prefix "ID: ".
How would you design a flow to extract only the container ID number (without the prefix) from an image and store it in a string variable? Describe the key actions and logic.
Show answer
- Trigger and AI Action: Start with a manual trigger that accepts a file and use the
Recognize text in an image or a PDF documentaction. - Initialize Variable: Add an
Initialize variableaction. Create a string variable namedContainerIDand leave its initial value empty. - Apply to each: Add an
Apply to eachcontrol and provide thelinesoutput from the AI Builder action as its input. - Condition: Inside the loop, add a
Conditioncontrol. Set the condition to check if theTextdynamic content (from the current line in the loop) starts with the value"ID: ". - Set Variable: In the "If yes" branch of the condition, add a
Set variableaction. Select theContainerIDvariable. For theValue, use an expression to remove the prefix:replace(item()?['text'], 'ID: ', ''). This expression takes the text of the current item in the loop and replaces the prefix with an empty string. - End of Flow: After the
Apply to eachloop, theContainerIDvariable will hold the extracted ID number, ready to be used in subsequent actions like updating a Dataverse record.
Conclusion
In this lesson, you've added another powerful AI capability to your Power Automate toolkit. You learned how to use the prebuilt text recognition model to digitize text from images and PDFs, a common requirement in business process automation.
Key Takeaways:
- Text Recognition vs. Document Processing: Use text recognition for unstructured text extraction (OCR) and document processing for extracting specific, named fields from structured forms.
- Processing Outputs: You can either grab the
Full text of the documentfor simple cases or use anApply to eachloop on thelinesoutput for granular control and parsing. - Practical Application: This skill is crucial for automating tasks like digitizing scanned archives, processing photos of notes, or extracting information from non-standard documents where a custom model isn't practical.
What's Next?
We've now seen AI Builder integrated into both Power Apps and Power Automate. In our final lesson for this module, we will explore another prebuilt text model, but this time we'll integrate it directly into a Power App. You will learn how to use the prebuilt key phrase extraction AI model in an app to analyze user-provided text, which will enable you to build apps that can understand and react to user input in real-time.