Skip to main content
net10.0

Schema validation for F#. Zero-allocation parsing, type-safe computation expressions, 30+ validators, fromType, and JSON Schema generation.

Published
Mar 31, 2026
7mo ago
Total Downloads
1.0K
1,015

Install

dotnet add package Flame --version 0.1.0-alpha
ProductVersions
.NET
net10.0

README

Flame

Zod-like schema validation for F#. Zero-allocation parsing, type-safe computation expressions, and JSON Schema generation.

Install

dotnet add package Flame

Quick Start

open Flame

let userSchema = schema {
    let! name  = Schema.required "name"  Schema.string [ Schema.nonempty; Schema.maxLength 100; Schema.trim ]
    let! email = Schema.required "email" Schema.string [ Schema.email; Schema.trim; Schema.lowercase ]
    let! age   = Schema.optional "age"   Schema.int 0  [ Schema.min 0; Schema.max 150 ]
    return {| Name = name; Email = email; Age = age |}
}

match Schema.parseString userSchema """{"name":"Alice","email":"[email protected]","age":30}""" with
| Ok user -> printfn $"Hello, {user.Name} ({user.Email})"
| Error errors -> printfn $"Validation failed: {errors}"

Auto-generate from types

Schema.fromType<'T>() introspects F# record fields. Option fields become optional, nested records and typed lists are handled recursively. Cached per type — reflection runs once.

type Address = { Street: string; Zip: string }
type User = { Name: string; Age: int; Address: Address; Tags: string list; Nickname: string option }

let userSchema = Schema.fromType<User>()

Validation Rules

Category Rules
String length minLength, maxLength, length, nonempty
String format email, url, uuid, ip, ipv4, ipv6, datetime, pattern
String content startsWith, endsWith, includes, enum'
String transforms trim, lowercase, uppercase
Number bounds min, max, gt, lt
Number checks positive, negative, nonnegative, nonpositive, int', multipleOf
Array bounds minItems, maxItems, nonEmpty

Nested Schemas

let address = schema {
    let! street = Schema.req "street" Schema.string
    let! zip    = Schema.required "zip" Schema.string [ Schema.pattern @"^\d{5}$" ]
    return {| Street = street; Zip = zip |}
}

let user = schema {
    let! name    = Schema.req "name" Schema.string
    let! address = Schema.required "address" (Schema.nest address) []
    return {| Name = name; Address = address |}
}

Cross-field Validation

let passwordSchema = schema {
    let! password = Schema.req "password" Schema.string
    let! confirm  = Schema.req "confirm" Schema.string
    do! Schema.check (fun () ->
        if password = confirm then Ok ()
        else Error "confirm: must match password"
    )
    return {| Password = password |}
}

Parse from Multiple Sources

Schema.parseString schema jsonString        // from string (buffer path)
Schema.parseJson schema jsonElement          // from JsonElement
Schema.parseBuffer schema buffer             // from ReadOnlySequence<byte> (zero-alloc)
Schema.parsePipe schema pipeReader           // from PipeReader (async)
Schema.parseStream schema stream             // from Stream (async)
Schema.parseLookup schema lookupFn           // from lookup function (zero-alloc)
Schema.parseMap schema dictionary            // from IReadOnlyDictionary

JSON Schema Generation

let jsonSchema = Schema.toJsonSchema userSchema
// { "type": "object", "required": ["name", "email"], "properties": { ... } }

Performance

Flame parses and validates in a single pass using Utf8JsonReader — no intermediate JsonDocument allocation. Benchmarks on Apple M4 Pro, .NET 10:

Scenario Flame (buffer) FluentValidation (STJ + validate) Speedup Memory
3 fields + rules 239 ns / 408 B 266 ns / 832 B 1.1x 2x less
10 fields + nested 763 ns / 1,448 B 1,098 ns / 2,856 B 1.4x 2x less
Nested objects 370 ns / 824 B 509 ns / 2,136 B 1.4x 2.6x less
New validators (uuid, ip, etc.) 516 ns / 944 B 566 ns / 1,800 B 1.1x 1.9x less

License

MIT

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.