Skip to main content

Introduction

This page picks up where Introduction leaves off. There, you created a run and uploaded a document. Here you wait for the agent to finish, read what it extracted, and complete the human review task from code — writing corrected values back exactly the way the Cradl AI app does when a person reviews a document. Use this when you want to feed corrections back at scale, or run the full pipeline without anyone opening the app.

Before you begin

You need an access token (see Introduction), the ID of your agent, and the agent’s validation ID. The validation ID is in the agent’s resourceIds:
Take the entry starting with cradl:validation: — that is the <YOUR-VALIDATION-ID> used in steps 5 and 7.

The flow

1

Create a run

Create a run on your agent. Keep the id from the response — it is on the form <org-id>/<agent-id>/<run-id> and is the agentRunId that every later call needs.
variables is optional. It does not affect predictions — it is passed through and returned with the agent’s output.
2

Create and upload a document

Create a document attached to the run, then upload the file bytes to the fileUrl from the response.Save two more fields from that response: documentId and annotationFileUrl. You need the annotation file URL in steps 4 and 6.
The Python SDK’s create_document performs both the POST /documents call and the file upload for you, and deletes the document again if the upload fails.
3

Wait for the agent to finish

Poll the run until its status is ready-for-review, which means a review task is waiting for input.
Polling is the simplest option, but not the only one. To be notified instead of polling, use a Webhook export, or configure notifications on the validation itself, which can fire when a review task is created or cancelled, or when a run fails.
4

Read what the agent extracted

There are two files to read, and they serve different purposes. Both live on the file server and are fetched with a plain GET and the same Authorization header.The run’s variables file (variablesFileUrl on the run) is the run payload — the same data your export actions receive. Values are either plain values or objects with a value key.The document’s annotation file (annotationFileUrl from step 2) holds the per-field annotations that the review UI edits. This is the file you write back in step 6.
The JavaScript SDK exposes makeFileServerGetRequest and makeFileServerPutRequest for these reads and writes.
5

Create a validation task

Creating the task is what opens the review. input is required — send an empty object unless you have something to put there.
The response contains a taskId on the form cradl:task:xxx and status: "ready".
6

Write the corrected annotations

Correct the annotations you read in step 4 and PUT the whole object back to the document’s annotationFileUrl as JSON. See Annotation file format below for the structure.
7

Complete the task

Finally, patch the task to succeeded. Send the same annotations object as output — the file you wrote in step 6 is the working copy, while output is what the completed task carries.
The task accepts output, metadata, status, name and description on a patch.
To reject a document rather than approve it, cancel the task and say why:

Annotation file format

The annotation file is a JSON object keyed by the field IDs defined in your agent’s model.
  • Every field maps to an array. A single-value field is an array with one element, a multi-value field has one element per value, and a table field is an array of row objects keyed by column ID.
  • Each annotation has up to five keys: value, rawValue, confidence, page and id. null is allowed for all of them, so a hand-written correction can be as short as {"value": "2021-05-01"}.
  • Annotation files produced by the model also carry read-only fields such as location (four normalized numbers describing the bounding box) and source. These are dropped when the file is overwritten, so do not rely on a write preserving them.

Complete example

The code example below has been generated by an AI. Use it as a starting point and verify correctness before using in production.