🤖 AI Summary
Godantic is a new Go library (Show HN) that brings Pydantic‑style, tagless runtime validation plus automatic JSON Schema generation to Go projects—targeting LLM integrations, OpenAPI spec generation, and general structured-data validation. Instead of struct tags it uses per‑field methods that return FieldOptions[T] composed from validators (Required, Min/Max, MinLen/MaxLen, Regex, Email, URL, OneOf, Default, custom Validate, etc.). You get a type-safe API with Go generics (NewValidator[T] and Validate), IDE/test/debug friendliness, and unit-testable validation logic as single source of truth for both runtime checks and schema output.
Technically notable: Godantic supports union patterns (anyOf) and discriminated unions (oneOf with OpenAPI 3.1 discriminator mappings) using Go’s any and interfaces, generates proper $defs and can produce a flattened schema layout required by LLM providers (OpenAI, Gemini, Anthropic). It handles nested/embedded structs, pointers, slices, maps, treats zero values as “not set” for required checks, and includes all constraints automatically in the generated JSON Schema. The common workflow is defining types and Field methods, generating (flattened) schema to send to an LLM, then validating the parsed response to catch missing fields, type errors, out‑of‑range values or typos before business logic runs—making LLM-driven systems and OpenAPI clients more robust and interoperable.
Loading comments...
login to comment
loading comments...
no comments yet