pydantic

Validate and coerce Python data into typed Pydantic v2 models.

Updated Feb 25, 2023
One-click install
npx skills add https://github.com/GeorgeKuzora/dotfiles --skill pydantic-georgekuzora
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pydantic
Source: https://github.com/GeorgeKuzora/dotfiles/tree/main/dot_config/opencode/skills/pydantic
Command: npx skills add https://github.com/GeorgeKuzora/dotfiles --skill pydantic-georgekuzora

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Pydantic provides a robust framework for validating and parsing complex Python data into typed models at runtime, reducing boilerplate and preventing invalid data from propagating through applications.

Core Features & Use Cases

  • Runtime validation and coercion of Python data into BaseModel schemas.
  • Nested models, validators, and model validators for complex business rules.
  • Serialization to and from JSON, dicts, and JSON Schema generation for APIs and config.
  • Seamless integration with FastAPI, Django, and other frameworks for request/response validation and settings loading.

Quick Start

Create a simple Pydantic model and validate an input payload to observe automatic type coercion and error messages.

Frequently Asked Questions about pydantic

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

FAQPage Schema
How do I validate Python data into typed models at runtime?

Runtime data validation in Python uses BaseModel schemas to coerce and parse input payloads into typed models, preventing invalid data from propagating through your application. This Skill supports Pydantic v2 features like model_validate and model_dump for this exact task.

Can I use Pydantic v2 with FastAPI for API payload validation?

Yes, Pydantic v2 integrates seamlessly with FastAPI and Django for API payload validation. It validates request and response data using BaseModel schemas, handling nested models and model_validator rules to enforce complex business logic across web apps and CLIs.

What is the best way to generate JSON Schema from Python data models?

Generating JSON Schema from Python data models is handled automatically by defining BaseModel schemas with field validators. This process serializes your typed models into standard JSON Schema, providing structured configuration loading and API documentation outputs.

How do I serialize Python data models to JSON and dicts?

Serializing Python data models to JSON and dicts is performed using the model_dump method in Pydantic v2. This function transforms validated BaseModel instances into standard dictionary or JSON formats, enabling straightforward data export and API response generation.

Does Pydantic v2 support nested models and custom validators?

Yes, Pydantic v2 supports nested models and custom validators for complex business rules. You can apply field_validator and model_validator decorators to BaseModel schemas to enforce specific data coercion and validation logic across nested structures.

When do I need runtime validation for Python configuration loading?

Runtime validation for Python configuration loading is needed when parsing external data into typed models to prevent invalid configurations. Using BaseModel schemas with model_config ensures that configuration data is strictly coerced and validated before application startup.