go-playground/validator
Struct and field validation library for Go using struct tags. The standard validation library used by Gin, Echo, and Fiber web frameworks. Supports 100+ built-in validators (required, min, max, email, url, uuid, oneof, etc.) plus cross-field and cross-struct validation. Custom validators with RegisterValidation().
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Input validation library — proper use prevents invalid data. Validation alone is not a security boundary; combine with proper sanitization.
⚡ Reliability
Best When
Validating Go API request structs in web frameworks (Gin, Echo, Fiber) with tag-based rules.
Avoid When
You need JSON schema generation, dynamic validation rules, or OpenAPI integration — use separate schema tools.
Use Cases
- • Validate HTTP API request body structs in Go web frameworks (Gin, Echo, Fiber) with struct tag annotations
- • Implement cross-field validation rules: validate two related fields consistently in a struct
- • Add custom business rule validators via RegisterValidation for domain-specific constraints
- • Validate configuration structs at startup to catch invalid settings before serving requests
- • Localize validation error messages for multi-language API responses
Not For
- • Runtime type validation — validator uses struct tags defined at compile time; for dynamic schemas use jsonschema
- • Pydantic-style schema generation — validator doesn't generate OpenAPI schemas; combine with swaggo for docs
- • Non-struct validation of arbitrary data — validator is struct-centric
Interface
Authentication
Library — no auth needed.
Pricing
MIT licensed open source library.
Agent Metadata
Known Gotchas
- ⚠ ValidationErrors must be cast from error — use err.(validator.ValidationErrors) to access individual field errors; plain Error() returns a combined message
- ⚠ Pointer fields need 'omitempty' to skip nil validation — without omitempty, a nil pointer for a required field passes validation
- ⚠ Custom validators receive fl FieldLevel interface — access the field value with fl.Field() and the struct with fl.Parent()
- ⚠ Cross-field validators use 'eqfield' tag (e.g., validate:'eqfield=Password') — test with the exact Go field name, not JSON tag name
- ⚠ go-playground/validator v10 changed some tag names from v9 — code migrated from v9 may silently skip validation if tags were removed/renamed
- ⚠ Slice/map validation requires 'dive' tag: validate:'required,dive,required' validates the slice itself and each element — without dive, element validation is skipped
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for go-playground/validator.
Scores are editorial opinions as of 2026-03-06.