# Extraction Result

{% hint style="info" %}
**This is reference documentation.**

Code samples shown are only examples, and will not work as-is.\
You'll need to copy-paste and modify according to your requirements.

Looking full code samples?

\ <button type="button" class="button primary" data-action="ask" data-query="Write me a code sample for sending a file to my model, but ask for my model type (listing available types), model ID, and  language first" data-icon="gitbook-assistant">Ask our documentation AI to write code samples</button><br>

You can also use the "Ask" button at the top of any page in the documentation.
{% endhint %}

You'll need to have a response object as described in the [Response Processing](/integrations/client-libraries-sdk/process-the-response.md) section.

## Accessing Data Schema Fields

Fields are completely dynamic and depend on your model's [Data Schema Overview](/extraction-models/data-schema.md).

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](#value "mention") section below.

In addition, the `Simplefield` class has [#confidence](#confidence "mention") and [#locations](#locations "mention") attributes.

{% tabs %}
{% tab title="Python" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```python
from mindee import InferenceResponse

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

    my_simple_field = fields["my_simple_field"]
```

{% endtab %}

{% tab title="Node.js" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```javascript
handleResponse(response) {
  const fields = response.inference.result.fields;

  const simpleField = fields.getSimpleField("my_simple_field");
}
```

{% endtab %}

{% tab title="PHP" %}
Using the `$response` deserialized object from either the polling response or a webhook payload.

```php
use Mindee\Parsing\V2\InferenceResponse;

public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;

    $simpleField = $fields->getSimpleField('my_simple_field');
}
```

{% endtab %}

{% tab title="Ruby" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```ruby
def handle_response(response)
  fields = response.inference.result.fields

  simple_field = fields.get_simple_field('my_simple_field')
end
```

{% endtab %}

{% tab title="Java" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```java
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.SimpleField;

public void handleResponse(InferenceResponse response) {
  var fields = response.getInference().getResult().getFields();

  SimpleField simpleField = fields.getSimpleField("my_simple_field");
}
```

{% endtab %}

{% tab title=".NET" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```csharp
using Mindee.V2.Product.Extraction;
using Mindee.V2.Parsing.Inference.Field;

public void HandleResponse(ExtractionResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;

    SimpleField mySimpleField = fields["my_simple_field"].SimpleField;
}
```

{% endtab %}
{% endtabs %}

### `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.

{% tabs %}
{% tab title="Python" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```python
from mindee import InferenceResponse

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

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

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

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

  # booleans
  bool_field_value: bool | None = fields["bool_field"].value
```

{% endtab %}

{% tab title="Node.js" %}
The `value` attribute is an `Object` type under the hood.

You should use the explicitly-typed accessors, this is recommended for clarity.\
Take a look at your Data Schema to know which typed accessor to use.

```typescript
handleResponse(response) {
  const fields = response.inference.result.fields;
  
  // texts, dates, classifications ...
  const stringFieldValue = fields.getSimpleField("string_field").stringValue;
  
  // no distinction between floats and integers
  const floatFieldValue = fields.getSimpleField("float_field").numberValue;
  const intFieldValue = fields.getSimpleField("int_field").numberValue;
  
  // booleans
  const boolFieldValue = fields.getSimpleField("bool_field").booleanValue;
}
```

If the wrong accessor type is used, an exception will be thrown, something like this:

```
"Value is not a number"
```

{% endtab %}

{% tab title="PHP" %}
Using the `$response` deserialized object from either the polling response or a webhook payload.

```php
use Mindee\Parsing\V2\InferenceResponse;

public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;

    // texts, dates, classifications ...
    $stringFieldValue = $fields->getSimpleField('string_field')->value;

    // a JSON float will be a float
    $floatFieldValue = $fields->getSimpleField('float_field')->value;

    // even if the API always returns an integer, the type will be float
    $intFieldValue = $fields->getSimpleField('int_field')->value;

    // booleans
    $boolFieldValue = $fields->getSimpleField('bool_field')->value;
}
```

{% endtab %}

{% tab title="Ruby" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```ruby
def handle_response(response)
  fields = response.inference.result.fields

  # texts, dates, classifications ...
  string_field_value = fields.get_simple_field('string_field').value

  # a JSON float will be a float
  float_field_value = fields.get_simple_field('float_field').value

  # even if the API always returns an integer, the type will be float
  int_field_value = fields.get_simple_field('int_field').value

  # booleans
  bool_field_value = fields.get_simple_field('bool_field').value
end
```

{% endtab %}

{% tab title="Java" %}
The `value` attribute is an `Object` type under the hood.

You'll need to explicitly declare the type, otherwise the code will likely not compile.\
Take a look at your Data Schema to know which type to declare.

```java
import com.mindee.parsing.v2.InferenceResponse;

public void handleResponse(InferenceResponse response) {
  var fields = response.getInference().getResult().getFields();

  // texts, dates, classifications ...
  String stringFieldValue = fields.getSimpleField("string_field")
        .getStringValue();

  // a JSON float will be a Double
  Double floatFieldValue = fields.getSimpleField("float_field")
      .getDoubleValue();

  // even if the API always returns an integer, the type will be Double
  Double intFieldValue = fields.getSimpleField("int_field")
      .getDoubleValue();

  // booleans
  Boolean boolFieldValue = fields.getSimpleField("bool_field")
      .getBooleanValue();
}
```

If the wrong type method is used, an exception will be thrown, something like this:

```
ClassCast class java.lang.String cannot be cast to class java.lang.Double
```

{% endtab %}

{% tab title=".NET" %}
The `Value` attribute is a `dynamic` type under the hood.

You should explicitly declare the type, this is recommended for clarity.\
Take a look at your Data Schema to know which type to declare.

```csharp
using Mindee.V2.Parsing.Inference.Field;

public void HandleResponse(ExtractionResponse response)
{
    // texts, dates, classifications ...
    string stringFieldValue = fields["string_field"].SimpleField.Value;

    // a JSON float will be a Double
    Double floatFieldValue = fields["float_field"].SimpleField.Value;

    // even if the API always returns an integer, the type will be Double
    Double intFieldValue = fields["int_field"].SimpleField.Value;

    // booleans
    Boolean boolFieldValue = fields["bool_field"].SimpleField.Value;
}
```

If the wrong type is declared, an exception will be raised, something like this:

```
RuntimeBinderException : Cannot implicitly convert type 'string' to 'double'
```

{% endtab %}
{% endtabs %}

## `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](#fields "mention") section below.

In addition, the `ObjectField` class has [#confidence](#confidence "mention") and [#locations](#locations "mention") attributes.

{% tabs %}
{% tab title="Python" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```python
from mindee import InferenceResponse

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

    object_field = fields["my_object_field"]
```

{% endtab %}

{% tab title="Node.js" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```javascript
handleResponse(response) {
  const fields = response.inference.result.fields;

  const objectField = fields.getObjectField("my_object_field");
}
```

{% endtab %}

{% tab title="PHP" %}
Using the `$response` deserialized object from either the polling response or a webhook payload.

```php
use Mindee\Parsing\V2\InferenceResponse;

public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;

    $objectField = $fields->getObjectField('my_object_field');
}
```

{% endtab %}

{% tab title="Java" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```java
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.ObjectField;

public void handleResponse(InferenceResponse response) {
  var fields = response.getInference().getResult().getFields();

  ObjectField objectField = fields.getObjectField("my_object_field");
}
```

{% endtab %}

{% tab title=".NET" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```csharp
using Mindee.V2.Parsing.Inference.Field;

public void HandleResponse(ExtractionResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;

    ObjectField myObjectField = fields["my_object_field"].ObjectField;
}
```

{% endtab %}
{% endtabs %}

### `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 [#single-value-field-simplefield](#single-value-field-simplefield "mention")or a [#listfield-list-of-fields](#listfield-list-of-fields "mention").

{% tabs %}
{% tab title="Python" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```python
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
```

{% endtab %}

{% tab title="Node.js" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```javascript
handleResponse(response) {
  const fields = response.inference.result.fields;

  const objectField = fields.getObjectField("my_object_field");

  const simpleSubFields = objectField.simpleFields;

  // grab a single sub-field
  const subfield1 = subFields.get("subfield_1");

  // loop over simple sub-fields
  subFields.forEach((simpleSubFields, fieldName) => {
    // Choose the appropriate accessor:
    // stringValue, numberValue, booleanValue
    const fieldValue = subField.stringValue;
  });

  // Object fields can also have lists:
  const listSubFields = objectField.listFields;
}
```

{% endtab %}

{% tab title="PHP" %}
Using the `$response` deserialized object from either the polling response or a webhook payload.

```php
use Mindee\Parsing\V2\InferenceResponse;

public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;

    $objectField = $fields->getObjectField('my_object_field');
    $subFields = $objectField->fields;

    // grab a single sub-field
    $subfield1 = $subFields->getSimpleField('subfield_1');

    // loop over sub-fields
    foreach ($subFields as $fieldName => $subField) {
        $fieldValue = $subField->value;
    }
}
```

{% endtab %}

{% tab title="Ruby" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```ruby
def handle_response(response)
  fields = response.inference.result.fields

  object_field = fields.get_object_field('my_object_field')
  sub_fields = object_field.fields
  
  # grab a single sub-field
  sub_field_value = sub_fields.get_simple_field('sub_field').value
  
  # loop over sub-fields
  sub_fields.each_value do |sub_field|
    field_value = sub_field.value
  end
end
```

{% endtab %}

{% tab title="Java" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```java
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.ListField;
import com.mindee.parsing.v2.field.ObjectField;
import com.mindee.parsing.v2.field.SimpleField;

public void handleResponse(InferenceResponse response) {
  var fields = response.getInference().getResult().getFields();

  ObjectField objectField = fields.getObjectField("my_object_field");

  HashMap<String, SimpleField> subFields = objectField.getSimpleFields();

  // grab a single sub-field
  SimpleField subfield1 = subFields.get("subfield_1");

  // loop over sub-fields
  for (Map.Entry<String, SimpleField> entry : subFields.entrySet()) {
    String fieldName = entry.getKey();
    SimpleField subField = entry.getValue();
    
    // Choose the appropriate value type accessor method:
    // String, Double, Boolean
    String fieldValue = subField.getStringValue();
  }
}
```

{% endtab %}

{% tab title=".NET" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```csharp
using Mindee.V2.Parsing.Inference.Field;

public void HandleResponse(ExtractionResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;

    ObjectField objectField = fields["my_object_field"].ObjectField;

    Dictionary<string, SimpleField> subFields = objectField.SimpleFields;

    // grab a single sub-field
    SimpleField subField1 = subFields["subfield_1"];

    // loop over sub-fields
    // Note: in C#14, 'field' is a reserved keyword, hence use of 'entry'.
    foreach (KeyValuePair<string, SimpleField> entry in subFields)
    {
        string fieldName = entry.Key;
        SimpleField subField = entry.Value;
        
        // process the SimpleField ...
    }
}
```

{% endtab %}
{% endtabs %}

## `ListField` - List of Fields

Field having an `items` attribute which is a list of fields.\
See the [#items](#items "mention") section below.

In addition, the `ListField` class has a [#confidence](#confidence "mention") attribute.

{% tabs %}
{% tab title="Python" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```python
from mindee import InferenceResponse

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

    my_list_field = fields["my_list_field"]
```

{% endtab %}

{% tab title="Node.js" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```javascript
handleResponse(response) {
  const fields = response.inference.result.fields;

  const listField = fields.getListField("my_list_field");
}
```

{% endtab %}

{% tab title="PHP" %}
Using the `$response` deserialized object from either the polling response or a webhook payload.

```php
use Mindee\Parsing\V2\InferenceResponse;

public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;
    
    $listField = $fields->getListField('my_list_field');
}
```

{% endtab %}

{% tab title="Java" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```java
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.ListField;

public void handleResponse(InferenceResponse response) {
  var fields = response.getInference().getResult().getFields();

  ListField listField = fields.getListField("my_list_field");
}
```

{% endtab %}

{% tab title=".NET" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```csharp
using Mindee.V2.Parsing.Inference.Field;

public void HandleResponse(ExtractionResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;

    ListField myListField = fields["my_list_field"].ListField;
}
```

{% endtab %}
{% endtabs %}

### `items`

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

Each item in the list will be one of:

* [#simplefield-single-value-field](#simplefield-single-value-field "mention")
* [#objectfield-nested-object-field](#objectfield-nested-object-field "mention")

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

#### List of `SimpleField`

{% tabs %}
{% tab title="Python" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```python
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
```

{% endtab %}

{% tab title="Node.js" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```javascript
handleResponse(response) {
  const fields = response.inference.result.fields;

  const simpleListField = fields.getListField("my_simple_list_field");

  const simpleItems = simpleListField.simpleItems;

  // Loop over the list of Simple fields
  for (const itemField of simpleItems) {
    // Choose the appropriate accessor:
    // stringValue, numberValue, booleanValue
    const fieldValue = itemField.stringValue;
  }
}
```

{% endtab %}

{% tab title="PHP" %}
Using the `$response` deserialized object from either the polling response or a webhook payload.

```php
use Mindee\Parsing\V2\InferenceResponse;

public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;

    $simpleListField = $fields->getListField('my_simple_list_field');

    // access a value at a given position
    $fieldFirstValue = $simpleListField->items[0]->value;

    // Loop over the list of Simple fields
    foreach ($simpleListField->items as $listItem) {
        $itemValue = $listItem->value;
    }
}
```

{% endtab %}

{% tab title="Ruby" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```ruby
def handle_response(response)
  fields = response.inference.result.fields
  
  my_list_field = fields.get_list_field('my_simple_list_field')

  # access a value at a given position
  simple_list_field = my_list_field.simple_items[0].value

  # Loop over the list of Simple fields
  simple_list_field.simple_items.each do |list_item|
    item_value = list_item.value
  end
end
```

{% endtab %}

{% tab title="Java" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```java
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.ListField;
import com.mindee.parsing.v2.field.SimpleField;

public void handleResponse(InferenceResponse response) {
  var fields = response.getInference().getResult().getFields();

  ListField simpleListField = fields.getListField("my_simple_list_field");

  List<SimpleField> simpleItems = simpleListField.getSimpleItems();

  // Loop over the list of Simple fields
  for (SimpleField itemField : simpleItems) {
    // Choose the appropriate value type accessor method:
    // String, Double, Boolean
    String fieldValue = itemField.getStringValue();
  }
}
```

{% endtab %}

{% tab title=".NET" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```csharp
using Mindee.V2.Parsing.Inference.Field;

public void HandleResponse(ExtractionResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;

    ListField simpleListField = fields["my_simple_list_field"].ListField;

    List<SimpleField> simpleItems = simpleListField.SimpleItems;

    // Loop over the list of Simple fields
    foreach (SimpleField itemField in simpleItems)
    {
        // Choose the appropriate value type:
        // string, Double, Boolean
        string fieldValue = itemField.Value;
    }
}
```

{% endtab %}
{% endtabs %}

#### List of `ObjectField`

{% tabs %}
{% tab title="Python" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```python
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
```

{% endtab %}

{% tab title="Node.js" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```javascript
handleResponse(response) {
  const fields = response.inference.result.fields;

  const fieldObjectList = fields.getListField("my_object_list_field");

  const objectItems = fieldSimpleList.objectItems;

  // Loop over the list of Object fields
  for (const itemField of objectItems) {
    const simpleSubFields = itemField.simpleFields;

    // grab a single sub-field
    const subField1 = subFields.get("subfield_1");

    // Choose the appropriate accessor:
    // stringValue, numberValue, booleanValue
    const subFieldValue = subField1.stringValue;

    // loop over simple sub-fields
    simpleSubFields.forEach((subField, fieldName) => {
      // Choose the appropriate accessor:
      // stringValue, numberValue, booleanValue
      const fieldValue = subField.stringValue;
    });

    // Object fields can also have lists:
    const listSubFields = itemField.listFields;
  }
}
```

{% endtab %}

{% tab title="PHP" %}
Using the `$response` deserialized object from either the polling response or a webhook payload.

```php
use Mindee\Parsing\V2\InferenceResponse;

public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;
    $fieldObjectList = $fields->getObjectField('my_object_list_field');

    // access an object at a given position
    $objectItem0 = $fieldObjectList->items[0];
    $subField0Value = $objectItem0->fields->get('sub_field')->value;

    // Loop over the list of Object fields
    foreach ($myObjectListField->items as $objectItem) {
        $subFieldValue = $objectItem->fields->get('sub_field')->value;
    }
}
```

{% endtab %}

{% tab title="Ruby" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```ruby
def handle_response(response)
  fields = response.inference.result.fields
  
  object_list_field = fields.get_list_field('my_object_list_field')

  # access an object at a given position
  object_item_0 = object_list_field.items[0]
  sub_field_0_value = object_item_0.fields.get('sub_field').value

  # Loop over the list of Object fields
  object_list_field.fields.each do |object_item|
    sub_field_value = object_item.fields.get('sub_field').value
  end
end
```

{% endtab %}

{% tab title="Java" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```java
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.ListField;
import com.mindee.parsing.v2.field.ObjectField;
import com.mindee.parsing.v2.field.SimpleField;

public void handleResponse(InferenceResponse response) {
  var fields = response.getInference().getResult().getFields();

  ListField fieldObjectList = fields.getListField("my_object_list_field");

  List<ObjectField> objectItems = listField.getObjectItems();

  // Loop over the list of Object fields
  for (ObjectField itemField : objectItems) {

    // Object sub-fields will always be Simple fields
    HashMap<String, SimpleField> subFields = itemField.getSimpleFields();

    // grab a single sub-field
    SimpleField subfield1 = subFields.get("subfield_1");
    
    // Choose the appropriate value type accessor method:
    // String, Double, Boolean
    String subFieldValue = subfield1.getStringValue();

    // loop over sub-fields
    for (Map.Entry<String, SimpleField> entry : subFields.entrySet()) {
      String fieldName = entry.getKey();
      SimpleField subField = entry.getValue();
    }
  }
}
```

{% endtab %}

{% tab title=".NET" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```csharp
using Mindee.V2.Parsing.Inference.Field;

public void HandleResponse(ExtractionResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;

    ListField fieldObjectList = fields["my_simple_list_field"].ListField;

    List<ObjectField> objectItems = fieldObjectList.ObjectItems;

    // Loop over the list of Object fields
    foreach (ObjectField itemField in objectItems)
    {
        Dictionary<string, SimpleField> subFields = objectField.SimpleFields;
    
        // grab a single sub-field
        SimpleField subField1 = subFields["subfield_1"];
        
        // Choose the appropriate value type:
        // string, Double, Boolean
        string subFieldValue = subField1.Value;
    
        // loop over sub-fields
        // Note: in C#14, 'field' is a reserved keyword, hence use of 'entry'.
        foreach (KeyValuePair<string, SimpleField> entry in subFields)
        {
            string fieldName = entry.Key;
            SimpleField subField = entry.Value;
        }
    }
}
```

{% endtab %}
{% endtabs %}

## 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 Score and Accuracy Boost](/extraction-models/optional-features/automation-confidence-score.md) feature is activated.

The instance property is always present, however if the feature is not activated, it will always be empty (the exact type depends on language used: `null`, `undefined`, `None`, etc)

The attribute value will be a one of: `Certain`, `High`, `Medium`, `Low` .\
The language-appropriate enum type will be available for your convenience, mapped from a string value.

{% tabs %}
{% tab title="Python" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```python
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
    is_lte_medium = confidence <= FieldConfidence.MEDIUM
    is_gte_low = confidence >= FieldConfidence.LOW
```

{% endtab %}

{% tab title="Node.js" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```javascript
handleResponse(response) {
  const fields = response.inference.result.fields;

  const confidence = fields.getSimpleField("my_simple_field")?.confidence

  // compare using the enum `FieldConfidence`
  const isCertain = confidence === FieldConfidence.Certain;
  const isLteMedium = FieldConfidence.lessThanOrEqual(
    confidence, FieldConfidence.Medium
  );
  const isGteLow = FieldConfidence.greaterThanOrEqual(
    confidence, FieldConfidence.Low
  );
}
```

{% endtab %}

{% tab title="PHP" %}
Using the `$response` deserialized object from either the polling response or a webhook payload.

```php
use Mindee\Parsing\V2\InferenceResponse;
use Mindee\Parsing\V2\Field\FieldConfidence;

public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;

    $confidence = $fields->get('my_simple_field')->confidence;

    // compare using the enum `FieldConfidence`
    $isCertain = $confidence === FieldConfidence::Certain;
    $isLteMedium = $confidence->lessThanOrEqual(FieldConfidence::Medium);
    $isGteLow = $confidence->greaterThanOrEqual(FieldConfidence::Low);
}
```

{% endtab %}

{% tab title="Ruby" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```ruby
def handle_response(response)
  fields = response.inference.result.fields

  confidence = fields["my_simple_field"].confidence

  # compare using the class `FieldConfidence`
  FieldConfidence = Mindee::Parsing::V2::Field::FieldConfidence
  
  is_certain = confidence == FieldConfidence.CERTAIN
  is_lte_medium = confidence <= FieldConfidence.MEDIUM
  is_gte_low = confidence >= FieldConfidence.LOW
end
```

{% endtab %}

{% tab title="Java" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```java
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.FieldConfidence;

public void handleResponse(InferenceResponse response) {
  var fields = response.getInference().getResult().getFields();

  // choose the appropriate field type accessor method: Simple, Object, List
  FieldConfidence confidence = fields.getSimpleField("my_simple_field")
      .getConfidence();

  // compare using the enum `FieldConfidence`
  boolean isCertain = confidence === FieldConfidence.Certain;
  boolean isLteMedium = confidence.lessThanOrEqual(FieldConfidence.Medium);
  boolean isGteLow = confidence.greaterThanOrEqual(FieldConfidence.Low);
}
```

{% endtab %}

{% tab title=".NET" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```csharp
using Mindee.V2.Parsing.Inference.Field;

public void HandleResponse(ExtractionResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;

    // nullable enum since presence depends on feature activation
    FieldConfidence? confidence = fields["my_simple_field"]
        .SimpleField.Confidence;

    // compare using the enum `FieldConfidence`
    bool isCertain = confidence == FieldConfidence.Certain;
    // cast to int for relative inequalities
    bool isLteMedium = (int?)confidence <= (int)FieldConfidence.Medium;
    bool isGteLow = (int?)confidence >= (int)FieldConfidence.Low;
}
```

{% endtab %}
{% endtabs %}

### `locations`

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

The data are only filled if the [Polygons (Bounding Boxes)](/extraction-models/optional-features/polygons-bounding-boxes.md) 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.

{% tabs %}
{% tab title="Python" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```python
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, since the Point class extends List<float>
    # 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
```

{% endtab %}

{% tab title="Node.js" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```javascript
handleResponse(response) {
  const fields = response.inference.result.fields;

  const locations = fields.getSimpleField("my_simple_field")?.locations;

  // accessing the polygon
  const polygon = locations![0].polygon!;

  // accessing points: the Polygon class extends Array<Point>
  const topX = polygon[0][0];

  // there are geometry functions available in the Polygon class
  const center = polygon.getCentroid();

  // accessing the page index on which the polygon is
  const pageIndex = locations![0].page!;
}
```

{% endtab %}

{% tab title="PHP" %}
Using the `$response` deserialized object from either the polling response or a webhook payload.

```php
use Mindee\Parsing\V2\InferenceResponse;
use Mindee\Parsing\V2\Field\FieldConfidence;

public function handleResponse(InferenceResponse $response)
{
    $fields = $response->inference->result->fields;

    $locations = $fields->get('my_simple_field')->locations;

    // accessing the polygon
    $polygon = $locations[0]->polygon;
    
    // accessing points:
    $points = $polygon->coordinates;
    $topX = $points[0]->getX();
    // alternative syntax, since the Point class extends Array<float>
    // $topX = $points[0][0]

    // there are geometry functions available in the Polygon class
    $center = $polygon->getCentroid();
    
    // accessing the page index on which the polygon is
    $pageIndex = $locations[0]->page;
}
```

{% endtab %}

{% tab title="Ruby" %}
Using the `$response` deserialized object from either the polling response or a webhook payload.

```ruby
def handle_response(response)
  fields = response.inference.result.fields

  locations = fields.get_simple_field('my_simple_field').locations

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

  # accessing points:
  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
end
```

{% endtab %}

{% tab title="Java" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```java
import com.mindee.geometry.Point;
import com.mindee.geometry.Polygon;
import com.mindee.parsing.v2.InferenceResponse;
import com.mindee.parsing.v2.field.FieldLocation;
import java.util.List;

public void handleResponse(InferenceResponse response) {
  var fields = response.getInference().getResult().getFields();

  // choose the appropriate field type accessor method: Simple, Object
  List<FieldLocation> locations = fields.getSimpleField("my_simple_field")
      .getLocations();
  
  // accessing the polygon
  Polygon polygon = locations.get(0).getPolygon();

  // accessing points
  List<Point> points = polygon.getCoordinates();
  double topX = points.get(0).getX();

  // there are geometry functions available in the Polygon class
  Point center = polygon.getCentroid();

  // accessing the page index on which the polygon is
  int pageIndex = locations.get(0).getPage();
}
```

{% endtab %}

{% tab title=".NET" %}
Using the `response` deserialized object from either the polling response or a webhook payload.

```csharp
using Mindee.V2.Parsing.Inference.Field;
using Mindee.Geometry;

public void HandleResponse(ExtractionResponse response)
{
    InferenceFields fields = response.Inference.Result.Fields;

    List<FieldLocation> locations = fields["my_simple_field"]
        .SimpleField.Locations;

    // accessing the polygon
    Polygon polygon = locations.First().Polygon;

    // accessing points: the Polygon class extends List<Point>
    double topX = polygon[0].X;

    // alternative notation, since the Point class extends List<double>
    // double topX = polygon[0][0];

    // there are geometry functions available in the Polygon class
    Point center = polygon.GetCentroid();

    // accessing the page index on which the polygon is
    int pageIndex = locations.First().Page;
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mindee.com/extraction-models/sdk-integration/extraction-result.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
