--- name: valibot-best-practices description: Valibot conventions for owned wire contracts and explicit validation outcomes. Use when defining, debugging, or reviewing schemas or parsing untrusted data. --- # Valibot Best Practices > [!IMPORTANT] > Apply the `architecture:code-style` principles to Valibot: treat a schema as the owned contract at an untrusted data boundary that defines accepted wire values, produces trusted domain values, and makes invalid input an explicit, intentional outcome. ## Library Sources - GitHub repository ID: `open-circle/valibot` - Context7 library ID: `/open-circle/valibot` - DeepWiki repository ID: `open-circle/valibot` Use Context7 for current documentation and DeepWiki for implementation details. ## References Read the references that apply to the current task before defining or reviewing Valibot schemas and parsing code. 1. Make schemas the owned, trusted contract for wire data. - [Make a schema that proves a domain shape the single source of truth](./references/schema-ownership.md) and infer a type when needed, exposing the schema/type pair only as an intentional public contract. - [Keep constructors under the `v` namespace](./references/namespace-imports.md) so library ownership stays clear and import forms remain consistent. 2. Encode exact wire semantics inside the schema. - [Encode missing and `null` wire semantics](./references/wire-nullability.md) with the matching wrapper rather than whichever wrapper compiles. - [Dispatch literal-tagged alternatives with `v.variant`](./references/discriminated-variants.md) so Valibot selects and reports the failing tagged branch. - [Define defaults with exact domain meaning in the schema](./references/schema-defaults.md); do not use a default to reinterpret malformed input. - [Transform normalized wire input inside the schema](./references/schema-transformations.md) with matching built-ins so consumers receive the intended domain values. 3. Make validation failure match the boundary contract. - [Choose the parse API from the failure contract](./references/parse-failure-contracts.md): abort a violated invariant or return an expected branch, reusing immutable schemas and parser functions. - [Preserve expected validation issues](./references/validation-failure-preservation.md) instead of substituting an invented `null` or empty value.