# Extract data from a document

> Run an IXP model to extract structured fields from a document and route by confidence for automatic or human review processing.

**What you'll build:** A workflow that takes a document, pulls structured fields from it with an Intelligent eXtraction Platform (IXP) model, and routes by confidence. High-confidence extractions process automatically; anything uncertain goes to a person for review. This is the foundation for any document-driven process: invoices, claims, forms, contracts.

## What you'll need

- A UiPath Automation Cloud account with access to Flow.
- A deployed IXP model in a folder you can access. If you don't have one, [build and deploy a model in IXP](https://docs.uipath.com/ixp/automation-cloud/latest/user-guide/introduction) first. The Extract node has no options until a model is deployed.
- Both **IXP** and **Document Understanding** services enabled on your tenant (Admin → Tenant → Services).

## Nodes used

- [Manual Trigger](node-manual-trigger.md): starts the workflow and supplies the document during testing.
- [Extract](node-extract.md): runs the IXP model and returns the extracted fields.
- [Script](node-script.md): reads specific fields out of the extraction result.
- [Decision](node-decision.md): branches on extraction confidence.
- [Quick Form](node-quick-form.md): routes low-confidence documents to a person.
- [Terminate](node-terminate.md): ends a failure path cleanly.

## Steps

### 1. Create a flow and supply a document

1. Open **Maestro Orchestrate** → **Flow** and select **New Flow**.
2. Add a **Manual Trigger** to the canvas.
3. In the trigger's configuration panel, define an input that holds the document to process (for example, `invoiceFile`). During testing you can attach a sample file to this input.

For production, replace the Manual Trigger with a trigger that delivers the document, for example an email or connector trigger that provides an attachment.

### 2. Add an Extract node

1. Open the node palette and expand **Document processing → Extract**.
2. Select your deployed model. If the category is empty, deploy a model in IXP and reopen the palette.
3. Connect the Extract node to the trigger.
4. In the properties panel, set **Document** to the file from the trigger, for example `$vars.start.output.invoiceFile`.

### 3. Read the fields you need

1. Add a **Script** node after the Extract node.
2. Walk the result and pull the fields by name. Values live in a `Values` array, so read `Values[0].Value`. Compute the minimum confidence across only the fields the model actually returned, skipping missing fields and the `-1.0` sentinel:

   ```javascript
   const fields = $vars.extract1.output?.ExtractionResult?.ResultsDocument?.Fields || [];
   const norm = (s) => String(s || "").toLowerCase().replace(/\s+/g, "");
   const get = (name) => {
     const f = fields.find((x) => norm(x.FieldName) === norm(name));
     return f && f.Values?.[0] ? f.Values[0].Value : undefined;
   };

   const confidences = fields
     .filter((f) => !f.IsMissing && f.FieldType !== "Table")
     .map((f) => f.Values?.[0]?.Confidence)
     .filter((c) => typeof c === "number" && c >= 0);
   const minConfidence = confidences.length ? Math.min(...confidences) : 1;

   return {
     vendor: get("Vendor Name"),
     total: get("Total"),
     minConfidence,
   };
   ```

### 4. Branch on confidence

1. Add a **Decision** node after the Script node.
2. Set the condition to check the lowest confidence, for example `$vars.script1.output.minConfidence >= 0.8`.
3. On the **True branch** (high confidence): connect to the next step in your automation (a system write, a notification, or a downstream node).
4. On the **False branch** (low confidence): connect to the Human node in step 5.

### 5. Send low-confidence documents for review

1. Add a **Human** node on the False branch.
2. Configure a quick form that shows the extracted values and lets the reviewer correct them. Refer to [Add human approval to a workflow](add-human-approval.md) for the form details.
3. Add a **Decision** node after the Human node to branch on the reviewer's `status`, then rejoin the main path with the corrected values.

### 6. Test and debug

Select **Run Debug** (▶) in the bottom toolbar of the canvas. In the execution trace:

- Select the **Extract** node to inspect the returned `ExtractionResult`.
- Confirm the **Script** node pulled the right values. If a field is `undefined`, check the field name against the model's schema (matching is case- and space-insensitive in the snippet above).
- Use **Mock output** on the Extract node to test both branches without calling the model: supply a sample `ExtractionResult` with high, then low, confidence values.

## Result

Your workflow extracts structured fields from the document, routes high-confidence results through the automatic path, and sends low-confidence documents to a human reviewer. You can inspect the extraction result and confidence scores in the execution trace and mock the Extract node to test both branches without calling the model.

## Extend this workflow

- **Process a batch:** wrap the Extract node in a [Loop](node-loop.md) to handle a list of documents.
- **Write results onward:** after the high-confidence branch, add an [HTTP Request](node-http-request.md) or a connector node to push the data into a downstream system.
- **Hand off to an agent:** pass the extracted fields to an [Autonomous Agent](node-agent.md) for classification, summarization, or a drafted response.
