-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
Question
Hi Pydantic AI team,
I couldn’t find documentation about using field_validator together with ModelRetry.
Does using field_validator with ModelRetry actually work, and will it cause the LLM to retry with the updated sentence?
Or should I use ValueError?
Thanks in advance.
Additional Context
Here’s my case example:
@final
class Task(BaseModel):
"""A task in an execution plan."""
task_name: str = Field(
description='Name of the specialized task to execute.',
)
@field_validator('task_name', mode='before')
@classmethod
def _upper_task_name(cls, value: str):
value = value.strip()
if not value:
raise ModelRetry('task_name is required and cannot be empty.')
return value.upper()
# OR
@field_validator('task_name', mode='before')
@classmethod
def _upper_task_name(cls, value: str):
value = value.strip()
if not value:
raise ValueError('task_name is required and cannot be empty.')
return value.upper()
# Code
agent = Agent(
...
output_type=Task,
)
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested