# Validation Rules

### Overview&#x20;

Validation Rules allow you to set up quality control checks on extracted document data. When a document is processed, Docspire automatically evaluates the extracted fields against your defined rules and takes appropriate action when validation fails.&#x20;

This feature helps ensure data accuracy, enforce business policies, and route documents requiring attention to the appropriate team members for review.&#x20;

### Common Use Cases&#x20;

* **Required field checks** – Ensure critical fields like vendor name or invoice number are not empty&#x20;
* **Amount thresholds** – Flag invoices or expenses exceeding approval limits for manager review&#x20;
* **Calculation verification** – Verify that line totals match quantity multiplied by unit price&#x20;
* **Date validation** – Check that document dates are within acceptable ranges and in correct format&#x20;
* **ID verification** – Validate that ID documents are not expired&#x20;
* **Compliance checks** – Enforce business rules specific to your industry or organization&#x20;

### Accessing Validation Rules&#x20;

1. Navigate to **Automation > Validation Rules** in the left sidebar.&#x20;
2. The Validation Rules page displays two sections: the rule creation form at the top and the Current Validation Rules table below.&#x20;

<figure><img src="https://3990462849-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fgjpo1gyiI3QKDSNO9maQ%2Fuploads%2FSn1oPapjKCP8xIvx27Fl%2F1%20-%20validation%20page.png?alt=media&#x26;token=a3d82e3a-d61b-4db3-8905-2a489d35e7f0" alt=""><figcaption></figcaption></figure>

### Understanding the Interface&#x20;

#### Current Validation Rules Table&#x20;

The table displays all configured validation rules with the following columns:&#x20;

| **Column**        | **Description**                                                       |
| ----------------- | --------------------------------------------------------------------- |
| Rule Name         | The name you assigned to the rule                                     |
| Document/Workflow | Shows "Document" or "Workflow" based on rule type                     |
| Type              | The document type the rule applies to (Invoice, Purchase Order, etc.) |
| Action            | What happens on failure: "Flag for Review" or "Error"                 |
| Applied To        | The field being validated (shown as a purple badge)                   |
| Assignee          | The team member assigned to review flagged documents                  |
| Status            | Toggle showing if the rule is active (green) or inactive (gray)       |
| Actions           | Edit button to modify the rule                                        |

<figure><img src="https://3990462849-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fgjpo1gyiI3QKDSNO9maQ%2Fuploads%2FMhjpCPCTwOCoszkVdxpb%2F2%20-%20current%20validation%20rules%20table.png?alt=media&#x26;token=511b91d6-8acb-45c2-95a7-29dd2b3fcc77" alt=""><figcaption></figcaption></figure>

You can filter rules using the search box and the **All Status** dropdown to show active, inactive, or all rules.&#x20;

Click the expand arrow (**v**) next to any rule to view its details, including the Business Logic description, Message, and Calculation expression.&#x20;

<figure><img src="https://3990462849-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fgjpo1gyiI3QKDSNO9maQ%2Fuploads%2FnczkUQtURnytV7GXHnRx%2F3%20-%20expand%20details%20of%20each%20rule%20in%20the%20table.png?alt=media&#x26;token=4fee5358-3673-41e5-9be6-273f0078a6e5" alt=""><figcaption></figcaption></figure>

&#x20;

### Creating a Validation Rule&#x20;

Follow these steps to create a new validation rule:&#x20;

#### Step 1: Enter Rule Name&#x20;

In the **Rule Name** field, enter a descriptive name that identifies the rule's purpose. Use a clear naming convention such as "ExpenseApproval", "NullVendor", or "LineTotalCheck".&#x20;

<figure><img src="https://3990462849-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fgjpo1gyiI3QKDSNO9maQ%2Fuploads%2Fn8vzBXZ2uPbMqjpM8zR4%2F4%20-%20create%20new%20rule.png?alt=media&#x26;token=d0d1bd89-8f55-4af9-94ec-93503068ab2a" alt=""><figcaption></figcaption></figure>

#### Step 2: Select Type

<figure><img src="https://3990462849-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fgjpo1gyiI3QKDSNO9maQ%2Fuploads%2FbO0gMsFHh2tma4LAIsGa%2F5%20-%20type%20drop%20down.png?alt=media&#x26;token=1d1925a4-23e1-4c17-8cbd-b4010ecba0eb" alt=""><figcaption></figcaption></figure>

From the **Type** dropdown, select where the rule should apply:

| **Type** | **Description**                                                   |
| -------- | ----------------------------------------------------------------- |
| Document | Apply the rule to individual documents during processing          |
| Workflow | Apply the rule to documents processed through a specific workflow |

#### Step 3: Select Document Type&#x20;

From the **Document Type** dropdown, select the type of document this rule applies to:&#x20;

