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

# Validation Rules

> Set conditions that records must meet before they can be saved.

## What Are Validation Rules?

A validation rule is a condition that must be true before a record can be created or updated. If the condition is false, Twenty blocks the save and shows a message explaining what needs to change.

Use rules to require information at the right time, such as an amount before an opportunity becomes a customer, or to prevent inconsistent values, such as an end date before a start date.

> [!NOTE]
>
> Validation rules are available on the Organization plan. You need permission
> to edit the data model to manage them.

## Create a Validation Rule

1. Go to **Settings → Data Model** and select the object you want to configure.
2. Open the **Settings** tab, find **Validation rules**, and click **Add rule**.
3. Give the rule a name and, optionally, a description to explain its purpose.
4. Write a **Condition**. Start typing a field name or function and select suggestions from the helper panel.
5. Under **Error**, enter a **Message** that tells people how to fix the record. Use **Show on** to attach it to a specific field or select **Whole record**.
6. Check the **Preview** to see how the condition behaves on existing records.
7. Click **Activate** to start enforcing the rule.

New rules stay inactive until you activate them. A rule needs a name, a valid condition, and an error message before it can be activated.

### Preview Your Rule

The preview uses up to three recent records from the selected object. Use the arrows to move between them and inspect the values used by the condition.

| Status | Meaning |
| - | - |
| **Valid** | The record meets the condition. |
| **Blocked** | The record fails the condition. The preview also shows your error message. |
| **Error** | The condition could not be evaluated. Check the error details and adjust the expression. |

Previewing a rule does not change any records. If the object has no records yet, create a few to try the preview.

## Write a Condition

Write the condition that allows a save. For example, `employees > 0` allows a company to be saved only when its employee count is greater than zero.

Use field names such as `employees`, rather than display labels such as **Employees**. Selecting a field from the helper inserts the correct reference.

| Syntax | Use |
| - | - |
| `==`, `!=`, `<`, `<=`, `>`, `>=` | Compare values. |
| `and`, `or`, `not` | Combine or negate conditions. |
| `+`, `-`, `*`, `/` | Calculate values. |
| `stage in ['NEW', 'CUSTOMER']` | Check whether a value is in a list. |
| `true`, `false` | Compare boolean fields. |
| `now` | Use the date and time of the save. |

Put text in single or double quotes and use parentheses to group conditions. Use `and` and `or` rather than `&&` and `||`: `||` joins two values as one text, skipping a value that is not set, as `concat` does.

### Check for Missing Values

| Function | Use |
| - | - |
| `isEmpty(value)` | Check for a missing value, empty text, an empty list, or an empty composite field. |
| `isDefined(value)` | Check whether a value is set. Empty text still counts as defined. |
| `isNonEmptyString(value)` | Check that a value is text with at least one character. |
| `includes(listOrText, value)` | Check whether a list contains a value or text contains a substring. Text matching is case-sensitive. |
| `arrayLength(list)` | Get the number of items in a list. |

To make a field required, use `not isEmpty(fieldName)`. This also works for composite fields such as emails and addresses.

### Compare Dates

| Function | Use |
| - | - |
| `dateDiff(from, to, unit)` | Get the number of whole units from one date to another. Minutes and hours are elapsed time; days, weeks, months, quarters and years count calendar days and months, in UTC. Negative when `to` is earlier. |
| `dateAdd(date, amount, unit)` | Move a date by a whole number of units, in UTC. A month added to the 31st lands on the last day of the month. |
| `dateTrunc(date, unit)` | Get the start of the unit that contains the date, in UTC. Weeks start on Monday. |
| `datePart(date, part)` | Get one part of the date as a number, in UTC: `"YEAR"`, `"QUARTER"`, `"MONTH"`, `"WEEK"`, `"DAY"`, `"DAY_OF_WEEK"` (1 is Monday), `"HOUR"` or `"MINUTE"`. |
| `isInRelativeDateRange(date, direction, amount, unit)` | Check whether a date falls in a period counted from today, in UTC. `direction` is `"PAST"`, `"NEXT"` or `"THIS"`, `unit` is `"DAY"`, `"WEEK"`, `"MONTH"`, `"QUARTER"` or `"YEAR"`. `"PAST"` and `"NEXT"` leave out the current period. |

