Skip to content

Commit 4ccfe5b

Browse files
committed
Extracted model response template to a constant.
1 parent 7fdd745 commit 4ccfe5b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pydantic_ai_slim/pydantic_ai/messages.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ def otel_event(self, _settings: InstrumentationSettings) -> Event:
423423
error_details_ta = pydantic.TypeAdapter(list[pydantic_core.ErrorDetails], config=pydantic.ConfigDict(defer_build=True))
424424

425425

426+
DEFAULT_MODEL_RESPONSE_TEMPLATE = '{description}\n\nFix the errors and try again.'
427+
428+
426429
@dataclass(repr=False)
427430
class RetryPromptPart:
428431
"""A message back to a model asking it to try again.
@@ -461,14 +464,18 @@ class RetryPromptPart:
461464
part_kind: Literal['retry-prompt'] = 'retry-prompt'
462465
"""Part type identifier, this is available on all parts as a discriminator."""
463466

467+
model_response_template: str = field(
468+
default=DEFAULT_MODEL_RESPONSE_TEMPLATE,
469+
)
470+
464471
def model_response(self) -> str:
465472
"""Return a string message describing why the retry is requested."""
466473
if isinstance(self.content, str):
467474
description = self.content
468475
else:
469476
json_errors = error_details_ta.dump_json(self.content, exclude={'__all__': {'ctx'}}, indent=2)
470477
description = f'{len(self.content)} validation errors: {json_errors.decode()}'
471-
return f'{description}\n\nFix the errors and try again.'
478+
return self.model_response_template.format(description=description)
472479

473480
def otel_event(self, _settings: InstrumentationSettings) -> Event:
474481
if self.tool_name is None:

0 commit comments

Comments
 (0)