# Azure - AI Document Intelligence

> Execute layout analysis, form understanding, and structured extraction on complex documents using Microsoft Azure AI Document Intelligence (formerly Azure Form Recognizer).

Source: https://docs.sommatic.ai/en/nodes/integrations.microsoft.azure.document-intelligence/

- Slug: `integrations.microsoft.azure.document-intelligence`
- Family: Integrations
- Version: 1.0.0
- Status: Available
- Execution: async

Execute layout analysis, form understanding, and structured extraction on complex documents using Microsoft Azure AI Document Intelligence (formerly Azure Form Recognizer).

Authenticates with your own Azure resource via `connection_id` (api-key credential with `endpoint` metadata); execution costs are billed by Azure to your subscription.

**Operations (prebuilt and custom models):**
- **prebuilt-layout** (default): full page structure — paragraphs, tables, selection marks, reading order.
- **prebuilt-document:** generic key-value and entity extraction across arbitrary forms.
- **prebuilt-invoice:** typed schema for invoice fields (vendor, totals, line items, dates).
- **prebuilt-receipt:** typed schema for retail receipts (merchant, totals, taxes, items).
- **prebuilt-tax.us.w2:** typed schema for U.S. W-2 tax forms.
- **prebuilt-id:** typed schema for government-issued identification documents.
- **prebuilt-healthInsuranceCard.us:** typed schema for U.S. health insurance cards.
- **prebuilt-read:** page-level OCR with handwriting and multi-language support.
- **custom-<id>:** user-trained models for specific document templates.

## Configuration

- `connection_id` (string, required): Connection credential with endpoint + api-key for your Azure AI Document Intelligence resource.
- `model` (string, optional): Azure AI Document Intelligence model identifier. Use a built-in prebuilt model or a custom trained model id (custom-<id>). Default: `prebuilt-layout`. Allowed values: `prebuilt-layout`, `prebuilt-invoice`, `prebuilt-receipt`, `prebuilt-tax.us.w2`, `prebuilt-idDocument`, `prebuilt-healthInsuranceCard.us`, `prebuilt-read`.
- `pages` (string, optional, accepts expressions): Optional page range filter (e.g. "1-3"). Leave empty for all pages.

Its configuration shows the shared execution settings, but this node does not apply retries (`retryOnFail`, `maxTries`) yet. `continueOnFail` is not applied by any node.

## Output ports

- `extracted` (default): Extracted
- `empty`: Empty
- `error`: Error

## Input contract

- `content_base64` (string, optional)
- `file_path` (string, optional)

## Output contract

- `text` (string, optional)
- `chars` (number, optional)
- `empty` (boolean, optional)
- `method` (string, optional)
- `metadata` (object, optional)
- `tables` (array, optional)
- `key_value_pairs` (array, optional)

## In expressions

What a later node can read from this node's output with `$("Azure - AI Document Intelligence").item.json.<path>` (write your node's label instead of `Azure - AI Document Intelligence`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `extracted`, from the output shown in Ports.

- `$("Azure - AI Document Intelligence").item.json.text` (string) = `"INVOICE 2026-0418\nTotal: 129.99 USD"`
- `$("Azure - AI Document Intelligence").item.json.chars` (number) = `35`
- `$("Azure - AI Document Intelligence").item.json.empty` (boolean) = `false`
- `$("Azure - AI Document Intelligence").item.json.method` (string) = `"azure-document-intelligence:prebuilt-layout"`
- `$("Azure - AI Document Intelligence").item.json.metadata` (object) = `{…}`
- `$("Azure - AI Document Intelligence").item.json.tables` (array) = `[…] (1)`
- `$("Azure - AI Document Intelligence").item.json.key_value_pairs` (array) = `[…] (0)`
- `$("Azure - AI Document Intelligence").item.json.metadata.model_id` (string) = `"prebuilt-layout"` (Not suggested by the editor)
- `$("Azure - AI Document Intelligence").item.json.metadata.pages_analyzed` (number) = `1` (Not suggested by the editor)
- `$("Azure - AI Document Intelligence").item.json.metadata.tables_count` (number) = `1` (Not suggested by the editor)
- `$("Azure - AI Document Intelligence").item.json.metadata.key_value_pairs_count` (number) = `0` (Not suggested by the editor)


## How it works

Analyzes a document with Azure AI Document Intelligence using your own resource and returns its text, tables and key-value pairs. Routes to `empty` when no text is found.

