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

# Add custom validators

> How to add custom validators in Atoti Limits by implementing ILimitStructureValidator, ILimitValidator, or IIncidentValidator to replace the default validation logic for limit structures, limits, or incidents

You can customize the validation performed when creating or updating limit structures, limits, and incidents by adding beans
that implement the `ILimitStructureValidator`, `ILimitValidator`, and `IIncidentValidator` interfaces, respectively.
Here’s how to do this:

## 1. Create the Spring Bean(s)

These interfaces provide the explicit type parameter for the generically-typed `IValidator` interface:

```java theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
public interface ILimitStructureValidator extends IValidator<LimitStructure> {}
```

```java theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
public interface ILimitValidator extends IValidator<Limit> {}
```

```java theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
public interface IIncidentValidator extends IValidator<Incident> {}
```

To implement a custom validator, create a class that implements the appropriate interface and override its methods. A custom
implementation of `ILimitValidator` could look like this:

```java theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
@Component
public class MyLimitValidator implements ILimitValidator {

    @Autowired
    IValidationErrorHandler<Limit> validationErrorHandler;

    @Getter private List<Limit> validObjects = new ArrayList<>();
    @Getter private List<Limit> invalidObjects = new ArrayList<>();

    @Override
    public boolean validate(Limit limit) {
        // Custom validation logic
        return true;
    }

    @Override
    public void preValidation(Collection<Limit> limits) {
        // Custom pre-validation logic
    }

    @Override
    public void postValidation(Collection<Limit> validatedLimits) {
        // Custom post-validation logic
    }

    @Override
    boolean validateTuple(Object[] tuple, int lineNumber) {
        // Custom tuple validation logic
        return true;
    }

    @Override
    public IValidationErrorHandler<Limit> getValidationErrorHandler() {
        return validationErrorHandler;
    }

    @Override
    public void reset(final boolean throwException) {
        validObjects.clear();
        invalidObjects.clear();
        validationErrorHandler.getValidationErrors().clear();
    }
}
```

<Note>
  Note that the `hasErrors` method is not overridden in the custom validator. The default implementation of this method in `IValidator` is sufficient for most use cases.
</Note>

## 2. Import the Spring Bean

Once the bean is created, import it into the project. See [Importing Spring Beans into the Project](..#importing-spring-beans-into-the-project) on how to do this. Once done,
Spring will use the custom bean when validating the relevant object type.
