The following code is throwing an Invalid argument error on KeyValuePairs while keyValuePairs feature exists and is valid. Can you help explain?
AnalyzeDocumentOperation operation = await client.AnalyzeDocumentFromUriAsync(WaitUntil.Completed, "prebuilt-layout", fileUri, new AnalyzeDocumentOptions() { Features = { DocumentAnalysisFeature.KeyValuePairs } });
Error message: Azure.RequestFailedException: ‘Invalid argument. Status: 400 (Bad Request) ErrorCode: InvalidArgument Content: {"error":{"code":"InvalidArgument","message":"Invalid argument.","innererror":{"code":"InvalidParameter","message":"The parameter keyValuePairs is invalid: The feature is invalid or not supported."}}}
I tried all below feature and they work, but keyvaluepairs feature don’t work.
AnalyzeDocumentOptions options = new AnalyzeDocumentOptions();
options.Features.Add(DocumentAnalysisFeature.Barcodes);
options.Features.Add(DocumentAnalysisFeature.Formulas);
options.Features.Add(DocumentAnalysisFeature.Languages);
options.Features.Add(DocumentAnalysisFeature.FontStyling);
options.Features.Add(DocumentAnalysisFeature.OcrHighResolution);
2
Answers
My issue is resolved now. I was using the The Azure.AI.FormRecognizer 4.1.0 which defaults to the 2023-07-31 version of the service. The Document Intelligence public preview version defaults to REST API version 2023-10-31-preview. I had to add the pre-release version of the Azure.AI.DocumentIntelligence package to my project.
Prerequisites:
Create an Azure AI services or Document Intelligence single-service or multi-service.
To connect your application to the Azure Document Intelligence service:
Use Document Intelligence client library SDKs or REST API – Azure AI services.
Code taken from DOC.
Output: