Hello! Welcome to your next lesson in the "Applying AI Builder Models" module.
In our last session, we focused on the critical process of evaluating and improving the performance of your AI models. You learned how to interpret accuracy scores, diagnose issues like overfitting, and use an iterative process to refine your training data. Now that you have a high-performing, reliable model, it's time to put it into action.
Today's lesson bridges the gap between the AI model and the end-user. The learning outcome is to integrate a trained AI Builder model into a Power App to process user input or images. We'll explore the practical steps and Power Fx formulas needed to bring your model to life within a Canvas App, creating a functional and intelligent business application. This is a core skill for the PL-400 exam and a common requirement in modern Power Platform solutions.
1. Methods of Integration in Canvas Apps
When you integrate an AI model into a Canvas App, you are essentially making an API call to the AI Builder service and then processing the JSON response it sends back. Power Apps simplifies this into two primary methods:
- AI Builder Components: These are specialized, pre-built controls available in the "Insert" pane (e.g.,
Form processor,Object detector). They provide a user interface for capturing input (like using the device camera) and handle the call to the model. This is the most straightforward method for models that process images or documents. - Power Fx
PredictFunction: This is a more direct, code-based approach where you call the model using a formula:'Your Model Name'.Predict(input). This method offers maximum flexibility and is ideal for models that process text or when you want to build a fully custom UI for triggering the model and handling its output.

First, let's see how to add your model to the app. Regardless of the integration method you choose, the first step is always to add the AI Builder model as a data source.

