pydantic

Validate Python data structures using type hints with Pydantic v2 models.

Updated Sep 14, 2026
One-click install
npx skills add https://github.com/desarrolloainia/nuevo_circuito_mir --skill pydantic-desarrolloainia
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: pydantic
Source: https://github.com/desarrolloainia/nuevo_circuito_mir/tree/main/backend/.agents/skills/pydantic
Command: npx skills add https://github.com/desarrolloainia/nuevo_circuito_mir --skill pydantic-desarrolloainia

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pydantic, pydantic-settings.

What problem does it solve? Python applications often receive untrusted or loosely typed data from APIs, environment variables, and databases, leading to runtime errors and inconsistent state. This Skill provides patterns for enforcing type safety and validation rules at runtime using Pydantic v2. ## Core Features & Use Cases - Model Validation: Define BaseModel classes with field constraints, custom validators, and automatic type coercion for API request/response handling in FastAPI and Django. - Settings Management: Load and validate environment variables and .env files with BaseSettings, including nested configuration and multi-environment support. - ORM and Serialization Integration: Convert SQLAlchemy and Django ORM objects to validated schemas, customize JSON serialization, and generate JSON Schema for OpenAPI documentation. - Use Case: When building a FastAPI endpoint that accepts user registration data, define a UserCreate model with EmailStr and password length constraints so invalid payloads are rejected automatically with detailed error messages. ## Quick Start Ask the AI to create a Pydantic v2 model with field validators for your API request payload.

Frequently Asked Questions about pydantic

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

FAQPage Schema
How do I validate API request data with Pydantic in FastAPI?▼

Define a BaseModel subclass with typed fields and Field constraints, then use it as the parameter type in your FastAPI route. FastAPI automatically validates the request body and returns 422 errors with detailed messages for invalid payloads.

What changed in Pydantic v2 compared to v1?▼

Pydantic v2 replaces .dict() with .model_dump(), .parse_obj() with .model_validate(), @validator with @field_validator, and class Config with model_config = ConfigDict(). It also uses a Rust core for 5-50x faster validation.

Does Pydantic work with SQLAlchemy ORM models?▼

Yes, set model_config = ConfigDict(from_attributes=True) on your Pydantic schema, then call ModelSchema.model_validate(orm_object) to convert SQLAlchemy instances. This validates ORM attributes against your schema types.

How do I load environment variables with validation in Python?▼

Use BaseSettings from pydantic-settings with SettingsConfigDict specifying env_file and env_prefix. Fields are read from environment variables, type-coerced, and validated automatically, with support for nested settings using double-underscore delimiters.

Why does Pydantic strict mode reject string inputs for integer fields?▼

Strict mode disables type coercion, so a string like "42" is not converted to an integer. Enable it globally with ConfigDict(strict=True) or per-field with Field(strict=True) when you need exact type matching.

When should I use field_validator versus model_validator?▼

Use field_validator for single-field checks like format or range rules, and model_validator for cross-field logic such as ensuring end_date is after start_date. Model validators run in before, after, or wrap modes.