Process Result Fields

Reference documentation on processing result fields of the response using the Mindee client libraries.

Requirements

You'll need to have a response object as described in the Process the Response section.

Accessing Result Fields

Fields are completely dynamic and depend on your model's Data Schema.

In the client library, you'll have access to the various fields as a key-value mapping type (Python's dict, Java's HashMap, etc).

Accessing a field is done via its name in the Data Schema.

Each field will be one of the following types:

  • A single value, SimpleField class.

  • A nested object (sub-fields), ObjectField class.

  • A list or array of fields, ListField class.

SimpleField - Single-Value Field

Basic field type having the value attribute. See the value section below.

In addition, the Simplefield class has confidence and locations attributes.

Using the response deserialized object from either the polling response or a webhook payload.

from mindee import InferenceResponse

def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields

    my_simple_field = fields["my_simple_field"]

value

The extracted data value. Possible types: string, number (integer or floating-point), boolean. All types can be null.

On the platform, you can specify date and classification types. These are returned as strings.

For statically-typed languages (C#, Java), the client library will always return a nullable double for number values.

Using the response deserialized object from either the polling response or a webhook payload.

from mindee import InferenceResponse

def handle_response(response: InferenceResponse):
  fields: dict = response.inference.result.fields

  # texts, dates, classifications ...
  string_field_value: str = fields["string_field"].value;

  # a JSON float will be a float
  float_field_value: float = fields["float_field"].value;

  # even if the API always returns an integer, the type will be float
  int_field_value: float = fields["int_field"].value;

  # booleans
  bool_field_value: bool = fields["bool_field"].value;

ObjectField - Nested Object Field

Field having a fields attribute which is a hash table (Python's dict, Java's HashMap, etc) of sub-fields. See the fields section below.

In addition, the ObjectField class has confidence and locations attributes.

Using the response deserialized object from either the polling response or a webhook payload.

from mindee import InferenceResponse

def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields

    object_field = fields["my_object_field"]

fields

The sub-fields as a key-value mapping type (Python dict, Java HashMap, etc).

Accessing a sub-field is done via its name in the Data Schema.

Each sub-field will be a Process Result Fields.

Using the response deserialized object from either the polling response or a webhook payload.

from mindee import InferenceResponse

def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields

    object_field = fields["my_object_field"]

    sub_fields: dict = object_field.fields

    # grab a single sub-field
    subfield_1 = sub_fields["subfield_1"]

    # loop over sub-fields
    for field_name, sub_field in sub_fields.items():
        sub_field.value

ListField - List of Fields

Field having an items attribute which is a list of fields. See the items section below.

In addition, the ListField class has a confidence attribute.

Using the response deserialized object from either the polling response or a webhook payload.

from mindee import InferenceResponse

def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields

    my_list_field = fields["my_list_field"]

items

List of fields as a variable-length array type (Python list, Java List, etc).

Each item in the list will be one of:

There will not be a mix of both types in the same list.

List of SimpleField

Using the response deserialized object from either the polling response or a webhook payload.

from mindee import InferenceResponse

def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields

    simple_list_field = fields["my_simple_list_field"]

    # Loop over the list of Simple fields
    for list_item in simple_list_field.items:
        item_value = list_item.value

List of ObjectField

Using the response deserialized object from either the polling response or a webhook payload.

from mindee import InferenceResponse

def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields

    object_list_field = fields["my_object_list_field"]

    # Loop over the list of Object fields
    for object_item in object_list_field.items:
        # grab a single sub-field
        sub_field_value = object_item.fields["sub_field"].value
        
        # loop over sub-fields
        for field_name, sub_field in object_item.fields.items():
            sub_field.value

Optional Field Attributes

These field attributes are only filled when their respective features are activated.

The attributes are always present even when not activated.

confidence

The confidence level of the extracted value.

The data are only filled if the Confidence Scores (for Automation) feature is activated.

The attribute is always present, in case of Confidence Score not activated, it will always be null.

The attribute value will be one of: Certain, High, Medium, Low .

All languages use the appropriate enum type.

Using the response deserialized object from either the polling response or a webhook payload.

from mindee import InferenceResponse
from mindee.parsing.v2.field import FieldConfidence

def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields

    confidence = fields["my_simple_field"].confidence

    # compare using the enum `FieldConfidence`
    is_certain = confidence == FieldConfidence.CERTAIN

locations

A list of the field's locations on the document.

The data are only filled if the Polygons (Bounding Boxes) feature is activated.

It's possible for a single field to have multiple locations, for example when an invoice item spans two pages.

Each location has a page index and a Polygon.

Page indexes are 0-based, so the first page is 0.

A Polygon class contains a list of Points, the specific implementation will depend on the language.

Points are listed in clockwise order, where index 0 is top left.

Point X,Y coordinates are normalized floats from 0.0 to 1.0, relative to the page dimensions.

Using the response deserialized object from either the polling response or a webhook payload.

from mindee import InferenceResponse

def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields
    
    locations = fields["my_simple_field"].locations

    # accessing the polygon
    polygon = locations[0].polygon

    # accessing points: the Polygon class extends List[Point]
    top_x = polygon[0].x

    # alternative syntax:
    # top_x = polygon[0][0]

    # there are geometry functions available in the Polygon class
    center = polygon.centroid

    # accessing the page index on which the polygon is
    page_index = locations[0].page

Last updated

Was this helpful?