# Validation

{% hint style="success" %}
This is the official documentation of Forest Admin Cloud.
{% endhint %}

Most data sources can import validation rules directly. For example, in a SQL database, columns defined as `VARCHAR(15)` will automatically include a rule to ensure content is shorter than 15 characters. Similarly, columns marked as `NOT NULL` will require that some content is always present.

***

To make the code easier to read, all the code snippets below should be wrapped in the following code. Ensure you update the collection and field names as needed.

```typescript
import type { Agent } from '@forestadmin/forest-cloud';
import { Schema } from '../typings';

export default function customizeAgent(agent: Agent<Schema>) {
  agent.customizeCollection('users', (collection) => {
    // Insert the code snippet here.
  });
}
```

***

In some cases, it might be necessary to enforce stricter rules than the ones currently set in your data source. This can be achieved through the use of the `addFieldValidation` method.

```typescript
collection
  .addFieldValidation('first_name', 'Present')
  .addFieldValidation('first_name', 'LongerThan', 2)
  .addFieldValidation('first_name', 'ShorterThan', 13)
  .addFieldValidation('first_name', 'Match', /^[a-z]+$/i);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.forestadmin.com/cloud/code-customization/fields/validation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