| **Document Type**    | **Example Fields Available**                                                                       |
| -------------------- | -------------------------------------------------------------------------------------------------- |
| Bank Statement       | transaction\_debit, transaction\_credit, transaction\_balance, total\_deposits, total\_withdrawals |
| Credit Report        | credit\_score, account\_status, payment\_history                                                   |
| ID                   | date\_of\_birth, expiry\_date, document\_number                                                    |
| Invoice              | total, subtotal, tax, vendor\_name, invoice\_number, amount                                        |
| Mortgage Application | loan\_to\_value\_ratio, disposable\_income, property\_value                                        |
| Pay Slip             | gross\_pay, net\_pay, deductions, pay\_period                                                      |
| Purchase Order       | vendorName, totalPrice, quantity, unitPrice                                                        |
| Other                | Custom fields based on document configuration                                                      |

<figure><img src="https://3990462849-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fgjpo1gyiI3QKDSNO9maQ%2Fuploads%2F3fyrBMSxAsWkcBTvvqgv%2F6%20-%20document%20type%20dropdown.png?alt=media&#x26;token=63a33575-aca2-4d1b-855c-05e9093abd39" alt=""><figcaption></figcaption></figure>

#### Step 4: Select Field to Validate&#x20;

From the **Field To Validate** dropdown, select the extracted field that this rule will check. The available fields depend on the document type selected. Each field shows its data type in parentheses (e.g., "total (number)", "vendorName (string)", "transaction\_date (string)").&#x20;

<figure><img src="https://3990462849-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fgjpo1gyiI3QKDSNO9maQ%2Fuploads%2FgHZumYqo8qvdeCPD1Y4O%2F7%20-%20fields%20to%20validate%20dropdown.png?alt=media&#x26;token=f330c37c-9f9d-49b8-af24-c12d501f12b6" alt=""><figcaption></figcaption></figure>

#### Step 5: Select Action On Failure&#x20;

From the **Action On Failure** dropdown, select what happens when the validation fails:&#x20;

| **Action**      | **Description**                                                                                                                                 |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| Flag for Review | Document is marked "In Review" and assigned to a team member for manual review. Processing continues but the document requires human attention. |
| Error           | Document processing fails validation. The error message is displayed and the document is not processed further until the issue is resolved.     |

<figure><img src="https://3990462849-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fgjpo1gyiI3QKDSNO9maQ%2Fuploads%2FjdJtRhMnsomBAIw0IxJa%2F8%20-%20action%20on%20failure.png?alt=media&#x26;token=51cb92ed-fd7a-49c6-aa80-ea8ca57febe7" alt=""><figcaption></figcaption></figure>

#### Step 6: Assign Reviewer (If Applicable)&#x20;

If you selected **Flag for Review** as the action, the **Assignee** dropdown appears. Select a team member from your organization who will be responsible for reviewing documents that fail this validation.&#x20;

<figure><img src="https://3990462849-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fgjpo1gyiI3QKDSNO9maQ%2Fuploads%2FBqC2MScbuMxXSFuHCot6%2F9%20-%20Reviewer%20Assigned.png?alt=media&#x26;token=563aff84-014e-48c9-99b9-47d5147154ef" alt=""><figcaption></figcaption></figure>

#### Step 7: Write the Validation Expression&#x20;

In the **Validation Expression** field, enter the condition that must be true for the document to pass validation. The expression should evaluate to true when the data is valid.&#x20;

**Expression Examples:**&#x20;

| **Purpose**                     | **Expression**                                |
| ------------------------------- | --------------------------------------------- |
| Check field is not null         | IsNotNull(vendorName) = true                  |
| Flag amount above threshold     | total < 10000                                 |
| Compare calculated vs extracted | Abs(quantity \* unitPrice - totalPrice) < 0.1 |
| Subtotal verification           | Abs(cal\_subtotal - subtotal) < 0.2           |
| Value must be positive          | amount > 0                                    |
| Date comparison                 | expiry\_date > current\_date                  |

<figure><img src="https://3990462849-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fgjpo1gyiI3QKDSNO9maQ%2Fuploads%2FsUzBugdOtRtg3QXJY0kC%2F10%20-%20validation%20expression%20and%20the%20error%20message%20to%20show%20when%20amount%20exceeds%20a%20threahold.png?alt=media&#x26;token=0ec02be3-b65e-4a12-8d4c-ce7bf68d20d4" alt=""><figcaption></figcaption></figure>

#### Step 8: Enter Show Message&#x20;

In the **Show Message** field, enter the message that will be displayed when the validation fails. This message should clearly explain why the document failed validation and what action may be needed.&#x20;

#### Step 9: Save the Rule&#x20;

Click **Add Rule** to save the validation rule. The rule will appear in the Current Validation Rules table and will be applied to matching documents during processing.&#x20;

