#schema-validation #reflection #schema #facet #validation

facet-validate

Validation attributes for facet - validate field values during deserialization

5 unstable releases

Uses new Rust 2024

0.43.2 Jan 23, 2026
0.43.1 Jan 23, 2026
0.43.0 Jan 22, 2026
0.42.0 Jan 6, 2026
0.1.0 Jan 6, 2026

#2950 in Encoding

Download history 24/week @ 2026-01-05 43/week @ 2026-01-12 77/week @ 2026-01-19 88/week @ 2026-01-26

232 downloads per month
Used in 2 crates (via facet-format)

MIT/Apache

1MB
19K SLoC

facet-validate

Coverage Status crates.io documentation MIT/Apache-2.0 licensed Discord

facet-validate

Field validation during deserialization for the facet ecosystem.

Features

  • Validation runs during deserialization, so errors include source spans (e.g., pointing to the exact JSON location)
  • Custom validators with meaningful error messages via Result<(), String>
  • Auto-deref: fn(&str) validators work for String fields

Usage

use facet::Facet;
use facet_validate as validate;

fn validate_positive(n: &i64) -> Result<(), String> {
    if *n <= 0 {
        Err(format!("must be positive, got {}", n))
    } else {
        Ok(())
    }
}

#[derive(Facet)]
struct Product {
    #[facet(validate::custom = validate_positive)]
    price: i64,
}

Built-in Validators

Validator Syntax Applies To
min validate::min = 0 numbers
max validate::max = 100 numbers
min_length validate::min_length = 1 String, Vec, slices
max_length validate::max_length = 100 String, Vec, slices
email validate::email String
url validate::url String
regex validate::regex = r"..." String
contains validate::contains = "foo" String
custom validate::custom = fn_name any

Integration

Enable the validate feature on facet-json (or other format crates):

[dependencies]
facet-json = { version = "0.41", features = ["validate"] }
facet-validate = "0.41"

Sponsors

Thanks to all individual sponsors:

GitHub Sponsors Patreon

...along with corporate sponsors:

AWS Zed Depot

...without whom this work could not exist.

Special thanks

The facet logo was drawn by Misiasart.

License

Licensed under either of:

at your option.

Dependencies

~3.5–5MB
~83K SLoC