GitHub Copilot ChatGPT Claude Codex CLI Cursor opencode Skill Text

pydantic-models-py

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.

Ciza · 0 points · 25 views 0 listing impressions 0 install-command copies
Virus-scanned Reviewed automatically before listing.

Full trust report

Download microsoft-skills-.github_plugins_azure-sdk-python_skills_pydantic-models-py-e58528d.zip · 2 KB
Part of microsoft/skills — 195 skills

Install

skills CLI npx skills add https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-python/skills/pydantic-models-py
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install microsoft-skills@llmmart
Git git clone https://github.com/microsoft/skills.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole microsoft/skills collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

Pydantic Models

Create Pydantic models following the multi-model pattern for clean API contracts.

Quick Start

Copy the template from assets/template.py and replace placeholders:

  • {{ResourceName}} → PascalCase name (e.g., Project)
  • {{resource_name}} → snake_case name (e.g., project)

Multi-Model Pattern

Model Purpose
Base Common fields shared across models
Create Request body for creation (required fields)
Update Request body for updates (all optional)
Response API response with all fields
InDB Database document with doc_type

camelCase Aliases

from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field

class MyModel(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    workspace_id: str = Field(..., alias="workspaceId")
    created_at: datetime = Field(..., alias="createdAt")

Optional Update Fields

class MyUpdate(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    name: Optional[str] = Field(None, min_length=1)
    description: Optional[str] = None

Database Document

class MyInDB(MyResponse):
    doc_type: str = "my_resource"

Integration Steps

  1. Create models in src/backend/app/models/
  2. Export from src/backend/app/models/__init__.py
  3. Add corresponding TypeScript types

Reference Files

File Contents
references/capabilities.md Additional non-hero capabilities, operation-group coverage, and production checklists.
Files (skills)
  • assets
    • template.py 1.5 KB
      """{{ResourceName}} models following the multi-model pattern."""
      
      from datetime import datetime
      from typing import Optional
      from pydantic import BaseModel, ConfigDict, Field
      
      
      class {{ResourceName}}Base(BaseModel):
          """Common fields shared by all {{resource_name}} models."""
      
          model_config = ConfigDict(populate_by_name=True)
      
          name: str = Field(..., min_length=1, max_length=200)
          description: Optional[str] = Field(None, max_length=2000)
      
      
      class {{ResourceName}}Create({{ResourceName}}Base):
          """Request body for creating a {{resource_name}}."""
      
          workspace_id: str = Field(..., alias="workspaceId")
      
      
      class {{ResourceName}}Update(BaseModel):
          """Request body for partial updates (all fields optional)."""
      
          model_config = ConfigDict(populate_by_name=True)
      
          name: Optional[str] = Field(None, min_length=1, max_length=200)
          description: Optional[str] = Field(None, max_length=2000)
      
      
      class {{ResourceName}}({{ResourceName}}Base):
          """API response with all {{resource_name}} fields."""
      
          model_config = ConfigDict(populate_by_name=True, from_attributes=True)
      
          id: str
          workspace_id: str = Field(..., alias="workspaceId")
          author_id: str = Field(..., alias="authorId")
          created_at: datetime = Field(..., alias="createdAt")
          updated_at: Optional[datetime] = Field(None, alias="updatedAt")
      
      
      class {{ResourceName}}InDB({{ResourceName}}):
          """Database document with doc_type for Cosmos DB queries."""
      
          doc_type: str = "{{resource_name}}"
      
  • references
    • capabilities.md 1.1 KB
      # pydantic-models-py capability coverage
      
      **SDK/package**: `pydantic`
      
      This reference captures additional non-hero capabilities and API breadth so the main `SKILL.md` can stay focused on copy/paste hero flows.
      
      ## Hero scenarios covered in SKILL.md
      
      - `Quick Start`
      - `Multi-Model Pattern`
      - `camelCase Aliases`
      - `Optional Update Fields`
      
      ## Important non-hero scenarios to include when needed
      
      - `Database Document`
      - `Integration Steps`
      
      ## API breadth checklist
      
      - Verify field validators (`@field_validator`) and model validators (`@model_validator`) cover all required constraints.
      - Confirm serialization behavior: use `model_dump(mode="json")` for JSON-safe output and `model_dump(exclude_unset=True)` for partial updates.
      - Include schema generation examples (`model_json_schema()`) when the model drives API contracts or documentation.
      - Use `model_validate` when validating an existing dict or object; direct `BaseModel(...)` construction also runs validators and coercion.
      - Ensure new code uses Pydantic v2 patterns (`@field_validator`, `model_config`) rather than deprecated v1 patterns (`@validator`, `orm_mode`).
      
  • SKILL.md 1.9 KB
    ---
    name: pydantic-models-py
    description: 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.
    license: MIT
    metadata:
      author: Microsoft
      version: "1.0.0"
    ---
    
    # Pydantic Models
    
    Create Pydantic models following the multi-model pattern for clean API contracts.
    
    ## Quick Start
    
    Copy the template from [assets/template.py](assets/template.py) and replace placeholders:
    - `{{ResourceName}}` → PascalCase name (e.g., `Project`)
    - `{{resource_name}}` → snake_case name (e.g., `project`)
    
    ## Multi-Model Pattern
    
    | Model | Purpose |
    |-------|---------|
    | `Base` | Common fields shared across models |
    | `Create` | Request body for creation (required fields) |
    | `Update` | Request body for updates (all optional) |
    | `Response` | API response with all fields |
    | `InDB` | Database document with `doc_type` |
    
    ## camelCase Aliases
    
    ```python
    from datetime import datetime
    
    from pydantic import BaseModel, ConfigDict, Field
    
    class MyModel(BaseModel):
        model_config = ConfigDict(populate_by_name=True)
    
        workspace_id: str = Field(..., alias="workspaceId")
        created_at: datetime = Field(..., alias="createdAt")
    ```
    
    ## Optional Update Fields
    
    ```python
    class MyUpdate(BaseModel):
        model_config = ConfigDict(populate_by_name=True)
    
        name: Optional[str] = Field(None, min_length=1)
        description: Optional[str] = None
    ```
    
    ## Database Document
    
    ```python
    class MyInDB(MyResponse):
        doc_type: str = "my_resource"
    ```
    
    ## Integration Steps
    
    1. Create models in `src/backend/app/models/`
    2. Export from `src/backend/app/models/__init__.py`
    3. Add corresponding TypeScript types
    
    ## Reference Files
    
    | File | Contents |
    |------|----------|
    | [references/capabilities.md](references/capabilities.md) | Additional non-hero capabilities, operation-group coverage, and production checklists. |
    

Comments (0)

Sign in to join the conversation.

No comments yet.

Reviews (0)

No reviews yet.

Related