1. Resolves the node config. Reads `content_base64` or `file_path` from the config first and then from the incoming item.
2. Requires `connection_id` and one of `content_base64` or `file_path`.
3. Resolves the credential on the server: the secret must contain `apiKey` (or `api_key`) and the endpoint is read from the credential config (`endpoint`) or from the secret.
4. Runs a Python process that calls `begin_analyze_document` with `model` (default `prebuilt-layout`) and the optional `pages` range, and waits for the analysis to finish.
5. Builds `{ text, chars, empty, method, metadata, tables, key_value_pairs }`. Tables become grids of cell text (`rows`) with the page of their first region.
6. Chooses `empty` when the trimmed text is empty, otherwise `extracted`.

## In a workflow

### Node

```json
{
  "node_id": "node-read-invoice",
  "label": "Read invoice",
  "operator_slug": "integrations.microsoft.azure.document-intelligence",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "model": "prebuilt-layout",
    "pages": "1-3"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "text": "INVOICE 2026-0418\nTotal: 129.99 USD",
    "chars": 35,
    "empty": false,
    "method": "azure-document-intelligence:prebuilt-layout",
    "metadata": {
      "model_id": "prebuilt-layout",
      "pages_analyzed": 1,
      "tables_count": 1,
      "key_value_pairs_count": 0
    },
    "tables": [
      {
        "page": 1,
        "rows": [
          [
            "Item",
            "Amount"
          ],
          [
            "Service",
            "129.99"
          ]
        ]
      }
    ],
    "key_value_pairs": []
  },
  "port": "extracted"
}
```

## Output ports (behaviour in the code)

### `extracted`

The analysis returned text.

```json
{
  "text": "INVOICE 2026-0418\nTotal: 129.99 USD",
  "chars": 35,
  "empty": false,
  "method": "azure-document-intelligence:prebuilt-layout",
  "metadata": {
    "model_id": "prebuilt-layout",
    "pages_analyzed": 1,
    "tables_count": 1,
    "key_value_pairs_count": 0
  },
  "tables": [
    {
      "page": 1,
      "rows": [
        [
          "Item",
          "Amount"
        ],
        [
          "Service",
          "129.99"
        ]
      ]
    }
  ],
  "key_value_pairs": []
}
```

### `empty`

The analysis succeeded but found no text (for example a blank or image-only page with a model that does not read it).

```json
{
  "text": "",
  "chars": 0,
  "empty": true,
  "method": "azure-document-intelligence:prebuilt-layout",
  "metadata": {
    "model_id": "prebuilt-layout",
    "pages_analyzed": 1,
    "tables_count": 0,
    "key_value_pairs_count": 0
  },
  "tables": [],
  "key_value_pairs": []
}
```

### `error`

Validation, credential resolution, the Python process or the Azure call failed. Python failures include its `stderr`.

```json
{
  "error": "Python timed out after 300000ms",
  "stderr": ""
}
```

## Behaviour in the code

- `connection_id`: Use an `object` credential whose secret holds `apiKey` and `endpoint` (or put `endpoint` in the credential config).
- `model`: Passed through unchanged, so any model id your resource supports works, including custom models, not only the listed ones.
- `content_base64`: Undeclared in the config schema; normally comes from the incoming item. `file_path` works the same way and wins only when `content_base64` is absent.
- `execution`: Only `timeout_ms` is read (default 300000). The retry settings are not applied.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `connection_id is required.` | `error` | No credential configured. |
| `Either content_base64 or file_path is required.` | `error` | The incoming item carries neither field. Also returned by Python when `file_path` does not exist on the orchestrator. |
| `connection must provide endpoint + apiKey` | `error` | The credential secret is not an object with `apiKey`, or no endpoint is stored. A plain string api-key secret does not work. |
| `Python timed out after <ms>ms` | `error` | The analysis took longer than `execution.timeout_ms` (default 300000). |
| `Failed to resolve connection <connection_id>: <detail>` | `error` | The credential does not exist or the backend could not be reached. |

## Notes and limits

