Create Pydantic models following the multi-model pattern with Base, Create, Update, Response, and InDB variants. Use when defining API request/response schemas, database models, or data validation in Python applications using Pydantic v2.
Add this skill
npx mdskills install sickn33/pydantic-models-pyClear multi-model pattern guidance but lacks trigger conditions and step-by-step agent instructions
1---2name: pydantic-models-py3description: Create Pydantic models following the multi-model pattern with Base, Create, Update, Response, and InDB variants. Use when defining API request/response schemas, database models, or data validation in Python applications using Pydantic v2.4---56# Pydantic Models78Create Pydantic models following the multi-model pattern for clean API contracts.910## Quick Start1112Copy the template from [assets/template.py](assets/template.py) and replace placeholders:13- `{{ResourceName}}` → PascalCase name (e.g., `Project`)14- `{{resource_name}}` → snake_case name (e.g., `project`)1516## Multi-Model Pattern1718| Model | Purpose |19|-------|---------|20| `Base` | Common fields shared across models |21| `Create` | Request body for creation (required fields) |22| `Update` | Request body for updates (all optional) |23| `Response` | API response with all fields |24| `InDB` | Database document with `doc_type` |2526## camelCase Aliases2728```python29class MyModel(BaseModel):30 workspace_id: str = Field(..., alias="workspaceId")31 created_at: datetime = Field(..., alias="createdAt")3233 class Config:34 populate_by_name = True # Accept both snake_case and camelCase35```3637## Optional Update Fields3839```python40class MyUpdate(BaseModel):41 """All fields optional for PATCH requests."""42 name: Optional[str] = Field(None, min_length=1)43 description: Optional[str] = None44```4546## Database Document4748```python49class MyInDB(MyResponse):50 """Adds doc_type for Cosmos DB queries."""51 doc_type: str = "my_resource"52```5354## Integration Steps55561. Create models in `src/backend/app/models/`572. Export from `src/backend/app/models/__init__.py`583. Add corresponding TypeScript types59
Full transparency — inspect the skill content before installing.