<figure><img src="https://3990462849-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fgjpo1gyiI3QKDSNO9maQ%2Fuploads%2F0HVubZmRjHf573qgm5Lt%2F11%20-%20New%20rule%20added%20to%20the%20table.png?alt=media&#x26;token=b61b30f6-afc4-40d4-abcd-992ef92160db" alt=""><figcaption></figcaption></figure>

### Editing an Existing Rule&#x20;

1. In the Current Validation Rules table, locate the rule you want to edit.&#x20;
2. Click the edit icon (pencil) in the **Actions** column.&#x20;
3. The **Edit Validation Rule** form will appear at the top of the page with the rule's current settings.&#x20;
4. Modify any fields as needed.&#x20;
5. Click **Update Rule** to save your changes, or **Cancel** to discard them.&#x20;

<figure><img src="https://3990462849-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fgjpo1gyiI3QKDSNO9maQ%2Fuploads%2F1vuaCeybiAe2qX787lAN%2F12%20-%20edit%20or%20update%20and%20existing%20rule.png?alt=media&#x26;token=ca3b30b2-dbd6-4e0b-a843-1d4e031a011c" alt=""><figcaption></figcaption></figure>

### Enabling or Disabling Rules&#x20;

You can quickly enable or disable a rule without editing it by clicking the status toggle in the **Status** column of the Current Validation Rules table. A green toggle indicates the rule is active; a gray toggle indicates it is inactive.&#x20;

### Example Validation Rules&#x20;

#### Example 1: Expense Approval Threshold&#x20;

Flag invoices over $10,000 for manager approval.&#x20;

| **Field**             | **Value**                                            |
| --------------------- | ---------------------------------------------------- |
| Rule Name             | ExpenseApproval                                      |
| Type                  | Document                                             |
| Document Type         | Invoice                                              |
| Field To Validate     | total (number)                                       |
| Action On Failure     | Flag for Review                                      |
| Assignee              | <manager@company.com>                                |
| Validation Expression | total < 10000                                        |
| Show Message          | Expense exceeding $10000 needs approval from manager |

#### &#x20;Example 2: Required Vendor Name&#x20;

Ensure vendor name is present on purchase orders.&#x20;

| **Field**             | **Value**                    |
| --------------------- | ---------------------------- |
| Rule Name             | NullVendor                   |
| Type                  | Document                     |
| Document Type         | Purchase Order               |
| Field To Validate     | vendorName (string)          |
| Action On Failure     | Flag for Review              |
| Assignee              | <ap-team@company.com>        |
| Validation Expression | IsNotNull(vendorName) = true |
| Show Message          | Vendor Name Does Not Exist   |

#### &#x20;Example 3: Line Total Verification&#x20;

Verify that line total equals quantity multiplied by unit price (with tolerance for rounding).&#x20;

| **Field**             | **Value**                                     |
| --------------------- | --------------------------------------------- |
| Rule Name             | LineTotalCheck                                |
| Type                  | Document                                      |
| Document Type         | Purchase Order                                |
| Field To Validate     | totalPrice (number)                           |
| Action On Failure     | Error                                         |
| Validation Expression | Abs(quantity \* unitPrice - totalPrice) < 0.1 |
| Show Message          | Line total is incorrect                       |

#### &#x20;Best Practices&#x20;

* **Use descriptive rule names** – Names should clearly indicate what the rule checks.&#x20;
* **Write clear error messages** – Messages should explain the issue and suggest next steps.&#x20;
* **Use tolerance for numeric comparisons** – Use Abs() function with small tolerance values to account for rounding differences.&#x20;
* **Test rules with sample documents** – Create rules as and test against sample documents with issues. &#x20;
* **Assign appropriate reviewers** – Route flagged documents to team members with authority to resolve the issues.&#x20;
* **Review and update rules periodically** – Business requirements change; ensure your validation rules stay current.&#x20;

#### Troubleshooting&#x20;

| **Issue**                        | **Solution**                                                                                                    |
| -------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| Rule not triggering              | Verify the rule status is Active. Check that Document Type and Field match the documents being processed.       |
| Expression syntax error          | Use field names exactly as shown in the Field To Validate dropdown. Ensure operators and functions are correct. |
| Wrong documents flagged          | Review the validation expression logic. Remember the expression should be true when data is valid.              |
| Assignee not receiving documents | Verify the assignee email is correct and the user has access to the Human Review feature.                       |
| Numeric comparison issues        | Use Abs() function with tolerance for floating-point comparisons to handle rounding differences.                |

#### &#x20;Related Features&#x20;

* **Document Queue** – View documents flagged by validation rules with "In Review" status.&#x20;
* **Human Review** – Review and correct documents that failed validation.&#x20;
* **Document Tracking** – Monitor validation status and history for each document.&#x20;
* **Process Notifications** – Set up alerts when documents fail validation.&#x20;
* **Workflow** – Include validation rules as part of automated document processing pipelines.&#x20;
