validator
CLAUDE.md20k starsChanged 21 months agoMITView on GitHub
github.com/go-playground/validator/v10 — struct and field validation library based on struct tags. The module path ends in /v10; changes must preserve v10 API compatibility. Contributions require test coverage (see .github/CONTRIBUTING.md). Tests live alongside source in the package root (validatortest.go, benchmarkstest.go); run them from the repo root. Non-standard validators and translations are separate packages (./non-standard/validators, ./translations/...) and are included by ./.... The library compiles validation tags into cached execution plans, then runs them against values via reflection. Understanding three layers is enough…
We split this CLAUDE.md into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 47
When adding a new tag: register it in bakedInValidators in baked_in.go, add its description to the table in README.md, and add tests in …
- Very specific: line 70
Avoid allocations in the success path — several baked-in validators and the executor reuse pooled buffers (validate.misc, str1, str2).
- Very specific: line 76
Don't introduce new top-level exported types without need — most extension happens through Register* methods on Validate.
≈ “Common” is an estimate: at least 1 in 5 of the 25,680 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Repository
github.com/go-playground/validator/v10 — struct and field validation library based on struct tags. The module path ends in /v10; changes must preserve v10 API compatibility. Contributions require test coverage (see .github/CONTRIBUTING.md).
Commands
make test # go test -cover -race ./...
make lint # installs golangci-lint v2.0.2 if missing, then runs it
make bench # go test -run=NONE -bench=. -benchmem ./...
# Single test / subtest
go test -run TestName ./...
go test -run TestName/subtest_name ./...
# Single benchmark
go test -run=NONE -bench=BenchmarkFieldSuccess -benchmem ./...Tests live alongside source in the package root (validator_test.go, benchmarks_test.go); run them from the repo root. Non-standard validators and translations are separate packages (./non-standard/validators, ./translations/...) and are included by ./....
Architecture
The library compiles validation tags into cached execution plans, then runs them against values via reflection. Understanding three layers is enough to be productive:
1. Registration & configuration — validator_instance.go
Validate is the singleton entry point. It holds:
validations— tag →FuncCtx(the validator functions)aliases— shorthand tag → expanded tag expressioncustomFuncs—reflect.Type→ value extractor (for types likesql.NullStringor anything implementing theValuerinterface, see doc.go)structLevelFuncs— struct-level validatorstagCacheandstructCache— parsed-tag and parsed-struct caches (critical for performance;Validateis thread-safe and must be used as a singleton)
Options live in options.go (WithRequiredStructEnabled, WithPrivateFieldValidation, etc.). WithRequiredStructEnabled is the forward-compatible default users should adopt before v11.
2. Baked-in validators — baked_in.go
All built-in tags (required, email, uuid, oneof, gt, cross-field eqfield, etc.) are registered here as Func/FuncCtx receiving a FieldLevel (see field_level.go). restrictedTags enumerates names that cannot be overridden. Cross-field validators resolve the other field via fl.GetStructFieldOK* against the parent struct captured in the execution context.
Adjacent data tables:
- regexes.go, postcode_regexes.go — compiled regexps used by validators
- country_codes.go, currency_codes.go, language_codes.go — lookup tables
When adding a new tag: register it in bakedInValidators in baked_in.go, add its description to the table in README.md, and add tests in validator_test.go.
3. Execution — validator.go + cache.go
- cache.go parses struct tags into
cFieldandcTaglinked lists once per type and stores them instructCache/tagCache.cTag.typeof(typeDefault,typeOmitEmpty,typeDive,typeStructOnly,typeOr, etc.) tells the executor what to do. - validator.go contains the per-call
validatestruct (pooled viasync.Pool) and thevalidateStruct/traverseFieldmutual recursion.ns/actualNsare the accumulated dotted namespaces used in error paths;dive,keys,endkeyspush/pop through slices/maps.
Public entry points live on Validate: Struct, StructCtx, StructPartial, StructExcept, StructFiltered, Var, VarWithValue, and their Ctx variants.
Errors
errors.go defines ValidationErrors (a []FieldError) and InvalidValidationError. Per README.md and doc.go, callers type-assert err.(validator.ValidationErrors) after checking err != nil. Only InvalidValidationError signals misuse (e.g. passing a non-struct to Struct).
Struct-level & field-level custom validators
struct_level.go and field_level.go define the contexts passed to user-registered functions. Struct-level validators report errors via StructLevel.ReportError / ReportValidationErrors — they operate on the whole struct instead of a single field.
Translations — translations.go + translations/
Each locale under translations/<locale> registers a human-readable message per tag against a ut.Translator. FieldError.Translate(trans) consumes the registered TranslationFunc. When adding a new tag with a translation, add an entry in each locale package — translations are parallel packages, not a single table.
Non-standard validators — non-standard/validators/
Opt-in validators (NotBlank) users register manually. Keep niche or opinionated validators here rather than expanding baked_in.go.
Performance-sensitive areas
Validation is on the hot path for many users. When touching cache.go, validator.go, or baked_in.go hot functions:
- Avoid allocations in the success path — several baked-in validators and the executor reuse pooled buffers (
validate.misc,str1,str2). - Benchmarks in benchmarks_test.go gate regressions; run
make benchbefore and after significant changes and include results in the PR if they move.
Conventions
- Go module minimum version is pinned in go.mod; don't lower it.
- Don't introduce new top-level exported types without need — most extension happens through
Register*methods onValidate. restrictedTags(in baked_in.go) is intentionally a denylist for aliases and registrations; adding a tag with one of those names will break the parser.- Examples live under
_examples/(underscore prefix excludes them from the module build). Keep them runnable as standalonemainpackages.
Trending
More talk lately.about the whole repository
Who's talking about go-playground/validator
- spf13/viper“AutomaticEnv does not seem to pull ENV anymore. Broken since 1.19.0, working in 1.18.0”GitHub · Jul 31, 2024 · 16 reactions
- runatlantis/atlantis“Remove old dependencies”GitHub · Dec 14, 2022 · 9 reactions
- gin-gonic/gin“Undefined validation function 'exists' on field”GitHub · Nov 29, 2019 · 9 reactions
- sqlc-dev/sqlc“Add custom struct tags to params structs ”GitHub · Jan 27, 2023 · 8 reactions
- Stack Overflow“How not to allow empty fields when Unmarshalling json to a struct”Stack Overflow · Jul 5, 2019 · 6 votes
The biggest 5 of 73 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 73
Talked about on GitHub, Stack Overflow, Bluesky and the web (73 times).
On GitHub · 50
- Jul 31, 2024AutomaticEnv does not seem to pull ENV anymore. Broken since 1.19.0, working in 1.18.0 — spf13/viper16 reactions · 14 comments
- Dec 14, 2022Remove old dependencies — runatlantis/atlantis9 reactions · 5 comments
- Nov 29, 2019Undefined validation function 'exists' on field — gin-gonic/gin9 reactions · 5 comments
- Jan 27, 2023Add custom struct tags to params structs — sqlc-dev/sqlc8 reactions · 1 comment
- Aug 4, 2025Support for InvokeModelWithBidirectionalStream — aws/aws-sdk-go-v25 reactions · 8 comments
45 more on GitHub
- Dec 15, 2022basichost: netroute.New() cannot fetch RIB on Android SDK 30+ — libp2p/go-libp2p5 reactions · 1 comment
- Apr 16, 2025Feature Request: More regular releases — gin-gonic/gin4 reactions · 8 comments
- Nov 25, 2024[FEATURE]: Go validator tags support — glideapps/quicktype4 reactions · 2 comments
- Feb 6, 2023Unable to login - ERROR engine/engine.go:323 no such column: plugin_name — iris-contrib/go-admin-template4 reactions · 2 comments
- Sep 10, 2024[BUG] incompatibe with validate from github.com/go-playground/validator — swaggo/swag3 reactions · 5 comments
- May 7, 2024fix(deps): update module github.com/gin-gonic/gin to v1.11.0 - autoclosed — oapi-codegen/runtime3 reactions · 2 comments
- Jun 7, 2023import mapping broke between v1.12.0 and v1.13.0 — oapi-codegen/oapi-codegen3 reactions · 1 comment
- Dec 15, 2022netroute.New() cannot fetch RIB on Android SDK 30+ — libp2p/go-libp2p-kad-dht3 reactions · 1 comment
- Aug 2, 2022Routed host does not respect ForceDirectDial context — libp2p/go-libp2p3 reactions
- Feb 11, 2022✨ feature: custom validator — gofiber/fiber3 reactions · 6 comments
- Sep 29, 2020Custom validations are not working — gin-gonic/gin3 reactions · 1 comment
- Apr 21, 2020Validation issue — gin-gonic/gin3 reactions · 8 comments
- Dec 13, 2017Issues/Improvements found after working with gin for a while — gin-gonic/gin3 reactions · 1 comment
- Jul 24, 2026Build failure: ollama-cuda — NixOS/nixpkgs2 reactions · 8 comments
- Jun 22, 2026chore(deps): bump the minor-and-patch group across 1 directory with 5 updates — konsulin-care/konsulin-api2 reactions · 4 comments
- Jun 8, 2026chore(deps): bump the minor-and-patch group across 1 directory with 4 updates — konsulin-care/konsulin-api2 reactions · 5 comments
- Jun 3, 2026chore(deps): bump the minor-and-patch group with 2 updates — konsulin-care/konsulin-api2 reactions · 4 comments
- May 31, 2026fix(deps): update module github.com/go-playground/validator/v10 to v10.30.3 — dannybouwers/trala2 reactions · 2 comments
- May 19, 2026chore(deps): bump github.com/sigstore/timestamp-authority/v2 from 2.0.3 to 2.0.6 in /hack/tools — cloudpilot-ai/karpenter-provider-gcp2 reactions · 2 comments
- Apr 6, 2026chore(deps): bump the minor-and-patch group with 3 updates — konsulin-care/konsulin-api2 reactions · 4 comments
- Dec 15, 2025deps(go): bump github.com/go-playground/validator/v10 from 10.20.0 to 10.29.0 — karlorz/auth-gateway2 reactions · 2 comments
- Aug 29, 2025rule to detect unnecessary conditionals — revive-lint/revive2 reactions
- Jan 2, 2025proxy.golang.org, cmd/go: 403 Forbidden on go get — golang/go2 reactions · 12 comments
- Oct 20, 2024Validation only partially working. Bug or Mistake by me? — oapi-codegen/oapi-codegen2 reactions · 2 comments
- Jul 29, 2024Make use of `github.com/go-playground/validator/v10` to validate configuration — arch-go/arch-go2 reactions
- Oct 16, 2023Support `ppc64le` architecture — ollama/ollama2 reactions · 27 comments
- May 11, 2023cmd/go: implement lazy module loading in workspace mode to avoid `ambiguous import` errors — golang/go2 reactions · 4 comments
- Nov 26, 2020Really slow benchmark, am I wrong? — asaskevich/govalidatorsays it tested it2 reactions · 1 comment
- Feb 18, 2020Might be a bug in the example custom-validation — gin-gonic/examples2 reactions · 4 comments
- Oct 26, 2026chore(all): update opentelemetry-go-contrib monorepo — GoogleCloudPlatform/golang-samples1 reaction · 1 comment
- Oct 18, 2026chore(deps): bump the go-minor-patch group across 1 directory with 20 updates — Yogdunana/StarByte1 reaction
- Oct 16, 2026build(deps): bump github.com/go-playground/validator/v10 from 10.30.3 to 10.30.5 — gravitl/netmaker1 reaction · 3 comments
- Oct 10, 2026chore(deps): update go — googleapis/mcp-toolbox1 reaction · 28 comments
- Sep 28, 2026chore(deps): bump github.com/go-playground/validator/v10 from 10.30.4 to 10.30.5 — symbioticfi/relay1 reaction · 3 comments
- Sep 27, 2026chore(deps): bump the go-minor-patch group across 1 directory with 19 updates — Yogdunana/StarByte1 reaction · 1 comment
- Sep 24, 2026deps: Bump the "all-dependencies" group with 1 update across multiple ecosystems — cynative/cynative1 reaction · 1 comment
- Sep 23, 2026sloctl 0.27.0 — chenrui333/homebrew-tap1 reaction · 2 comments
- Sep 21, 2026chore(deps): bump the go-minor-patch group across 1 directory with 19 updates — Yogdunana/StarByte1 reaction · 2 comments
- Sep 20, 2026chore(deps): bump the go-minor-patch group in /backend with 20 updates — Yogdunana/StarByte1 reaction · 1 comment
- Sep 14, 2026chore(deps): bump github.com/go-playground/validator/v10 from 10.30.2 to 10.30.4 — symbioticfi/relay1 reaction · 2 comments
- Sep 13, 2026chore(deps): bump the minor-and-patch group across 1 directory with 14 updates — open-mrp/api1 reaction
- Sep 12, 2026ci: release 1.4.1 — canonical/hook-service1 reaction · 2 comments
- Sep 7, 2026deps: Bump the "all-dependencies" group with 1 update across multiple ecosystems — cynative/cynative1 reaction
- Jul 1, 2026ci(deps): bump github.com/go-playground/validator/v10 from 10.30.2 to 10.30.3 — kv-shepherd/shepherd1 reaction · 2 comments
- Jun 22, 2026chore(deps): weekly safe go updates · 7 packages — blaxel-ai/sandbox1 reaction · 1 comment
On Stack Overflow · 15
- Jul 5, 2019How not to allow empty fields when Unmarshalling json to a struct6 votes
- Mar 11, 2022Validator v10 get list of error on single field4 votes
- Apr 3, 2023Go "go-playground/validator/v10": how to register a custom error message3 votes
- Jul 3, 2020unable to validate using validator.v2 golang3 votes
- Sep 1, 2023Go Validator Translate Error Message From Map2 votes · 1 answer
10 more on Stack Overflow
- Dec 17, 2022Golang validator custom validation rules for enum2 votes · 1 answer
- Nov 2, 2022How to accept only one of multiple fields in Go Validator?2 votes
- Apr 3, 2022What's the best way to validate an untagged Go struct2 votes
- Sep 27, 2020How can go-validator check fields against their zero value?2 votes · 1 answer
- Jul 29, 2018Excessive use of map[string]interface{} in go development?2 votes
- Dec 1, 2023Graphql-go Has No Built-In Validation For Argument/Variables Passed On?1 vote
- Sep 8, 2023problems with cross field custom validation in go1 vote
- Mar 11, 2023Go-playground validator: How to validate json string1 vote
- Feb 23, 2023Baked-in validation to return an error if the request body contains a specific field in Go1 vote
- Nov 11, 2021Is there anyway to validate field of nested struct item from first struct in Golang?1 vote
On Bluesky · 4
- Sep 14, 2024github.com/go-playgroun... — @matheuslf.dev4 likes and reposts
- Apr 25, 2025📦 go-playground / validator ⭐ 18,122 (+18) 🗒 Go 💯Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and… — @github-trending.bsky.social3 likes and reposts
- Apr 26, 2025go-playground/validator 💯Go Struct and Field validation, including Cross Field, Cross Struct, ...… — @golang.activitypub.awakari.com.ap.brid.gy2 likes and reposts
- Feb 14, 2025📦 go-playground / validator ⭐ 17,485 (+11) 🗒 Go 💯Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and… — @github-trending.bsky.social1 likes and repost
On the web · 4
- Feb 12, 2024Import problem (Validator V10 / Go 1.22 / VS Code) #1229 — google.com
- May 25, 2023Custom validation on slice of embedded structs · Issue #1111 — google.com
- Feb 13, 2018How to easly test a custom validator? · Issue #342 — google.com
- Mar 1, 2015validator package - gopkg.in/go-playground/validator.v1 — pkg.go.dev
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

