> ## Documentation Index
> Fetch the complete documentation index at: https://flatfileinc-remove-rss-json.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Constraints

> system level validation rules

## Field-Level

Field-level constraints allow you to indicate additional validations that will
be applied to fields of a Sheet. These constraints are in addition to the
implicit constraints based on types of data. (eg: String, Number)

For example, a value is required for every record (RequiredConstraint), or every
record must contain a unique value for the field (UniqueConstraint).

### Required

Required Constraints indicate that the given field **must** be provided with a
non-null value.

<Note>A `null` value in this case constitutes an empty cell.</Note>

```json theme={"system"}
// within the context of a create Workbook API call
 "fields": [
  {
    "key": "firstName",
    "type": "string",
    "label": "First Name",
    "constraints": [
      {
        "type": "required"
      }
    ]
  }
]
```

### Unique

Unique Constraints indicate that the given field value must only appear **once**
in all the values for that field.

<Note>
  `null` values will appear many times because they are not considered unique as
  there is no value to compare.
</Note>

```json theme={"system"}
// within the context of a create Workbook API call
 "fields": [
  {
    "key": "internalCustomerId",
    "type": "number",
    "label": "Internal Customer Id",
    "constraints": [
      {
        "type": "unique"
      }
    ]
  }
]
```

### Computed

The computed constraint hides the given field from the mapping process, so your
users will not be able to map incoming columns to this field.

```json theme={"system"}
// within the context of a create Workbook API call
 "fields": [
  {
    key: 'age',
    type: 'number',
    label: 'Age',
    description: "The number of years since the person's birth date",
    constraints: [
      {
        type: 'computed',
      },
    ],
  },
]
```

## Sheet-Level

### Composite Uniqueness

Composite Uniqueness is a feature where a combination of two or more fields must
be unique across an entire Sheet.

To implement composite uniqueness, add the following parameters to the
`constraints` property:

* `name` *defines the name of the constraint*

* `fields` *array of field keys to consider*

* `type` *defines the type of the constraint*

* `strategy` *defines how to determine uniqueness* {" "} Can either be: {" "}
  `concat` *concatenates values from each field defined inside the `fields`
  array* {" "} or `hash` *creates a sha1 hash using of the values of each field*

```json theme={"system"}
"sheets": [
  {
    "name": "Products",
    "description": "A list of products available for sale",
    "slug": "products",
    "constraints": [
      {
        "name": "constraint name",
        "fields": ["field_key_one", "field_key_two"],
        "type": "unique",
        "strategy": "concat"
      }
    ],
  }
]
```
