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

# Validations

> Ensure data quality with validation rules

Validations allow you to enforce rules on extracted data to ensure quality and consistency. TableFlow supports various validation types that can be applied to both template fields and table columns.

Any data that fails validation will be flagged in the review interface, allowing for manual correction before further processing.

## How Validations Work

Validations are defined as an array on template fields or table columns:

```json theme={null}
"validations": [
  {
    "validate": "not_blank",
    "message": "This field is required",
    "severity": "error"
  },
  {
    "validate": "regex",
    "options": "^INV-\\d{4}$",
    "message": "Invoice number must follow format INV-XXXX",
    "severity": "error"
  }
]
```

Each validation has the following properties:

* **validate** (required): The type of validation rule
* **options**: Additional configuration for the validation rule (varies by type)
* **message**: Custom error message to display on validation failure
* **severity**: The severity level of the validation failure ("error", "warn", or "info")

## Validation Types

### Universal Validations

These validations can be applied to any data type.

#### Not Blank

Ensures that the field or cell contains a non-blank value.

```json theme={null}
{
  "validate": "not_blank",
  "message": "This field is required"
}
```

### String Validations

These validations can only be applied to string data types.

#### List

Ensures the value matches one of the items in a predefined list. Comparisons are case-insensitive.

```json theme={null}
{
  "validate": "list",
  "options": ["Small", "Medium", "Large"],
  "message": "Size must be one of the standard options"
}
```

#### Email

Ensures the value is a valid email address.

```json theme={null}
{
  "validate": "email",
  "message": "Please enter a valid email address"
}
```

#### Phone

Ensures the value is a valid phone number.

```json theme={null}
{
  "validate": "phone",
  "message": "Please enter a valid phone number"
}
```

#### Length

Validates the length of text content.

```json theme={null}
{
  "validate": "length",
  "options": {
    "min": 4,
    "max": 16
  },
  "message": "Value must be between 4 and 16 characters"
}
```

You can specify only min or max:

```json theme={null}
{
  "validate": "length",
  "options": {
    "min": 8
  },
  "message": "Value must be at least 8 characters"
}
```

#### Regex

Ensures the value matches a specific regular expression pattern.

```json theme={null}
{
  "validate": "regex",
  "options": "^[A-Za-z0-9-]+$",
  "message": "Only alphanumeric characters and hyphens are allowed"
}
```

### Number Validations

These validations can only be applied to number data types.

#### Range

Validates that the number falls within a specific range.

```json theme={null}
{
  "validate": "range",
  "options": {
    "min": 0,
    "max": 100
  },
  "message": "Value must be between 0 and 100"
}
```

You can specify only min or max:

```json theme={null}
{
  "validate": "range",
  "options": {
    "min": 0
  },
  "message": "Value must be greater than or equal to 0"
}
```

#### Decimal

Validates the number of decimal places.

```json theme={null}
{
  "validate": "decimal",
  "options": {
    "places": 2
  },
  "message": "Value must have exactly 2 decimal places"
}
```

### Date Validations

These validations can only be applied to date data types.

#### Date Range

Validates that a date falls within a specific range.

```json theme={null}
{
  "validate": "date_range",
  "options": {
    "min": "2023-01-01",
    "max": "2023-12-31"
  },
  "message": "Date must be in 2023"
}
```

## Validation Severity Levels

TableFlow supports three severity levels for validations:

* **error**: Prevents extraction data from being used until fixed
* **warning**: Allows data to be used but indicates potential issues
* **info**: Provides informational feedback without blocking

```json theme={null}
{
  "validate": "not_blank",
  "message": "This field is required",
  "severity": "error"
}
```

## Combining Multiple Validations

You can apply multiple validation rules to the same field or column. All validations must pass for the data to be considered valid.

```json theme={null}
"validations": [
  {
    "validate": "not_blank",
    "message": "This field is required"
  },
  {
    "validate": "regex",
    "options": "^[A-Z]\\d{5}$",
    "message": "Product code must start with a capital letter followed by 5 digits"
  }
]
```

## How Validations Affect Extraction

During the document extraction process:

1. Data is extracted from the document based on the template
2. Each extracted value is checked against applicable validations
3. Values that fail validation are flagged for review
4. The review interface highlights validation errors with their messages
5. Users can correct the data before finalizing the extraction

## Example Validation Scenarios

### Invoice Number Validation

```json theme={null}
{
  "name": "Invoice Number",
  "key": "invoice_number",
  "data_type": "string",
  "validations": [
    {
      "validate": "not_blank",
      "message": "Invoice number is required"
    },
    {
      "validate": "regex",
      "options": "^INV-\\d{4}$",
      "message": "Invoice number must follow format INV-XXXX"
    }
  ]
}
```

### Amount Validation

```json theme={null}
{
  "name": "Total Amount",
  "key": "total_amount",
  "data_type": "number",
  "validations": [
    {
      "validate": "not_blank",
      "message": "Total amount is required"
    },
    {
      "validate": "range",
      "options": {
        "min": 0
      },
      "message": "Total amount must be positive"
    },
    {
      "validate": "decimal",
      "options": {
        "places": 2
      },
      "message": "Total amount must have exactly 2 decimal places"
    }
  ]
}
```

## Best Practices

For optimal validation results:

1. **Start Simple** - Begin with basic validations and add complexity as needed
2. **Use Clear Messages** - Write clear, descriptive validation messages
3. **Combine Validations** - Use multiple validation types for complex rules
4. **Set Appropriate Severity** - Use error for critical validations, warnings for less critical issues
5. **Test Thoroughly** - Verify validations work with real-world documents

## Next Steps

Learn how to use [webhooks](/webhooks) to integrate extracted data with your application.
