# Real-time validation

### How it works

![](https://2266347786-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFTZ3y4gwn_iaPw5B8H%2F-MFTbmdAF7vGiCvCCyHl%2F-MFTeFcS6w-_gZU3YfDA%2Fimage.png?alt=media\&token=de4680ed-9d50-43f2-813a-01a567e299e3)

## Getting started

To upload documents under the conditional validation workflow, a few changes to the standard `fileupload` form-data parameters are required:

* Specify the validation workflow type by setting: `workflowId=validate`
* Specify the `fieldSet` or `fieldSets` parameter to predict against
* Configure the `workflowOptions` according to the required validation rules

{% hint style="info" %}
Validation workflows are a `BETA` feature and subject to change.\
This guide is under-construction.
{% endhint %}

![Sample Postman configuration for a file-upload with the validate workflow](https://2266347786-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFTZ3y4gwn_iaPw5B8H%2F-MFdUtslKL4FkHDfV9KG%2F-MFdZtz4w5iXQqg06tbE%2Fimage.png?alt=media\&token=aabcff21-f509-434c-b139-a27618b675d3)

#### Validation Parameters

Workflow options are strings which contain a JSON-formatted object that controls how the steps in the validation workflow are executed. Here's a sample `workflowOptions` string which validates the confidence of the `bpay.crn` field:

```javascript
{
   "prediction":{
      "fieldset": "sypht.bpay",
      "conditions":[
         {
            "type": "field-confidence-range",
            "field": "bpay.crn",
            "min": 0.5
         }
      ],
      "createTask":{
         "submit": true,
         "priority": 1
      }
   }
}
```

For the sample above, extractions which include a `bpay.crn` with confidence less than `0.5` will produce a validation task for the `sypht.bpay` specification.

{% hint style="info" %}
&#x20;The `fieldset` specified to validate in the `workflowOptions` should be contained in the `fieldSets` requested to predict against on the base `/fileupload/` request
{% endhint %}

The full set of validation conditions includes:

* `field-confidence-range`
  * Validates whether a given field's prediction condidence value falls within an expected range.
  * Predictions with values outside the allowed range will trigger validation of the field.
  * Typically used to identify and review low confidence predictions.
  * **Required**
    * `field` - Id of the field to validate
  * **Options**
    * `min` - The minimum value for the predicted field confidence
      * Inclusive
      * Default = `null` for no minimum
    * `max` - The maximum value for the predicted field confidence
      * Inclusive
      * Default = `null` for no maximum
* `field-value-range`
  * Validates whether a given field's normalised value falls within an expected range.
  * Predictions with values outside the allowed range will trigger validation of the field.
  * **Required**
    * `field` - Id of the field to validate
  * **Options**
    * `min` - The minimum value for the predicted field confidence
      * Inclusive
      * Default = `null` for no minimum
    * `max` - The maximum value for the predicted field confidence
      * Inclusive
      * Default = `null` for no maximum
* `field-present`
  * Verifies the presence of a value for a field on a document.
  * Documents missing values for this field will trigger validation of the field.
  * **Required**
    * `field` - Id of the field to validate

{% code title="Response" %}

```bash
{
    "fileId": "815c63f6-6152-467c-9182-f07223d057cb",
    "uploadedAt": "2020-08-20T03:19:07.319Z",
    "status": "RECEIVED"
}
```

{% endcode %}

#### Tasks

<https://app.sypht.com/tasks>

![](https://2266347786-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFTZ3y4gwn_iaPw5B8H%2F-MFTbmdAF7vGiCvCCyHl%2F-MFTdkntVkwhJAXxPnbt%2Fimage.png?alt=media\&token=ccf013dd-28ad-4c0f-aedb-374d4475a0a6)

#### Collecting results

While tasks are in progress, the results endpoint will block requests for up-to 30 seconds and return an `IN PROGRESS` status.

```javascript
GET https://api.sypht.com/result/final/815c63f6-6152-467c-9182-f07223d057cb

Response
{
    "fileId": "1111111-6152-467c-9182-f07223d057cb",
    "status": "IN PROGRESS"
}

```

One complete, results will be returned normally.

```javascript
Response (once prediction/ is complete)
{
    "fileId": "1111111-6152-467c-9182-f07223d057cb",
    "status": "FINALISED",
    "results": {
        "timestamp": "2020-08-20T03:30:09.703Z",
        "fields": [
            {
                "name": "vehicle.odometerKm",
                "value": "148500",
                "confidence": 0.9958282699555642,
                ...
            },
            ...
        ]
    }
}
```
