pydantic-model-scaffolder
Scaffolds Pydantic models for request/response validation with advanced validation rules. Use for complex data models. Related: fastapi-endpoint-scaffolder for quick endpoint creation.
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
Pydantic Model Scaffolder Workflow
Purpose
Scaffolds type-safe Pydantic models for request/response validation, incorporating advanced validation rules, documentation, and examples.
When to Use
- When creating new API request or response schemas for FastAPI.
- When defining database models with specific validation constraints.
- When establishing consistent data structures across the backend services.
Process
-
Ask for model details:
- Model name (PascalCase, e.g.,
NotificationPreferences,EmailTemplate) - Purpose (e.g., "User notification settings", "Email template data")
- Model type: Request, Response, Database, or All
- Model name (PascalCase, e.g.,
-
Ask for fields:
- Field names and types (e.g.,
email_enabled: bool,push_enabled: bool,frequency: str) - Optional fields (mark with
Optional[type]) - Default values if any
- Field descriptions for documentation
- Validation rules (e.g., email format, string length, numeric ranges)
- Field names and types (e.g.,
-
Generate model file:
- Read template based on model type:
-
request_model.py.tplfor request models -
response_model.py.tplfor response models -
database_model.py.tplfor database models -
complete_model.py.tplfor all model types
-
- Replace placeholders:
-
{{MODEL_NAME}}- PascalCase model name -
{{MODEL_DESCRIPTION}}- Purpose description -
{{FIELDS}}- Field definitions with types -
{{VALIDATORS}}- Custom validators -
{{EXAMPLE}}- Example data for documentation
-
- Write to:
backend/app/models/{{model_name_snake}}_schemas.py
- Read template based on model type:
-
Update models init.py:
- Read:
backend/app/models/__init__.py - Add import statement for new model
- Add to
__all__list - Write updated file
- Read:
-
Generate validation patterns:
- Add field validators for:
- Email format validation
- String length constraints
- Numeric ranges
- Enum validation
- Custom business rules
- Add field validators for:
-
Report success:
- Show file path
- Display generated model structure
- Show example usage code
- List validation rules applied
Model Types
Request Model
- Used for incoming API requests
- Strict validation
- Required fields enforced
- Examples for OpenAPI docs
Response Model
- Used for API responses
- May include computed fields
- Documentation for frontend
- Consistent structure
Database Model
- Used for Firestore/database operations
- May include timestamps
- Conversion methods (to_dict, from_dict)
- Field mapping
Example Usage
User: Create a Pydantic model for notification preferences
Assistant: I'll create a notification preferences model. Let me ask for the details...
- Model name: NotificationPreferences
- Fields:
- email_enabled: bool (default: True)
- push_enabled: bool (default: False)
- sms_enabled: bool (default: False)
- frequency: str (options: "instant", "daily", "weekly")
- quiet_hours_start: Optional[int] (0-23)
- quiet_hours_end: Optional[int] (0-23)
Template Variables
-
{{MODEL_NAME}}: PascalCase model name -
{{MODEL_DESCRIPTION}}: Description of the model's purpose -
{{FIELDS}}: Field definitions with types and defaults -
{{VALIDATORS}}: Custom validation functions -
{{EXAMPLE}}: Example JSON for documentation -
{{IMPORTS}}: Required imports based on field types
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-01-20
- Index updated
- 2026-03-03
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!