pydantic

Validate and serialize Python data with Pydantic v2 BaseModel and TypeAdapter.

15|2|Updated May 23, 2026
One-click install
npx skills add https://github.com/VKirill/antigravity-for-claude-code --skill pydantic-vkirill
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pydantic
Source: https://github.com/VKirill/antigravity-for-claude-code/tree/main/skills/pydantic
Command: npx skills add https://github.com/VKirill/antigravity-for-claude-code --skill pydantic-vkirill

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Pydantic eliminates runtime bugs caused by untrusted or loosely-typed data by turning Python type hints into strict(ish) validation, coercion rules, and predictable serialization.

Core Features & Use Cases

  • Schema-backed runtime validation: Validate request/response bodies, settings, and structured tool arguments using BaseModel and TypeAdapter.
  • Precise constraints and error reporting: Use Field constraints, discriminated unions, and strict mode to reject malformed inputs and produce actionable ValidationError.errors().
  • Serialization and JSON Schema for integrations: Generate JSON Schema for OpenAPI/LLM tool definitions and control output with serializers and computed fields.

Quick Start

Use the pydantic skill to validate and serialize an HTTP request body by defining a BaseModel with Field constraints and then calling model_validate_json on the incoming JSON payload, ensuring ValidationError returns structured errors via errors() when inputs are invalid.

Frequently Asked Questions about pydantic

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate JSON request bodies using Python type hints?

Validate JSON payloads by defining a pydantic BaseModel with Field constraints, then calling model_validate_json on incoming data. Invalid inputs raise a ValidationError containing structured error details via errors().

What is the best way to generate JSON Schema for OpenAPI and LLM tool definitions?

Generate JSON Schema from pydantic BaseModel and TypeAdapter definitions to produce OpenAPI or LLM tool argument schemas. The output reflects your type hints, Field constraints, and discriminated unions for structured tool typing.

How does discriminated union validation work in pydantic v2?

Discriminated unions validate polymorphic data by using a specific Field marker to route incoming JSON to the correct BaseModel subclass. This enables precise runtime validation and clear ValidationError reporting for untrusted payloads.

Can I use Python type hints for environment variable parsing?

Parse environment variables using pydantic-settings, which maps environment configuration to Python type hints. It validates settings at runtime, applies strict coercion rules, and rejects malformed configuration inputs with actionable ValidationError details.

Why does pydantic strict mode reject loosely-typed data?

Strict mode rejects loosely-typed data to prevent unexpected coercion bugs during runtime validation. It enforces exact type matching on BaseModel fields, ensuring untrusted JSON payloads conform strictly to declared Python type hints.

How do I migrate from Pydantic v1 to v2 validation methods?

Migrate from Pydantic v1 to v2 by replacing parse_obj and dict methods with model_validate and model_dump. Update field_validator and model_validator decorators to use explicit mode parameters for correct runtime validation and serialization.