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

# Validation Rules

> Check the fields of a case against each other

A validation rule checks fields of a case against each other: an end date after a start date, a reason when an order is rejected, line items that add up to the total. The rules are checked each time a case is saved, by a person, a flow or an email. You set them in the process's **Configuration**, under **Validation rules**; Genie and the API set them too.

* A rule flags the fields it names on the case page, with its message. The case is still saved, so you can fill its fields one at a time, in any order.
* A rule set to **Block closing** (a *strict* rule in the API) flags its fields as errors, and no one can close a case while it breaks one, even a rule added after the break: **Change status** holds **Closed** back and names the rule, a task that would close the case cannot be completed, and a flow step that closes the case fails and the case's timeline says why. When the process flow reaches **Case Completed**, or a flow completes a task that would close the case, the case stays open and its timeline says why. Reopening a case is never refused.
* A rule set to **Warn** only warns: the case can still be closed.
* A field's own check marked **Strict** (a maximum length, a pattern) holds the close the same way while the case's value breaks it, for example a value saved before the check was added. An edit to that field saves only once the whole field passes, every list item and table cell included. A read-only table column is the exception: you cannot change its cells, so an old bad value there holds only the close. Until then the case page keeps your value on screen, unsaved, and holds **Closed** back. A bad value in another field never stops an edit.

## Add a rule

**1. Open Validation rules**

In the process's **Configuration**, under **Validation rules**, click **Add rule** and pick the kind of rule.

**2. Fill in the sentence**

Pick the fields the rule compares. Each picker offers only the fields that can be compared with the one before it. **Add days** (or **Add offset** for numbers) shifts the right side. Until the rule is complete, it says what it still needs.

**3. Choose what happens if it is not met**

**Warn** flags the fields. **Block closing** also stops anyone, a flow included, from closing a case that breaks the rule. **Add message** replaces the sentence people see when the rule is broken.

**4. Click Save rule**

The rule collapses to its sentence, with a **Warns** or **Blocks closing** badge. **Cancel** drops the changes to this rule.

## Change or delete a rule

Click a rule's sentence to open it, then **Save rule** or **Cancel**. While a rule has unsaved changes, the other rules and **Add rule** wait for it. **Delete rule** asks first, then saves at once.

A rule that checks the same thing as another rule, whatever its message or what happens if it is not met, cannot be saved: change it, or delete one of the two.

## Kinds of rules

| Kind | Example |
| - | - |
| Compare two fields | End date must be on or after Start date plus 30 days |
| Require fields when conditions hold | Reason is required when Status is 'Rejected' or Status is one of 'On hold' |
| Fill at least one of several fields | At least 1 of Email, Phone must be filled |
| Compare a table's total with a field | The total of Line items, Amount must be at most Budget |
| Check every row of a table | On each row of Line items, Shipped on must be on or after Order date |

* Numbers and dates compare with less than, at most, greater than, at least, equal to and different from. Text compares only with equal to and different from.
* An offset adds to the right side of a comparison: whole days for dates (up to 36500), units for numbers. A negative offset subtracts.
* A condition on a Yes/No field is Yes or No.
* A rule with several conditions applies when all of them hold, or when any of them holds.
* A comparison is not checked while either side is empty. A table total skips empty cells, and a table with no rows is not checked.
* A row rule compares two columns of each row, or a column with a field of the case. It flags the table field and names each failing row, for example *Row 2: Quantity must be at most Ordered*.

## See the rules of a field

In **Case fields**, a field that a rule names carries a link mark beside its name. Hover the mark to read the rules. Click it to bring those rules into view in **Validation rules**.

The field's dialog lists the same rules in its **Validation** section. Click a rule to close the dialog on that rule, open. A rule with unsaved changes stays open, and the link only brings the other rule into view.

## When a field changes

A rule is paused while a field it names is deleted, or no longer fits it: its type changed, it now holds a list, an option a condition names is gone, or a table column it reads is gone or retyped. A paused rule flags nothing, refuses nothing and does not hold a close back. **Validation rules** shows it as paused with what is wrong: open it, pick what fits and click **Save rule**, or delete it. Each rule is saved on its own, so one rule can be repaired while another stays paused.

Before you save a change to a field or delete it, its dialog lists the rules the change would pause, with a tick to delete them too. The API says what is wrong with each rule in the process's `validation_rule_problems`.

## Genie and the API

Genie writes rules when it configures a process, by field name. The API stores them in the process's `validation_rules`, with each field by its id and a table's columns by column name. It refuses a set of rules with an incomplete or impossible rule with a `422` whose `identifier` is `validation_rules_invalid`; its `params.problems` has one line per problem, each starting with the rule's number (`rule 2: pick a column of the table`). It checks only the rules a request adds or changes: a rule already saved is kept as it is, even one that names a deleted field, so each broken rule can be repaired or dropped on its own.

An edit that breaks a rule is saved, through the API and by Genie too. A flow step that closes a case that breaks a strict rule fails with the rule's message, and the case's timeline says why it stays open. A close refused for a broken strict rule or a field's own strict check, by hand or by completing a task that closes the case, is a `422` whose `identifier` is `strict_rules_broken`; `params.gate` is `close_case` and `params.rules` lists each flagged field as `field_id`, `field_name` and `reason`.

## Export and import

An exported process carries its rules, with fields named by name. An import keeps every rule. A rule that names a field the process does not have, or one that no longer fits a field's type, is paused until it is repaired. An import into an existing process from a file made before processes had rules keeps that process's rules.


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