Skip to main content
Kotlin 2.4Java 17+Apache 2.0

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.
User.kt

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

Phone numbers are in a separate module, validity-phone. See Installation for the modules and the imports.
Validity is not on Maven Central yet: the first release is on its way. Until it lands, clone the repository 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 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

Quick start

Validate your first class.

Why Validity

The ideas, and how it compares.

Constraints

All 175, by type of value.