File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
pydantic_ai_slim/pydantic_ai Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -423,6 +423,9 @@ def otel_event(self, _settings: InstrumentationSettings) -> Event:
423
423
error_details_ta = pydantic .TypeAdapter (list [pydantic_core .ErrorDetails ], config = pydantic .ConfigDict (defer_build = True ))
424
424
425
425
426
+ DEFAULT_MODEL_RESPONSE_TEMPLATE = '{description}\n \n Fix the errors and try again.'
427
+
428
+
426
429
@dataclass (repr = False )
427
430
class RetryPromptPart :
428
431
"""A message back to a model asking it to try again.
@@ -461,14 +464,18 @@ class RetryPromptPart:
461
464
part_kind : Literal ['retry-prompt' ] = 'retry-prompt'
462
465
"""Part type identifier, this is available on all parts as a discriminator."""
463
466
467
+ model_response_template : str = field (
468
+ default = DEFAULT_MODEL_RESPONSE_TEMPLATE ,
469
+ )
470
+
464
471
def model_response (self ) -> str :
465
472
"""Return a string message describing why the retry is requested."""
466
473
if isinstance (self .content , str ):
467
474
description = self .content
468
475
else :
469
476
json_errors = error_details_ta .dump_json (self .content , exclude = {'__all__' : {'ctx' }}, indent = 2 )
470
477
description = f'{ len (self .content )} validation errors: { json_errors .decode ()} '
471
- return f' { description } \n \n Fix the errors and try again.'
478
+ return self . model_response_template . format ( description = description )
472
479
473
480
def otel_event (self , _settings : InstrumentationSettings ) -> Event :
474
481
if self .tool_name is None :
You can’t perform that action at this time.
0 commit comments