
Pydantic
- 159 installs
- 7 repo stars
- Updated January 25, 2026
- jiatastic/open-python-skills
Define validated Python models, settings, and request/response schemas with Pydantic v2 patterns for APIs, CLIs, and agent tool I/O.
About
The pydantic skill teaches Claude Code to apply Pydantic v2 correctly for Python backends, including model design, validation, settings management, JSON schema export, and robust parsing for APIs, CLIs, and agent interfaces.
- Models BaseModel fields with correct validators
- Uses Field, model_config, and typed settings
- Maps JSON schema for APIs and agent tools
- Handles unions, generics, and nested structures
- Improves error messages for invalid inputs
Pydantic by the numbers
- 159 all-time installs (skills.sh)
- +4 installs in the week ending Aug 2, 2026 (Skillselion tracking)
- Ranked #74 of 290 Python skills by installs in the Skillselion catalog
- Data as of Aug 2, 2026 (Skillselion catalog sync)
npx skills add https://github.com/jiatastic/open-python-skills --skill pydanticAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 159 |
|---|---|
| repo stars | ★ 7 |
| Last updated | January 25, 2026 |
| Repository | jiatastic/open-python-skills ↗ |
What it does
Define validated Python models, settings, and request/response schemas with Pydantic v2 patterns for APIs, CLIs, and agent tool I/O.
Files
pydantic
Type-driven validation and serialization using Pydantic models.
Overview
Pydantic validates data using Python type hints and provides rich serialization via model_dump() and JSON schema output.
When to Use
- Validating request/response payloads
- Normalizing untrusted input
- Generating JSON schema for docs
Quick Start
uv pip install pydanticfrom pydantic import BaseModel
class User(BaseModel):
id: int
email: str
user = User(id=1, email="a@example.com")Core Patterns
1. Typed fields: strict schema definitions. 2. Field validators: custom validation logic. 3. Model validators: cross-field checks. 4. Serialization: model_dump() and model_dump_json(). 5. Settings: environment-driven config via BaseSettings.
Example: field_validator
from pydantic import BaseModel, field_validator
class Model(BaseModel):
name: str
@field_validator("name")
@classmethod
def ensure_not_empty(cls, v: str):
if not v:
raise ValueError("name required")
return vExample: model_validate + model_dump
from pydantic import BaseModel
class Model(BaseModel):
foo: int
model = Model.model_validate({"foo": 1})
print(model.model_dump())Troubleshooting
- Coercion surprises: use strict types if needed
- Slow validators: keep them minimal
- Mutable defaults: use
default_factory
References
- https://docs.pydantic.dev/
Pydantic Pitfalls
Common Issues
- Silent coercion: unexpected type casting
- Slow validators: heavy logic in validation
- Mutable defaults: shared state
Fix Patterns
- Use strict types where needed
- Keep validators fast and simple
- Use
Field(default_factory=...)
Example: default_factory
from pydantic import BaseModel, Field
class Model(BaseModel):
tags: list[str] = Field(default_factory=list)Pydantic Quickstart
Install
uv pip install pydanticMinimal Model
from pydantic import BaseModel, EmailStr
class User(BaseModel):
email: EmailStr
age: int
user = User(email="a@example.com", age=30)Serialization
user.model_dump()
user.model_dump_json()Validators
from pydantic import field_validator
class User(BaseModel):
age: int
@field_validator("age")
@classmethod
def validate_age(cls, v: int):
if v < 0:
raise ValueError("age must be >= 0")
return v