Skip to content

Commit ff18443

Browse files
committed
🎨 [Documentation] Add guidelines for converting Pydantic model fields to use Annotated pattern
1 parent a21f916 commit ff18443

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

docs/llm-prompts/pydantic-annotated-fields.md renamed to .github/prompts/pydantic-annotated-fields.prompt.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
# Prompt
1+
---
2+
mode: 'edit'
3+
description: 'Update user messages'
4+
---
5+
26

3-
```
47
Please convert all pydantic model fields that use `Field()` with default values to use the Annotated pattern instead.
58
Follow these guidelines:
69

@@ -10,7 +13,8 @@ Follow these guidelines:
1013
4. Add the import: `from common_library.basic_types import DEFAULT_FACTORY` if it's not already present.
1114
5. If `Field()` has no parameters (empty), don't use Annotated at all. Just use: `field_name: field_type = default_value`.
1215
6. Leave any model validations, `model_config` settings, and `field_validators` untouched.
13-
```
16+
17+
1418
## Examples
1519

1620
### Before:
@@ -53,6 +57,7 @@ class ProjectModel(BaseModel):
5357
id: str = Field(default_factory=uuid.uuid4, description="Unique project identifier")
5458
name: str = Field(default="Untitled Project", min_length=3, max_length=50)
5559
created_at: datetime = Field(default_factory=datetime.now)
60+
value: int = Field(..., description="Project value")
5661
config: dict = Field(default={"version": "1.0", "theme": "default"})
5762

5863
@field_validator("name")
@@ -74,6 +79,7 @@ class ProjectModel(BaseModel):
7479
id: Annotated[str, Field(default_factory=uuid.uuid4, description="Unique project identifier")] = DEFAULT_FACTORY
7580
name: Annotated[str, Field(min_length=3, max_length=50)] = "Untitled Project"
7681
created_at: Annotated[datetime, Field(default_factory=datetime.now)] = DEFAULT_FACTORY
82+
value: Annotated[int, Field(description="Project value")]
7783
config: dict = {"version": "1.0", "theme": "default"}
7884

7985
@field_validator("name")

0 commit comments

Comments
 (0)