Trending today

1

Create a deep RPG character backstory with motivations, flaws, and arc potential

11.8K views
2

Anomaly detection with rolling z-score windows in SQL

11.8K views
3

30-day social media content calendar with post templates

11.6K views
4

Structured logging with correlation IDs across microservices

11.4K views
5

Legacy JavaScript to modern ES2023 refactor

10.9K views

Creators to follow

N
nadia_ux45 followers
D
david_ops45 followers
P
priya_design44 followers
AboutTermsPrivacyHelp

© 2026 teliprompt

JE
jess_python
4 days ago•
Coding

Python dataclass to Pydantic v2 model converter

Claude Sonnet 4.6
code output
#python
#pydantic
#dataclass
#refactor
#validation
Views
10.3K
Copies
3.5K
Likes
2.0K
Comments
0
Copy rate
34.0%

Prompt

You are an expert Python engineer. Convert the following Python dataclass to an equivalent Pydantic v2 model.

Source dataclass:
[source_dataclass]

Requirements:
- Target Pydantic version: [pydantic_version]
- Preserve all fields, types, and default values exactly
- Translate `field(default_factory=...)` to Pydantic's `Field(default_factory=...)`
- Translate `Optional[X]` / `X | None` correctly with proper defaults
- Add sensible `Field(...)` validation (min_length, ge, le, pattern) where the field name implies constraints (email, age, url, slug)
- Convert any `__post_init__` logic into `@model_validator(mode='after')`
- Add a `model_config = ConfigDict(...)` block with `str_strip_whitespace=True`, `validate_assignment=True`, and `extra='forbid'`
- Include a working usage example at the bottom that constructs the model from a dict, serializes it with `model_dump()`, and round-trips through `model_validate_json()`

Output format:
- Return only the complete Python file, no prose
- First line: `from __future__ import annotations`
- Include all necessary imports at the top
- Type hints must be complete and correct

Customise this prompt

Fill in 3 variables to personalise this prompt

Preview
You are an expert Python engineer. Convert the following Python dataclass to an equivalent Pydantic v2 model. Source dataclass: [source_dataclass] Requirements: - Target Pydantic version: [pydantic_version] - Preserve all fields, types, and default values exactly - Translate `field(default_factory=...)` to Pydantic's `Field(default_factory=...)` - Translate `Optional[X]` / `X | None` correctly with proper defaults - Add sensible `Field(...)` validation (min_length, ge, le, pattern) where the field name implies constraints (email, age, url, slug) - Convert any `__post_init__` logic into `@model_validator(mode='after')` - Add a `model_config = ConfigDict(...)` block with `str_strip_whitespace=True`, `validate_assignment=True`, and `extra='forbid'` - Include a working usage example at the bottom that constructs the model from a dict, serializes it with `model_dump()`, and round-trips through `model_validate_json()` Output format: - Return only the complete Python file, no prose - First line: `from __future__ import annotations` - Include all necessary imports at the top - Type hints must be complete and correct

Example output

Related prompts

Task automation script with retry logic and notificationsby @jess_python
Coding
Legacy JavaScript to modern ES2023 refactorby @marcus_react
Coding
Custom React hook with TypeScript generics and full test suiteby @marcus_react
Coding
Regex builder with visual explanation and test casesby @mei_swift
Coding