---
name: "pydantic-v2-serialization-validators"
description: "Validate complex nested data models and serialize JSON at Rust speeds using Pydantic v2."
metadata:
  author: "Pydantic"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "write pydantic v2 validator"
  - "field_validator pydantic"
  - "computed_field pydantic"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Pydantic v2 Rust Core Validation & Field Validators

Implements Pydantic v2: BaseModel, field_validator, model_validator (mode='before' / 'after'), Field constraints (gt, regex), computed_field properties, and high-speed model_dump_json() serialization.

## When to Invoke
Invoke this skill whenever you need to:
- write pydantic v2 validator
- field_validator pydantic
- computed_field pydantic

## Execution SOP & Rules
1. Define model: class UserSchema(BaseModel): model_config = ConfigDict(from_attributes=True).
2. Add field validator: @field_validator('password') @classmethod def validate_pw(cls, v: str): ... return v.
3. Add root validator: @model_validator(mode='after') def check_passwords_match(self): ... return self.
4. Export data: model.model_dump(exclude_unset=True) or model.model_dump_json().

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