2. Integrating an Image-Based Model: Form Processing
Let's start with a common and powerful scenario: building an app to scan invoices and automatically extract key information. This uses the Form Processing model you've learned about and the dedicated AI Builder component.
This video from Reza Dorrani provides an excellent end-to-end demonstration. We'll focus on the part where he integrates the trained model into a Power App.
Multiple forms Processing using AI Builder (Different Layouts)
Watch this section of the video 'Multiple forms Processing using AI Builder' to see how to add the Form Processor component to a Canvas App, analyze a document, and display the extracted fields and table data.
Watch from 09:50 to 19:41. Pay close attention to how the outputs of the form processor control are used. Specifically, note the formulas used to display a single field's value in a label and to populate a gallery with the extracted line items table.
As you saw in the video, the process involves these key steps:
- Insert the Component: Add the Form processor control from the
AI Buildersection of theInsertpane. - Link the Model: In the properties panel for the component, set the
AI modelproperty to the form processing model you added as a data source. - Process the Output: After a document is analyzed, the component's
Resultsproperty is populated. This property contains all the extracted data.- Accessing Fields: To display a single extracted field, you access it through the
Fieldsproperty. For example, if your component is namedFormProcessor1and you extracted a field namedInvoiceID, the formula for a label'sTextproperty would be:FormProcessor1.Results.Fields.InvoiceID.Value - Accessing Tables: To display line items from an extracted table, you use the
Tablesproperty as theItemssource for a gallery. If you extracted a table namedInvoiceItems, you would set the gallery'sItemsproperty to:
You can then bind labels inside the gallery to the columns of that table, likeFormProcessor1.Results.Tables.InvoiceItemsThisItem.DescriptionorThisItem.Amount.
- Accessing Fields: To display a single extracted field, you access it through the
3. Integrating an Image-Based Model: Object Detection
The pattern for integrating an object detection model is very similar. This is useful for scenarios like inventory counting, retail shelf analysis, or quality assurance.
Let's look at another practical video that builds an inventory counting app.
Using the Power Apps AI Builder Object Detector 🤖 [Episode 41]
The video 'Using the Power Apps AI Builder Object Detector' demonstrates building a complete inventory solution. We'll focus on the integration and data handling parts.
First, watch from 08:43 to 11:34 to see how the Object Detector component is added and its output is bound to a gallery. Then, watch from 11:34 to 14:49 to see a more advanced, practical use case: using the detected objects to look up and patch data in a Dataverse table. This second part will be very familiar given your background with data operations.
The key takeaway here is how the output of the Object detector component is structured.
- Accessing Detected Objects: The
ObjectDetector1.VisionObjectsproperty returns a table of all objects the model is capable of detecting. - Displaying Results: You can set a gallery's
Itemsproperty toObjectDetector1.VisionObjects. Each record in this table contains:DisplayName: The name of the detected object (e.g., "Coca-Cola Can").Count: The number of times that object was detected in the image.BoundingBox: The coordinates of the detected object(s).
- Filtering for Detected Items: To show only the items that were actually found in the picture, you can filter the gallery:
Filter(ObjectDetector1.VisionObjects, Count > 0)
As shown in the video, you can then use this information within a ForAll or Patch function to update an inventory list in Dataverse, turning the AI detection into a powerful data entry tool.
Test your understanding!
You've added an Object detector component named ObjectDetector_Main to your screen. You want to display the number of "Hard Hat" objects detected in a label. What Power Fx formula would you use for the label's Text property?
Hint: You'll need to find the specific record for "Hard Hat" in the output table.
Show answer
You would use the LookUp function to find the correct row in the VisionObjects table and then access its Count property.
LookUp(ObjectDetector_Main.VisionObjects, DisplayName = "Hard Hat").Count
4. Integrating a Text-Based Model with Power Fx
Now let's cover the "user input" part of our learning outcome by integrating a model that processes text. For this, we'll use the Predict function, which gives you more granular control. We'll use the pre-built Language detection model as a simple and effective example.
Use AI Builder models in Power Apps
The Microsoft Learn article 'Use AI Builder models in Power Apps' provides the official documentation on this topic. It walks through adding a model and provides the syntax for the Predict function.
Please read the sections 'Use a model with controls' and 'Best practices'. The example shows how to use the Language detection model with a text input. The 'Best practices' section contains crucial advice for optimizing performance and credit usage, which is highly relevant for a professional developer.
Here's a summary of the process:
-
Add the Model: Add the
Language detectionmodel as a data source. -
Add Controls: Add a
Text inputcontrol (TextInput1) for the user to type in and aText labelcontrol (Label1) to show the result. -
Use the
PredictFunction: Set theTextproperty ofLabel1to the following formula:'Language detection'.Predict(TextInput1.Text).LanguageThe
Predictfunction returns an object, and we are accessing theLanguageproperty of that object.
Developer Best Practices
As the article mentions, blindly binding the Predict function to a control's OnChange property is inefficient. It will call the AI model on every keystroke, which consumes AI Builder credits rapidly and can slow down your app.
A much better pattern, especially given your development background, is to treat the AI model call like any other API call:
- Trigger On-Demand: Place a
Buttonon the screen. Use itsOnSelectproperty to call the model. This gives the user explicit control. - Cache the Result: Store the entire output object from the
Predictcall in a variable. You can then use this variable to populate multiple labels (e.g., one for language, one for confidence score) without making redundant API calls.
Here's the improved implementation:
Button's OnSelect property:
// Call the model once and store the entire result object in a variable
Set(
gblLanguageResult,
'Language detection'.Predict(TextInput1.Text)
)
Label for Language (Text property):
gblLanguageResult.Language
Label for Confidence Score (Text property):
Text(gblLanguageResult.Confidence * 100, "0.0") & "%"
This approach is more performant, cost-effective, and aligns with professional software development practices. The Microsoft Learn article "Use AI Builder models in Power Apps" also includes a helpful table of inputs and outputs by model type, which is an invaluable reference for knowing the exact structure of the object returned by each model.
Conclusion
In this lesson, you have learned the two primary methods for integrating AI Builder models into Power Apps. You can now build sophisticated applications that leverage AI to process images, documents, and user-provided text.
Key Takeaways:
- AI models are added to Canvas Apps via the Data pane.
- Image and document models are best integrated using their dedicated AI Builder components (e.g.,
Form processor). The output is accessed via the component'sResultsproperty. - Text-based models and custom scenarios are handled with the
'Model Name'.Predict(input)Power Fx function. - The output of a model call is an object or table that you parse to display the results.
- For performance and cost-efficiency, trigger AI model predictions on-demand (e.g., a button's
OnSelect) and store the results in a variable for reuse.
What's Next?
So far, you've used AI Builder interactively within a Power App. But what about automating backend processes? In the next lesson, you will learn how to integrate a trained AI Builder model into a Power Automate flow to automate document or text processing. This will enable you to build powerful, end-to-end automations, such as processing invoices attached to emails without any user interaction.