Data Validator
Generates precise validation schemas — JSON Schema, Pydantic models, Zod schemas, TypeScript types, or database constraints — from sample data, descriptions, or existing types to enforce data contracts at API boundaries, configuration files, and service interfaces.
When to Use
- User provides sample JSON/YAML and asks to "create a schema for this"
- API endpoints accept unvalidated request bodies
- User asks to generate Pydantic models, Zod schemas, or JSON Schema
- TypeScript types exist but need runtime validation added
- Configuration files need validation before the app starts
- Data pipelines need input/output contracts enforced
- User asks to convert between schema formats (JSON Schema → Zod, etc.)
Process
Identify the target schema format from context or ask:
- JSON Schema (draft-07 / 2020-12) — language-agnostic, OpenAPI, configs
- Pydantic v2 — Python, FastAPI, data validation + serialization
- Zod — TypeScript/JavaScript, runtime type-safe validation
- Yup — JavaScript, form validation, React integrations
- Joi — Node.js, server-side validation
- TypeBox — TypeScript, JSON Schema + TypeScript types in sync
- class-validator + class-transformer — NestJS, decorators
- OpenAPI requestBody schema — API spec validation
Analyze the input (sample data, description, or existing type):
- Identify all fields and their data types
- Infer required vs. optional fields from multiple samples or description
- Determine string formats: email, UUID, URL, date-time, ISO 8601
- Determine numeric constraints: min, max, integer vs. float
- Identify array item types and length constraints
- Identify enum/union types from repeated patterns
- Note nullable vs. undefined vs. missing field semantics
Design the schema:
- Use the most precise constraints possible (don't use
string when email or uuid is more accurate)
- Mark required fields explicitly; make optional fields clear
- Add minimum/maximum for numbers where semantics imply bounds (age: 0–150, port: 1–65535)
- Use
minLength/maxLength for strings with natural bounds
- Use
additionalProperties: false in JSON Schema for strict objects
- Use discriminated unions for polymorphic types
Add validation messages where the framework supports it (Zod, Yup, Pydantic):
- Provide human-readable error messages for each constraint
- Include field name and the constraint that failed
Generate the schema with documentation:
- Add inline comments or field-level descriptions
- Include example values where supported
If converting between formats, ensure semantic equivalence and note any features not supported in the target format.
Output Format
Pydantic v2 (Python)
from pydantic import BaseModel, Field, EmailStr, field_validator
from typing import Optional
from uuid import UUID
from datetime import datetime
from enum import Enum
class UserRole(str, Enum):
admin = "admin"
viewer = "viewer"
editor = "editor"
class CreateUserRequest(BaseModel):
model_config = {"str_strip_whitespace": True}
name: str = Field(min_length=1, max_length=100, description="Full display name")
email: EmailStr = Field(description="Primary email address")
role: UserRole = Field(default=UserRole.viewer)
age: Optional[int] = Field(default=None, ge=0, le=150)
@field_validator('name')
@classmethod
def name_must_not_be_blank(cls, v: str) -> str:
if not v.strip():
raise ValueError('Name must not be blank or whitespace only')
return v
Zod (TypeScript)
import { z } from 'zod';
const UserRole = z.enum(['admin', 'viewer', 'editor']);
export const CreateUserSchema = z.object({
name: z.string().min(1, 'Name is required').max(100, 'Name too long').trim(),
email: z.string().email('Invalid email address'),
role: UserRole.default('viewer'),
age: z.number().int().min(0).max(150).optional(),
});
export type CreateUserRequest = z.infer<typeof CreateUserSchema>;
Examples
Example Input
{
"orderId": "ord_abc123",
"customerId": "cus_xyz456",
"items": [
{ "productId": "prod_001", "quantity": 2, "unitPrice": 29.99 }
],
"shippingAddress": {
"street": "123 Main St",
"city": "Springfield",
"country": "US",
"postalCode": "62701"
},
"createdAt": "2024-03-15T10:30:00Z"
}
Example Output (JSON Schema)
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["orderId", "customerId", "items", "shippingAddress", "createdAt"],
"additionalProperties": false,
"properties": {
"orderId": { "type": "string", "pattern": "^ord_[a-z0-9]+$" },
"customerId": { "type": "string", "pattern": "^cus_[a-z0-9]+$" },
"items": {
"type": "array", "minItems": 1,
"items": {
"type": "object",
"required": ["productId", "quantity", "unitPrice"],
"additionalProperties": false,
"properties": {
"productId": { "type": "string" },
"quantity": { "type": "integer", "minimum": 1 },
"unitPrice": { "type": "number", "minimum": 0, "exclusiveMinimum": 0 }
}
}
},
"shippingAddress": {
"type": "object",
"required": ["street", "city", "country", "postalCode"],
"properties": {
"street": { "type": "string", "minLength": 1 },
"city": { "type": "string", "minLength": 1 },
"country": { "type": "string", "pattern": "^[A-Z]{2}$" },
"postalCode": { "type": "string" }
}
},
"createdAt": { "type": "string", "format": "date-time" }
}
}
Boundaries
- Do NOT infer required fields from a single sample — ask for multiple examples or an authoritative description to distinguish required from optional.
- Do NOT use
any / object / unknown types without noting that they weaken the contract.
- Do NOT generate validation that strips or transforms data unless the user explicitly requests coercion (i.e., prefer strict validation over silent mutation).
- If converting between schema formats, note any expressiveness gaps (e.g., JSON Schema
contentMediaType has no direct Zod equivalent).
- Do NOT generate schemas that accept user-controlled data without length constraints — always bound strings and arrays.
- Pydantic v2 syntax differs significantly from v1 — confirm the version before generating code.
1---2name: data-validator3description: Generates JSON Schema, Pydantic models, or Zod schemas from sample data or descriptions to enforce data contracts. Invoke when asked to validate data, create a schema, define a data model, generate Pydantic or Zod types, or enforce a data contract.4---56# Data Validator78Generates precise validation schemas — JSON Schema, Pydantic models, Zod schemas, TypeScript types, or database constraints — from sample data, descriptions, or existing types to enforce data contracts at API boundaries, configuration files, and service interfaces.910## When to Use1112- User provides sample JSON/YAML and asks to "create a schema for this"13- API endpoints accept unvalidated request bodies14- User asks to generate Pydantic models, Zod schemas, or JSON Schema15- TypeScript types exist but need runtime validation added16- Configuration files need validation before the app starts17- Data pipelines need input/output contracts enforced18- User asks to convert between schema formats (JSON Schema → Zod, etc.)1920## Process21221. **Identify the target schema format** from context or ask:23 - **JSON Schema (draft-07 / 2020-12)** — language-agnostic, OpenAPI, configs24 - **Pydantic v2** — Python, FastAPI, data validation + serialization25 - **Zod** — TypeScript/JavaScript, runtime type-safe validation26 - **Yup** — JavaScript, form validation, React integrations27 - **Joi** — Node.js, server-side validation28 - **TypeBox** — TypeScript, JSON Schema + TypeScript types in sync29 - **class-validator + class-transformer** — NestJS, decorators30 - **OpenAPI requestBody schema** — API spec validation31322. **Analyze the input** (sample data, description, or existing type):33 - Identify all fields and their data types34 - Infer required vs. optional fields from multiple samples or description35 - Determine string formats: email, UUID, URL, date-time, ISO 860136 - Determine numeric constraints: min, max, integer vs. float37 - Identify array item types and length constraints38 - Identify enum/union types from repeated patterns39 - Note nullable vs. undefined vs. missing field semantics40413. **Design the schema**:42 - Use the most precise constraints possible (don't use `string` when `email` or `uuid` is more accurate)43 - Mark required fields explicitly; make optional fields clear44 - Add minimum/maximum for numbers where semantics imply bounds (age: 0–150, port: 1–65535)45 - Use `minLength`/`maxLength` for strings with natural bounds46 - Use `additionalProperties: false` in JSON Schema for strict objects47 - Use discriminated unions for polymorphic types48494. **Add validation messages** where the framework supports it (Zod, Yup, Pydantic):50 - Provide human-readable error messages for each constraint51 - Include field name and the constraint that failed52535. **Generate the schema with documentation**:54 - Add inline comments or field-level descriptions55 - Include example values where supported56576. **If converting between formats**, ensure semantic equivalence and note any features not supported in the target format.5859## Output Format6061### Pydantic v2 (Python)62```python63from pydantic import BaseModel, Field, EmailStr, field_validator64from typing import Optional65from uuid import UUID66from datetime import datetime67from enum import Enum6869class UserRole(str, Enum):70 admin = "admin"71 viewer = "viewer"72 editor = "editor"7374class CreateUserRequest(BaseModel):75 model_config = {"str_strip_whitespace": True}7677 name: str = Field(min_length=1, max_length=100, description="Full display name")78 email: EmailStr = Field(description="Primary email address")79 role: UserRole = Field(default=UserRole.viewer)80 age: Optional[int] = Field(default=None, ge=0, le=150)8182 @field_validator('name')83 @classmethod84 def name_must_not_be_blank(cls, v: str) -> str:85 if not v.strip():86 raise ValueError('Name must not be blank or whitespace only')87 return v88```8990### Zod (TypeScript)91```ts92import { z } from 'zod';9394const UserRole = z.enum(['admin', 'viewer', 'editor']);9596export const CreateUserSchema = z.object({97 name: z.string().min(1, 'Name is required').max(100, 'Name too long').trim(),98 email: z.string().email('Invalid email address'),99 role: UserRole.default('viewer'),100 age: z.number().int().min(0).max(150).optional(),101});102103export type CreateUserRequest = z.infer<typeof CreateUserSchema>;104```105106## Examples107108### Example Input109```json110{111 "orderId": "ord_abc123",112 "customerId": "cus_xyz456",113 "items": [114 { "productId": "prod_001", "quantity": 2, "unitPrice": 29.99 }115 ],116 "shippingAddress": {117 "street": "123 Main St",118 "city": "Springfield",119 "country": "US",120 "postalCode": "62701"121 },122 "createdAt": "2024-03-15T10:30:00Z"123}124```125126### Example Output (JSON Schema)127```json128{129 "$schema": "https://json-schema.org/draft/2020-12/schema",130 "type": "object",131 "required": ["orderId", "customerId", "items", "shippingAddress", "createdAt"],132 "additionalProperties": false,133 "properties": {134 "orderId": { "type": "string", "pattern": "^ord_[a-z0-9]+$" },135 "customerId": { "type": "string", "pattern": "^cus_[a-z0-9]+$" },136 "items": {137 "type": "array", "minItems": 1,138 "items": {139 "type": "object",140 "required": ["productId", "quantity", "unitPrice"],141 "additionalProperties": false,142 "properties": {143 "productId": { "type": "string" },144 "quantity": { "type": "integer", "minimum": 1 },145 "unitPrice": { "type": "number", "minimum": 0, "exclusiveMinimum": 0 }146 }147 }148 },149 "shippingAddress": {150 "type": "object",151 "required": ["street", "city", "country", "postalCode"],152 "properties": {153 "street": { "type": "string", "minLength": 1 },154 "city": { "type": "string", "minLength": 1 },155 "country": { "type": "string", "pattern": "^[A-Z]{2}$" },156 "postalCode": { "type": "string" }157 }158 },159 "createdAt": { "type": "string", "format": "date-time" }160 }161}162```163164## Boundaries165166- Do NOT infer required fields from a single sample — ask for multiple examples or an authoritative description to distinguish required from optional.167- Do NOT use `any` / `object` / `unknown` types without noting that they weaken the contract.168- Do NOT generate validation that strips or transforms data unless the user explicitly requests coercion (i.e., prefer strict validation over silent mutation).169- If converting between schema formats, note any expressiveness gaps (e.g., JSON Schema `contentMediaType` has no direct Zod equivalent).170- Do NOT generate schemas that accept user-controlled data without length constraints — always bound strings and arrays.171- Pydantic v2 syntax differs significantly from v1 — confirm the version before generating code.