> ## Documentation Index
> Fetch the complete documentation index at: https://validity-kt.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Validity

> Validation for Kotlin, written in plain Kotlin.

Kotlin 2.4
Java 17+
Apache 2.0

[GitHub](https://github.com/soleworks/validity) · [Quick start](https://validity-kt.dev/quickstart.md) · [Constraints](https://validity-kt.dev/constraints/overview.md) · [For AI agents](https://validity-kt.dev/ai-agents.md)

## Introduction

Validity is a validation library for Kotlin. You describe the rules of your data in plain Kotlin, next to the data,
and Validity reports every rule that is broken, each with a path, a message for people and a code for programs.

```kotlin User.kt theme={null}
data class User(
    val name: String?,
    val email: String?,
    val age: Int?
) : Validatable {
    override fun validation() = validation {
        ::name required { minLength(2) }
        ::email required { email() }
        ::age ifPresent { min(18) }
    }
}
```

```kotlin theme={null}
User(name = "A", email = "ana@", age = 16).validate().violations
```

| Path | Message | Code |
| - | - | - |
| `name` | must have at least 2 characters | `minLength` |
| `email` | must be a valid email | `email` |
| `age` | must be at least 18 | `min` |

## Features

* Plain Kotlin: no annotations, no code generation, no reflection
* Every broken rule at once, with paths into nested objects, lists and maps
* Conditions are ordinary `if` and `when`
* Rules across fields, and rules that depend on the caller
* Rules can call `suspend` functions, such as a database lookup
* 175 built-in constraints, with documents of 14 countries and postal codes of 72
* Messages you can translate, and codes that never change
* Depends only on the Kotlin standard library and kotlinx.coroutines

## Installation

```kotlin build.gradle.kts theme={null}
implementation("io.github.soleworks:validity-core:0.1.0")
```

```groovy build.gradle theme={null}
implementation 'io.github.soleworks:validity-core:0.1.0'
```

```xml pom.xml theme={null}
<dependency>
    <groupId>io.github.soleworks</groupId>
    <artifactId>validity-core</artifactId>
    <version>0.1.0</version>
</dependency>
```

Phone numbers are in a separate module, `validity-phone`. See [Installation](https://validity-kt.dev/installation.md) for the modules
and the imports.

> [!WARNING]
>
> Validity is not on Maven Central yet: the first release is on its way. Until it lands, clone the
> [repository](https://github.com/soleworks/validity) next to your project and add `includeBuild("../validity")` to
> your `settings.gradle.kts`. Gradle then builds the dependency from the clone.

Validity provides an [MCP server](https://validity-kt.dev/ai-agents.md) that agents can use to search these docs, and an
`/llms.txt` file at the root of this site.

## Requirements

Validity runs on Java 17 or newer and is built with Kotlin 2.4.

## Next

> [card] [Quick start](https://validity-kt.dev/quickstart.md)
>
> Validate your first class.

> [card] [Why Validity](https://validity-kt.dev/introduction.md)
>
> The ideas, and how it compares.

> [card] [Constraints](https://validity-kt.dev/constraints/overview.md)
>
> All 175, by type of value.


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