### Compute Values

| Function | Use |
| - | - |
| `if(condition, valueIfTrue, valueIfFalse)` | Get the second value when the condition is true, otherwise the third one. |
| `coalesce(value, ...fallbacks)` | Get the first value that is set. |
| `concat(value, ...values)` | Join values as one text. Values that are not set are skipped. |
| `lower(text)`, `upper(text)` | Change the letter case of a text. |
| `min(number, ...numbers)`, `max(number, ...numbers)` | Get the smallest or largest number. Values that are not numbers are ignored. |
| `roundTo(number, decimals)` | Round a number to a number of decimals. |

`daysSince(date)` has been removed. Use `dateDiff(date, now, 'DAY')` instead.

Date comparisons use the UTC calendar day when a date has no time. Two date-times compare as instants, so equivalent offsets and fractional-second spellings compare equally. This also changes existing expressions that compared those values as text.

Units are `"MINUTE"`, `"HOUR"`, `"DAY"`, `"WEEK"`, `"MONTH"`, `"QUARTER"` or `"YEAR"`. For example, `dateDiff(closeDate, now, "DAY") >= 0 and dateDiff(closeDate, now, "DAY") <= 30` allows a save only on the close date or in the 30 days after it.

### Reference Composite and Related Fields

Use a dot to read part of a composite field, such as `name.firstName` or `amount.amountMicros`. You can also read a field through a many-to-one relation, such as `company.name` on a person. Select fields from the helper to find the available paths.

Currency amounts are stored in micros: one currency unit equals `1000000` micros. For example, `amount.amountMicros >= 100000000` requires an amount of at least 100 in the record's currency.

For select fields, compare the stored option value, such as `'CUSTOMER'`, rather than its display label. Check the helper examples for the values available on your field.

## Example Rules

Adapt the field names and option values to your data model. The `startDate`, `endDate`, and `tags` fields below are examples of custom fields.

| Goal | Condition | Suggested error message |
| - | - | - |
| Require a company name | `not isEmpty(name)` | Enter a company name. |
| Require a positive amount when an opportunity reaches Customer | `stage != 'CUSTOMER' or amount.amountMicros > 0` | Enter an amount greater than zero before moving this opportunity to Customer. |
| Require a person to be linked to a company | `isDefined(company)` | Select a company for this person. |
| Require an end date to be on or after the start date | `isDefined(startDate) and isDefined(endDate) and endDate >= startDate` | Enter a start date and an end date on or after it. |
| Require at least one tag | `arrayLength(tags) > 0` | Add at least one tag. |

The opportunity example uses `or` to make the amount requirement conditional: other stages can be saved without an amount.

## When Rules Are Checked

Active rules are checked when records are created or updated, including changes made through the API, imports, and workflows. A record must pass all active rules for its object to be saved.

Activating a rule does not change existing records. A record that fails the new condition must be corrected the next time it is saved.

A condition that reads a related record is evaluated when the record the rule belongs to is saved. Editing the related record alone does not recheck it.

## Edit, Disable, or Delete a Rule

Return to **Settings → Data Model → your object → Settings → Validation rules**, then click the rule.

* **Edit:** Update the condition or message, check the preview, and click **Save**. For an inactive rule, this button is **Activate**.
* **Disable:** In **Danger zone**, click **Disable** to stop enforcing the rule while keeping its configuration. Click **Enable** to enforce it again.
* **Delete:** In **Danger zone**, click **Delete** and confirm to permanently remove the rule. Existing records are not changed.

Deactivating or deleting a field used in a condition also deactivates the rules that read it. Review those rules before enabling them again.

To define validation rules in an app, see the [developer guide](https://docs.twenty.com/developers/extend/apps/data/validation-rules.md).


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