Confidence score check in Document Understanding

Hi Everyone,
I’m trying to check the confidence score of each field from ExtractedResult and if the score is below 0.7 then I’m throwing a business exception, but if there is no data extracted for any particular field then I’m getting an error as “If: Index was outside the bounds of the array.”
please see the below screenshots for more details:

item = ResultsDataPoint { DataSource=Automatic, DataVersion=0, FieldId=“NoGroup.NoCategory.PO8.InvoiceDate”, FieldName=“Invoice Date”, FieldType=Date, IsMissing=true, OperatorConfirmed=false, Values=ResultsValue[0] { } }

I also tried item.value(0) isNot Nothing, but still getting same error.
How to handle if item.values(0) is Empty?
If anyone knows how to handle this scenario, please help…

Thanks & Regard,
Nitesh

that’s your IF condition that is trying to access an element which doesn’t exists.

before using the element of array, check the length of that array.

You can check, if the value is not there, what is the number of array elements in array and then put a if condition to check array length and accordingly proceed

Hope this helps!

Hi @Nitesh_Rajput,

Instead of is nothing, you can use below:

string.IsNullOrEmpty(“enter value to be checked here”)

Also are you able to get the confidence value when its not empty?

Regards
Sonali

how this will work if the element does not exist?

The issue is the element was not there, as there were fewer data field extracted → that array had less element and hence the index @Nitesh_Rajput was trying to use was not found as it was not there)

Below is the same error if we use the string.IsNullOrEmpty(

Hi @rahulsharma,

Here is what I interpret from the problem statement:

Results are extracted for few columns and for few not extracted (which is common wrt Doc processing).

Where it is extracted, it works fine, but for columns where its not extracted, it throws error.
Now when result is not extracted for particular column , can be checked using isnullorempty in my view.

Hope this helps.

Regards
Sonali

1 Like

Appreciate your clarification! May be you wanted to mention using that syntax before the IF?

You are absolutely correct with this, but if we are looping through the values then the fields will not have any element to check on, item.value will be NULL

but item.value(0) will not exists, hence checking this for NULL will again throw the ugly red colored sentence.

Hence we ideally check if the value exists that can also be done with the help of syntax you mentioned but not for the array element of the current item’s value, it should be for the current item’s value

May be @Nitesh_Rajput can try out too and let us know!

1 Like

First off, please use the Document Understanding Process template found in Studio

CDec(io_ExtractionResults.ResultsDocument.Fields.Where(Function(field) field.FieldName.Equals(confField)).Select(Function(actual_field) actual_field.Values.Select(Function(val) val.Confidence))(0)(0))*100 < CDec(in_Config("other-Confidence"))

That’s how you check to see if the confidence of a field is lower than something you have set in your config file.

May I ask how to present the Overall confidence?

How to check for multiple field’s in single condition