pedantigo

module
v2.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: MIT

README

Pedantigo

CI Lint Coverage

Type-safe JSON validation and schema generation for Go.

v2 breaking change: the default struct tag changed from pedantigo to validate. This is to be in sync with wider range of community tools like swaggo that work with validate tags If you're upgrading from v1, see the migration guide before you update.

New projects should start with v2. v1 is maintained only for existing users — it receives no new features. All new feature development happens in v2.

Installation

go get github.com/SmrutAI/pedantigo/v2/validator

Requires Go 1.21+ (nuances)

Quick Example

type User struct {
    Email string `json:"email" validate:"required,email"`
    Age   int    `json:"age" validate:"min=18"`
}

// Parse and validate JSON
user, err := vl.Unmarshal[User](jsonData)
if err != nil {
    // Handle validation errors with field paths and error codes
    if ve, ok := err.(*validator.ValidationError); ok {
        for _, fe := range ve.Errors {
            fmt.Printf("%s: %s\n", fe.Field, fe.Message)
        }
    }
}

// Generate JSON Schema for LLM tools (no $schema field)
schemaBytes, _ := validator.SchemaJSONLLM[User]()

Framework Plugins

Plugins wire pedantigo directly into a web framework's own request-binding step, so validation runs automatically instead of requiring manual io.ReadAll + Unmarshal calls in every handler. Echo replaces the binder directly; Gin installs into both its JSON codec and validation hooks.

import "github.com/SmrutAI/pedantigo/plugins/web/pedantigoecho/v2"

e := echo.New()
e.Binder = pedantigoecho.NewBinder()

Features

Feature Description
100+ Constraints Email, URL, UUID, regex, numeric ranges, string length, and more
JSON Schema Generation Auto-generate schemas for LLM tool calling and OpenAPI
240x Caching Speedup Schema generation cached for high performance
Streaming Validation Validate partial JSON from LLM streams
Discriminated Unions Type-safe polymorphic data handling
Cross-Field Validation Validate relationships between fields
Zero Dependencies Only invopop/jsonschema + Go stdlib

Plugins

Plugin Framework Description
Echo Binder Echo Drop-in echo.Binder — automatic validation on every c.Bind() call
Gin Request Plugin Gin Installs Pedantigo into codec/json.API + binding.Validator for automatic request binding validation

Documentation

Full documentation at pedantigo.dev

Use Cases

Use Case Why Pedantigo?
API Request Validation Validate incoming JSON, return structured errors
LLM Structured Output Generate JSON Schema for function calling, validate responses
Configuration Files Parse config with defaults, fail fast on invalid values
Data Pipeline Input Ensure data quality at ingestion with detailed error paths

Feature Coverage

See API_PARITY.md for detailed comparison with Pydantic v2 and go-playground/validator.

License

MIT

Directories

Path Synopsis
package validator provides Pydantic-inspired validation for Go.
package validator provides Pydantic-inspired validation for Go.
internal/constraints
Package constraints provides validation constraint types and builders for pedantigo.
Package constraints provides validation constraint types and builders for pedantigo.
internal/isocodes
Package isocodes provides validation for ISO standard codes including country codes (ISO 3166-1), currency codes (ISO 4217), and postal codes.
Package isocodes provides validation for ISO standard codes including country codes (ISO 3166-1), currency codes (ISO 4217), and postal codes.
internal/schemagen
Package schemagen provides JSON Schema generation and enhancement utilities for pedantigo validators.
Package schemagen provides JSON Schema generation and enhancement utilities for pedantigo validators.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL