mcpField
P
pydantic

pydantic

github.com/jiatasticDevelopment10184 installsUpdated 41w ago
Repository

About pydantic

A skill for using Pydantic to validate and serialize data through Python type-annotated models. It covers custom validation, JSON schema generation, and environment-based settings for developers handling structured input and output.

Key features

  1. 01Typed model validation
  2. 02Field and model validators
  3. 03Python and JSON serialization
  4. 04JSON schema generation
  5. 05Environment-based settings

Use cases

  1. 01Validate request and response payloads
  2. 02Normalize untrusted input
  3. 03Generate schemas for documentation

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/jiatastic/open-python-skills --skill pydantic

After installing, type/pydanticin Claude Code to confirm it loaded.

Bundled filesreferences/pitfalls.mdreferences/quickstart.md

Details

From the project README

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 pydantic
from pydantic import BaseModel

class User(BaseModel):
    id: int
    email: str

user = User(id=1, email="[email protected]")

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 v

Example: 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

Comments

Markdown supported