- The first run on a host installs the Python dependencies in a cached virtual environment, which can take minutes.
- `file_path` must exist on the orchestrator's filesystem, for example a file written by `connectors.microsoft.outlook.attachments` in `file` mode.
- Azure usage is billed to your own resource. The worker does not retry.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "integrations.microsoft.azure.document-intelligence",
  "name": "Azure - AI Document Intelligence",
  "category": "integrations",
  "group": [
    {
      "key": "microsoft",
      "name": "Microsoft",
      "icon_url": "/icons/integrations/microsoft/microsoft.svg"
    },
    {
      "key": "foundry",
      "name": "Microsoft Foundry",
      "icon_url": "/icons/integrations/microsoft/foundry.webp"
    }
  ],
  "icon_url": "/icons/integrations/microsoft/microsoft.svg",
  "version": "1.0.0",
  "description": "Execute layout analysis, form understanding, and structured extraction on complex documents using Microsoft Azure AI Document Intelligence (formerly Azure Form Recognizer).\n\n  Authenticates with your own Azure resource via `connection_id` (api-key credential with `endpoint` metadata); execution costs are billed by Azure to your subscription.\n\n  **Operations (prebuilt and custom models):**\n  - **prebuilt-layout** (default): full page structure — paragraphs, tables, selection marks, reading order.\n  - **prebuilt-document:** generic key-value and entity extraction across arbitrary forms.\n  - **prebuilt-invoice:** typed schema for invoice fields (vendor, totals, line items, dates).\n  - **prebuilt-receipt:** typed schema for retail receipts (merchant, totals, taxes, items).\n  - **prebuilt-tax.us.w2:** typed schema for U.S. W-2 tax forms.\n  - **prebuilt-id:** typed schema for government-issued identification documents.\n  - **prebuilt-healthInsuranceCard.us:** typed schema for U.S. health insurance cards.\n  - **prebuilt-read:** page-level OCR with handwriting and multi-language support.\n  - **custom-<id>:** user-trained models for specific document templates.",
  "capabilities": [
    "document-intelligence",
    "ocr",
    "forms",
    "tables",
    "layout",
    "azure",
    "cloud"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "Azure AI Document Intelligence Credential",
        "description": "Connection credential with endpoint + api-key for your Azure AI Document Intelligence resource.",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "api-key",
            "object"
          ],
          "providers": [
            "azure"
          ]
        }
      },
      "model": {
        "type": "string",
        "title": "Model",
        "enum": [
          "prebuilt-layout",
          "prebuilt-invoice",
          "prebuilt-receipt",
          "prebuilt-tax.us.w2",
          "prebuilt-idDocument",
          "prebuilt-healthInsuranceCard.us",
          "prebuilt-read"
        ],
        "default": "prebuilt-layout",
        "description": "Azure AI Document Intelligence model identifier. Use a built-in prebuilt model or a custom trained model id (custom-<id>)."
      },
      "pages": {
        "type": "string",
        "title": "Pages",
        "description": "Optional page range filter (e.g. \"1-3\"). Leave empty for all pages.",
        "format": "expression"
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    },
    "required": [
      "connection_id"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "content_base64": {
        "type": "string"
      },
      "file_path": {
        "type": "string"
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "text": {
        "type": "string"
      },
      "chars": {
        "type": "number"
      },
      "empty": {
        "type": "boolean"
      },
      "method": {
        "type": "string"
      },
      "metadata": {
        "type": "object"
      },
      "tables": {
        "type": "array"
      },
      "key_value_pairs": {
        "type": "array"
      }
    }
  },
  "ports": [
    {
      "port_id": "extracted",
      "label": "Extracted",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "empty",
      "label": "Empty",
      "is_default": false,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard-io",
    "cloud-io"
  ],
  "tags": [
    "azure",
    "document-intelligence",
    "ocr",
    "forms",
    "layout"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://sommatic.ai",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string",
      "title": "Azure AI Document Intelligence Credential",
      "description": "Connection credential with endpoint + api-key for your Azure AI Document Intelligence resource.",
      "ui_widget": "connection_picker",
      "ui_options": {
        "credential_types": [
          "api-key",
          "object"
        ],
        "providers": [
          "azure"
        ]
      }
    },
    "model": {
      "type": "string",
      "title": "Model",
      "enum": [
        "prebuilt-layout",
        "prebuilt-invoice",
        "prebuilt-receipt",
        "prebuilt-tax.us.w2",
        "prebuilt-idDocument",
        "prebuilt-healthInsuranceCard.us",
        "prebuilt-read"
      ],
      "default": "prebuilt-layout",
      "description": "Azure AI Document Intelligence model identifier. Use a built-in prebuilt model or a custom trained model id (custom-<id>)."
    },
    "pages": {
      "type": "string",
      "title": "Pages",
      "description": "Optional page range filter (e.g. \"1-3\"). Leave empty for all pages.",
      "format": "expression"
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  },
  "required": [
    "connection_id"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "content_base64": {
      "type": "string"
    },
    "file_path": {
      "type": "string"
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "text": {
      "type": "string"
    },
    "chars": {
      "type": "number"
    },
    "empty": {
      "type": "boolean"
    },
    "method": {
      "type": "string"
    },
    "metadata": {
      "type": "object"
    },
    "tables": {
      "type": "array"
    },
    "key_value_pairs": {
      "type": "array"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "extracted",
    "label": "Extracted",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "empty",
    "label": "Empty",
    "is_default": false,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "is_default": false,
    "supports_condition": false
  }
]
```
