cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
N0AH
Frequent Visitor

Predict connector BadRequest and InvalidPredictionInput error with File Content

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"}}} 

 

flow_error.JPG

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)

 

flow_error2.JPG

I tried creating the expression by hand and the resulting expression is 

base64(triggerOutputs()?['body']) but I got exactly the same error. It is interesting that if I use the decodeBase64() function, as shown here
decodeBase64(string(triggerOutputs()?['body'])) then the Predict action works "apparently" fine as shown below.
 
flow_error3.JPG
Unfortunately, it does not return any value.
 
flow_error4.JPG
I have tried to fix this for hours but, so far, nothing works. I appreciate any help on this regard.
 
Thank you
1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

13 REPLIES 13
JoeF-MSFT
Power Apps
Power Apps

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:

  • If the file is a .jpeg image: image/jpeg
  • If the file is a .png image: image/png
  • If the file is a .pdf document : application/pdf

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?

 

2020-05-07_23-20-54.png

 

 

I tested the model and it works fine. It recognizes all of the values correctly. see image below:

 

flow_error5.JPG

 I peeked at the code using the ellipsis / peek code option in the Predict module and I found this:

 

flow_error_predict_json.JPG

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']).

 

flow_error_6_new_flow.JPG

 

 

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:

 

flow_error_8_with_base64_expression.JPG

 

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. 

2020-05-09_17-30-55.png

 

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

@JoeF-MSFT Thank you for the help and the time. Very appreciated!!

yabela
Helper I
Helper I

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! 

JoeF-MSFT
Power Apps
Power Apps

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. 🙂

JoeF-MSFT_0-1618346274253.png

 

@JoeF-MSFT Thanks! 

"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.

JoeF-MSFT
Power Apps
Power Apps

Thanks a lot @ericsnell for sharing this knowledge back! 🙂

mind sharing how you did this? encountering the same issue.

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,655)