> ## Documentation Index
> Fetch the complete documentation index at: https://docs.datalab.to/llms.txt
> Use this file to discover all available pages before exploring further.

# Form Fields

> Find the fillable fields on every page of a PDF or image: blank lines, empty boxes, tick boxes and signature blanks, with their types, locations and printed labels.

The form fields API reads a PDF or an image and returns every place a person has to fill something in. Each field comes with its type, its box on the page, the printed label next to it and, when the label does not say enough, a short descriptive name. Use it to inspect a form before you [fill it](https://docs.datalab.to/docs/recipes/form-filling/form-filling-api-overview.md), to build a form from a scan, or to place signature and date blanks.

**Before you begin**, make sure you have:

1. A [Datalab account](https://www.datalab.to/auth/sign_up) with an [API key](https://www.datalab.to/app/keys)
2. Python 3.11+ installed
3. The Datalab SDK: `pip install datalab-python-sdk`
4. Your `DATALAB_API_KEY` environment variable set

To inspect results without writing code, sign in to the
[Form Fields playground](https://www.datalab.to/app/playground/form-fields).
It shows detected field boxes and labels; use Form Filling when you need to write values.

## Quick Start

```python Python SDK theme={null}
from datalab_sdk import DatalabClient

client = DatalabClient()

result = client.form_fields("form.pdf")
if not result.success:
    raise RuntimeError(result.error or "Field detection failed")

for page in result.pages:
    for field in page["fields"]:
        print(page["page"], field["field_type"], field["bbox"], field["label"])
```

```bash cURL theme={null}
curl -X POST https://www.datalab.to/api/v1/form-fields \
  -H "X-API-Key: $DATALAB_API_KEY" \
  -F "file=@form.pdf"

# Poll request_check_url from the response until status is "complete"
```

```python Python (requests) theme={null}
import os
import time
import requests

headers = {"X-API-Key": os.environ["DATALAB_API_KEY"]}
with requests.Session() as session:
    with open("form.pdf", "rb") as file:
        response = session.post(
            "https://www.datalab.to/api/v1/form-fields",
            files={"file": ("form.pdf", file, "application/pdf")},
            headers=headers,
            timeout=60,
        )
    response.raise_for_status()
    check_url = response.json()["request_check_url"]
    for _ in range(300):
        response = session.get(check_url, headers=headers, timeout=30)
        response.raise_for_status()
        data = response.json()
        if data.get("success") is False or data.get("status") == "failed":
            raise RuntimeError(data.get("error") or "Field detection failed")
        if data["status"] == "complete":
            if data.get("result_url"):
                download = session.get(data["result_url"], timeout=60)
                download.raise_for_status()
                data = {
                    **download.json(),
                    **{key: value for key, value in data.items() if value is not None},
                }
            if data.get("success") is False:
                raise RuntimeError(data.get("error") or "Field detection failed")
            break
        time.sleep(2)
    else:
        raise TimeoutError("Detection still processing; keep the request ID")

for page in data["pages"]:
    for field in page["fields"]:
        print(page["page"], field["field_type"], field["bbox"], field["label"])

```

> [!WARNING]
>
> **Rate limits apply.** The rate limit is 25 requests per minute on Free and 400 on Launch and Team (429 on exceed, SDK retries automatically). A separate [page concurrency limit](https://docs.datalab.to/docs/common/limits.md#page-concurrency-limit) of 5,000 concurrent pages is enforced during processing — results return with `success: false` if exceeded. See [API Limits](https://docs.datalab.to/docs/common/limits.md) for details.

## What a field looks like

```json theme={null}
{
  "status": "complete",
  "success": true,
  "page_count": 1,
  "pages": [
    {
      "page": 0,
      "error": "",
      "fields": [
        {"field_type": "name", "bbox": [0.094, 0.143, 0.941, 0.166], "label": "Name of entity/individual", "name": ""},
        {"field_type": "checkbox", "bbox": [0.523, 0.085, 0.534, 0.095], "label": "Individual/sole proprietor", "name": ""},
        {"field_type": "text", "bbox": [0.62, 0.21, 0.94, 0.23], "label": "", "name": "Employer identification number"},
        {"field_type": "signature", "bbox": [0.18, 0.88, 0.62, 0.91], "label": "Signature", "name": ""}
      ]
    }
  ]
}
```

| Field | Description |
| - | - |
| `page` | Page index, starting at 0 |
| `fields[].field_type` | The kind of field. See [field types](#field-types). |
| `fields[].bbox` | `[x0, y0, x1, y1]` as fractions of the page width and height. The origin is the top-left corner of the page. |
| `fields[].label` | The printed label that tells a person what belongs in the field. It is an empty string when the model gives no label. |
| `fields[].name` | A short descriptive name in English, for example `Spouse first name`. It is set mainly for fields whose printed label is empty or unclear, such as a lone `Yes` or `Date`. It is an empty string when the printed label is enough. Use `name` when it is set and `label` otherwise. |
| `error` | Set when the model could not read the page, or repeated itself and its fields may be incomplete |

Fields come in the order the model reads the page. To get pixel coordinates, multiply `x0` and `x1` by the page width and `y0` and `y1` by the page height.

### Field types

`field_type` is one of: `signature`, `initials`, `email`, `name`, `firstName`, `lastName`, `company`, `title`, `date`, `text`, `checkbox`, `radio`.

A field is the empty space a person writes in. The API does not return printed labels, headings or instructions as fields, and it returns no field for a page that has none. A field with no rule or box, such as a blank inside a sentence, still counts.

## Options

| Parameter | Type | Default | Description |
| - | - | - | - |
| `file` / `file_url` | file / string | Required | A PDF or an image. Send one of the two. |
| `page_range` | string | All pages | Pages to process, for example `0,5-10,20`. |
| `max_pages` | integer | None | Process only the first pages. Do not combine it with `page_range`. |
| `skip_cache` | boolean | `false` | Run the detection again instead of returning a cached result. |
| `webhook_url` | string | None | URL that receives a call when the request completes. |
| `processing_location` | string | None | Residency region, for example `eu`, so page images stay in that region. |
| `include_text` | boolean | `false` | Also read the page text and mark each field in it. See [Fields in the page text](#fields-in-the-page-text). |

> [!NOTE]
>
> Spreadsheets are not accepted. Send a PDF or an image.

> [!TIP]
>
> The first request after a period without traffic can take longer than later ones. Pages with many fields also take longer.

## Fields in the page text

Set `include_text=true` to get the text of each page with every field marked where a reader meets it. The API runs fast mode OCR and field detection at the same time, then puts each field into the text.

```python Python SDK theme={null}
from datalab_sdk import DatalabClient, FormFieldsOptions

client = DatalabClient()

result = client.form_fields("form.pdf", options=FormFieldsOptions(include_text=True))

for page in result.pages:
    print(page["text"])
```

```bash cURL theme={null}
curl -X POST https://www.datalab.to/api/v1/form-fields \
  -H "X-API-Key: $DATALAB_API_KEY" \
  -F "file=@form.pdf" \
  -F "include_text=true"
```

```json theme={null}
{
  "status": "complete",
  "success": true,
  "pages": [
    {
      "page": 0,
      "error": "",
      "fields": [{"field_type": "name", "bbox": [0.094, 0.143, 0.941, 0.166], "label": "Name", "name": "Applicant name"}],
      "text": "Name: [name: \"Applicant name\"]\n[ ] Individual/sole proprietor"
    }
  ],
  "json": {"children": [{"id": "/page/0/Text/0", "html": "<p>Name: <input data-field-index=\"0\" data-field-type=\"name\"/></p>"}]},
  "text_error": ""
}
```

| Field | Description |
| - | - |
| `pages[].text` | The page text. A field shows as `[type: "name"]`, with its descriptive name, or its printed label when it has no name. A checkbox shows as `[ ]` and a radio button as `( )`. A label that the line already says is not repeated. |
| `json` | The [fast mode parse JSON](https://docs.datalab.to/docs/recipes/conversion/conversion-api-overview.md) of the document. In each block, the HTML holds an `<input data-field-index data-field-type>` tag for every field in that block. `data-field-index` is the position of the field in `pages[].fields` for that page. |
| `text_error` | Set when the page text could not be read. The fields are still returned. |

The text read adds time to the request. It is billed as a fast mode parse plus form fields. Without `include_text`, a request is billed as form fields only.

## Fill the fields you found

Detection tells you where the fields are. To write values into them, send the same file to the [form filling API](https://docs.datalab.to/docs/recipes/form-filling/form-filling-api-overview.md) with your field data.

## Next Steps

> [card] [Form Fields SDK](https://docs.datalab.to/docs/welcome/sdk/form-fields.md)
>
> Use form\_fields() from the Python SDK and the CLI.

> [card] [Form Filling](https://docs.datalab.to/docs/recipes/form-filling/form-filling-api-overview.md)
>
> Fill the fields with structured data.

> [card] [API Reference](https://documentation.datalab.to/api-reference/health)
>
> See every parameter of the form fields endpoint.

> [card] [Pricing](https://www.datalab.to/pricing)
>
> Per-page pricing for form field detection.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.