pydantic-models-py

Create Pydantic v2 models with Base, Create, Update, Response, and InDB variants.

Updated Apr 12, 2026
One-click install
npx skills add https://github.com/davidrrowley/CortexYouV3 --skill pydantic-models-py-davidrrowley
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pydantic-models-py
Source: https://github.com/davidrrowley/CortexYouV3/tree/main/.agents/skills/pydantic-models-py
Command: npx skills add https://github.com/davidrrowley/CortexYouV3 --skill pydantic-models-py-davidrrowley

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve?

Provide a consistent, testable pattern for defining Pydantic models that reduces duplication, enforces validation, and ensures stable API request/response and database document contracts across Python backends.

Core Features & Use Cases

  • Multi-Model Pattern: Produces Base, Create, Update, Response, and InDB model variants to separate concerns for input validation, partial updates, API responses, and storage.
  • Pydantic v2 Guidance: Uses modern v2 patterns such as model_config/ConfigDict, populate_by_name, from_attributes, and field_validator/model_validator for robust validation and aliasing.
  • Database & Integration: Includes doc_type conventions for Cosmos DB partitioning and examples for exporting models and aligning TypeScript types for front-end contracts.
  • Use Case: Ideal for backend engineers building REST/GraphQL endpoints that require precise input validation, consistent response shapes, and straightforward persistence mappings.

Quick Start

Create Pydantic models for a new resource by copying assets/template.py, replacing {{ResourceName}} and {{resource_name}} with your resource names, and adding the models to src/backend/app/models/.

Frequently Asked Questions about pydantic-models-py

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

FAQPage Schema
How do I structure Pydantic models for API request validation and response serialization?

Pydantic v2 handles API request validation using model_config with populate_by_name and from_attributes. It also uses field_validator and model_validator methods to enforce robust data constraints and aliasing for incoming payloads.

How do I create Pydantic models for Cosmos DB document storage?

To create Pydantic models for Cosmos DB, copy the template asset, replace the resource name placeholders, and place the file in your backend models directory. This generates the Base, Create, Update, Response, and InDB variants automatically.

What is the best way to reduce duplication across Pydantic API schemas?

The best way to reduce duplication across Pydantic API schemas is the multi-model pattern. It establishes a Base model and derives Create, Update, Response, and InDB variants, ensuring stable contracts without repeating field definitions.

Does this Pydantic multi-model pattern align with TypeScript types for front-end contracts?

Yes, the multi-model pattern supports Pydantic v2. It leverages modern features including ConfigDict for model_config, populate_by_name for aliasing, from_attributes for ORM mode, and field_validator for custom validation logic.