I have created an AI Builder model for invoices. I am trying to use it in a Power Automate flow that is triggered when a new file is created in a SharePoint document library, but I am getting the error below:
{"operationStatus":"Error","error":{"type":"Error","code":"InvalidPredictionInput","message":"Inference input for model 6edeea37-...-e22f4fc4e2e7 is invalid","properties":{"BackendErrorCode":"InvalidInferenceInput","DependencyHttpStatusCode":"400"}}}
I have read multiple solutions to similar problems and they talk about using base64() encoding or to use a string() around the File Content. You can see these posts here. Unfortunately, I don't have the option to enter a JSON structure, as I only have two parameters: the mime type and the document (see image below)
I tried creating the expression by hand and the resulting expression is
Solved! Go to Solution.
We tried again yesterday with a two new flows and it worked. I don't know what caused the problem. Probably the PDF files were corrupt. Thanks for the time, Joe! Very appreciated
Hi @N0AH,
Thanks for posting the question.
What is the type of the file you are looking to process? PDF? JPEG? PNG?
Try replacing the Document type input parameter from the Content-type attribute to:
Let us know if this helps.
Thank you. I tried, but I still get the same error. I think it has to do with the format of the file content. I have noticed that when I feed the model with one single file it works, but when I try to take the file content from either an incoming email or a new file in SharePoint, then it does not work.
Thank you!
Thanks for the update @N0AH,
If you take that file that you are uploading to SharePoint, and do a Quick test on the Model details page, do you get results back?
I tested the model and it works fine. It recognizes all of the values correctly. see image below:
I peeked at the code using the ellipsis / peek code option in the Predict module and I found this:
If you see the highlighted part, the Predict module has a "Document" parameter. I am feeding the "File Content" parameter in the item/requestv2/base64Encoded part of the code and it is receiving the "body" value in the outputs from the "Get file content" module (@outputs('Get_file_content')?['body']).
So I decided to take a look at what are the real inputs that are being fed to the predict module. I did this by running the flow, checking the inputs for the Predict module:
"item/requestv2/mimeType":"application/pdf","item/requestv2/base64Encoded":{"$content-type":"application/pdf","$content":"SlZCRVJpMHhMamNOTVNBd0lHOWlh
you can see that the Predict module is not receiving the base64Encoded that is expecting. Instead, it is receiving a JSON structure that contains the $content-type and the $content string, probably not encoded base64. I suspect this is the reason for the error. Somehow I think I need to feed only the $content part converted to base64. So I took this parameter and I created the following expression:
base64(string(outputs('Get_file_content')?['body']?['$content']))
and I put it into the Predict module, where it is expecting the "Document" parameter like so:
The flow still failed, but when I check the inputs of the Predict module I see that the "Document" parameter is now only the base64 encoded of the file content. I got rid of all the other parameters (as shown below). However it still fails. I suspect I am very close, it is that somehow I need to provide the file content in some different format for the Predict module to be able to process it, but I don't know how I should format it.
"item/requestv2/mimeType":"application/pdf","item/requestv2/base64Encoded":"U2xaQ1JWSnBNSGh
Any ideas?
Thanks @N0AH for the update.
The flow that you are trying to build should work without having the need to do base64 transformation.
I'll send you a private message to see if we can jump into a call and have a look at this issue together.
We tried again yesterday with a two new flows and it worked. I don't know what caused the problem. Probably the PDF files were corrupt. Thanks for the time, Joe! Very appreciated
Hi @JoeF-MSFT we are facing the same issue with a predict model using pdf file but getting a Bad Request error - would you be able to provide the solution used above to solve the issue, please?
Thanks!
Hi @yabela - it seems this was caused today by an incident that is now resolved. Let us know if this is not the case.
For future visitors of this forum thread, we now recommend to use the Process and save information from forms action in the AI Builder connector, instead of the Predict action. 🙂
"We tried again yesterday with a two new flows and it worked. I don't know what caused the problem. Probably the PDF files were corrupt. Thanks for the time, Joe! Very appreciated"
It might not be corrupted PDFs.. I ran into this exact issue and realized that I had not tested the use cases of processing an email that had multiple attachments of different types (those pictures of links to facebook, twitter, etc were coming in as attachments). My original test emails only had a PDF that was a match for the model and no other attachments. My following test emails (2 days later) gave me the error shown at the top of this post. The emails that gave me errors had multiple attachments because the pictures of logos and others are all included in the Attachments array. Those attachments of other types were what was breaking my model and flow. I filtered the attachments to only process PDFs and "presto" it worked! Testing with a PDF that doesn't match the expected model will create different errors because it won't find the expected values, but it'll fail also and I need to build in some 'on failure' steps to account for those errors.
mind sharing how you did this? encountering the same issue.