#validation
40 snippets tagged with #validation
Environment Variable Validator
Validates required environment variables at startup and returns a typed config object or throws with missing keys.
Best for: App startup validation
Express Zod Request Validation
Validate Express request body, params, and query with Zod schemas via reusable middleware.
Best for: API input validation
Request Validation Schema Builder
Build a lightweight request validation layer with type inference for API endpoints.
Best for: API request body validation
Schema Validation with Zod-like Patterns
Build a minimal schema validation library inspired by Zod using TypeScript type inference.
Best for: API request validation
Type-Safe Configuration Loader
Load and validate configuration from environment variables with type coercion and required field checks.
Best for: Application configuration management
Environment Secrets Loader
Loads and validates required environment variables at startup and throws meaningful errors for missing ones.
Best for: Application bootstrap
OpenAPI Request Validator
Validates incoming request body against a JSON schema derived from an OpenAPI spec.
Best for: API input validation
useFormValidation Hook
Lightweight form validation hook with field-level errors, touched tracking, and submit handling.
Best for: Contact forms
React Form Validation Hook
A type-safe form validation hook with field-level errors, dirty tracking, and submit handling.
Best for: Type-safe form handling without libraries
Controlled Form Component
A reusable controlled form pattern with field-level validation and submission handling.
Best for: Login forms
Type-Safe API Route Handler
Next.js App Router route handler with input validation, typed responses, and proper error handling.
Best for: CRUD API endpoints
Server Action with Form Validation
Next.js Server Action handling form submissions with validation, error messages, and redirect on success.
Best for: Blog post creation
Environment Variable Validation
Validate required environment variables at build time with type-safe access and descriptive errors.
Best for: App startup checks
Next.js Server Actions with Forms
Use Server Actions for form handling with validation, optimistic updates, and error handling.
Best for: Form submissions without API routes
Form with Server Action Validation
Build forms using Next.js server actions with server-side validation, error handling, and useActionState.
Best for: Contact form submissions
Server Action Validation with Zod
Validate form data in server actions using Zod schemas with type-safe error handling.
Best for: contact forms
File Upload with Server Action
Handle file uploads using server actions with validation, size limits, and storage.
Best for: image uploads
Environment Variable Validation with Zod
Validate environment variables at build time using Zod to catch misconfigurations early.
Best for: build-time validation
Dataclass with Validation
Python dataclass with __post_init__ field validation, type coercion, and descriptive error messages.
Best for: Data transfer objects
Pydantic v2 Model Patterns
Define and validate data models with Pydantic v2 using field validators, computed fields, and serialization.
Best for: API request/response models
Dataclasses with Post-Init Processing
Use Python dataclasses with __post_init__ for computed fields, validation, and default factories.
Best for: Domain models
Dataclass with __post_init__ Validation
Add custom validation to Python dataclasses using __post_init__.
Best for: Input validation
Data Validation with Pydantic Models
Define and validate data models with Pydantic for type-safe Python applications.
Best for: API request validation
LLM JSON Output Parser
Parse and validate JSON responses from LLMs with retry logic and schema enforcement using Zod.
Best for: Extracting structured data from LLM responses
Output Guardrails for LLM Responses
Validate and sanitize LLM outputs to prevent hallucination and injection.
Best for: Safety filtering
Text-to-SQL with Validation Safety
Convert natural language to SQL with LLM and validate queries before execution for safety.
Best for: safe NL2SQL
Data Validation with Pydantic
Validate and parse data records using Pydantic models with custom validators and error reporting.
Best for: Validating incoming data before warehouse loading
Data Quality Testing with Expectations
Define and run data quality expectations for automated validation in data pipelines.
Best for: Automated data quality gates in pipelines
Great Expectations Data Quality Suite
Define and run a Great Expectations validation suite to catch data quality issues early.
Best for: CI data validation
Pandera DataFrame Schema Validation
Use Pandera to validate DataFrame schemas with type checks, value constraints, and custom checks.
Best for: pipeline input validation
Pydantic Models for ETL Validation
Parse and validate raw JSON records against Pydantic models before inserting into a database.
Best for: input validation
Pandas Merge with Validation
Use merge() validate parameter to catch unexpected many-to-many or missing key issues in joins.
Best for: data integrity
Pandera @check_input and @check_output
Decorate pipeline functions with Pandera schema validators to enforce input and output contracts.
Best for: contract testing
Spring Boot — Custom Validator Annotation
Create custom validation annotations with ConstraintValidator for domain-specific field validation.
Best for: Domain-specific input validation
Java Regex — Pattern Matching Examples
Common regex patterns with Pattern and Matcher: email, URL, phone, extraction, and replacement.
Best for: Input validation for emails, URLs, and phone numbers
Preconditions — require, check, and error
Validate inputs and state with Kotlin preconditions: require, check, error, and custom assertions.
Best for: Input validation at function boundaries
Kotlin Regex Pattern Matching
Use Kotlin regex for validation, extraction, replacing, and destructuring with named groups.
Best for: Input validation for forms and APIs
Kotlin Error Handling Patterns
Comprehensive error handling: sealed result types, validated aggregation, and railway-oriented programming.
Best for: Form validation with error accumulation
Error Accumulation with Validated
Accumulate multiple validation errors instead of failing fast using Cats Validated and custom validators.
Best for: Form validation with all errors
Refined and Constrained Types
Create constrained types with validation: non-empty strings, bounded numbers, and validated domain types.
Best for: Domain type validation