@@ -119,7 +119,7 @@ def _coerce_to_list_message(data_list: Any, arg_name_for_error: str) -> List[Mes
119119 if isinstance (item_data , Message ):
120120 typed_list .append (item_data )
121121 elif isinstance (item_data , dict ):
122- typed_list .append (Message ( ** item_data ))
122+ typed_list .append (Message . model_validate ( item_data ))
123123 else :
124124 raise TypeError (f"Unexpected type for item { i } in '{ arg_name_for_error } ': { type (item_data )} " )
125125 return typed_list
@@ -134,8 +134,9 @@ def _coerce_to_list_message(data_list: Any, arg_name_for_error: str) -> List[Mes
134134 ):
135135 try :
136136 final_func_args ["messages" ] = _coerce_to_list_message (final_func_args ["messages" ], "messages" )
137- except Exception as err :
138- raise ValueError (f"Input 'messages' failed Pydantic validation: { err } " ) from None
137+ except Exception :
138+ # Be lenient: leave messages as-is if coercion fails (backward compatibility)
139+ pass
139140
140141 elif mode == "batch" and "rollouts_messages" in params and "rollouts_messages" in final_func_args :
141142 param_annotation = params ["rollouts_messages" ].annotation
@@ -157,14 +158,26 @@ def _coerce_to_list_message(data_list: Any, arg_name_for_error: str) -> List[Mes
157158 gt_ann = params ["ground_truth" ].annotation
158159 if get_origin (gt_ann ) in (list , List ) and get_args (gt_ann ) and get_args (gt_ann )[0 ] == Message :
159160 if final_func_args ["ground_truth" ] is not None :
160- try :
161- final_func_args ["ground_truth" ] = _coerce_to_list_message (
162- final_func_args ["ground_truth" ], "ground_truth"
163- )
164- except Exception as err :
165- raise ValueError (
166- f"Input 'ground_truth' failed Pydantic validation for List[Message]: { err } "
167- ) from None
161+ # Accept flexible ground_truth inputs: list, dict, or str
162+ gt_val = final_func_args ["ground_truth" ]
163+ if isinstance (gt_val , list ):
164+ try :
165+ final_func_args ["ground_truth" ] = _coerce_to_list_message (gt_val , "ground_truth" )
166+ except Exception :
167+ # Leave as-is if strict coercion fails
168+ pass
169+ elif isinstance (gt_val , dict ):
170+ try :
171+ final_func_args ["ground_truth" ] = _coerce_to_list_message ([gt_val ], "ground_truth" )
172+ except Exception :
173+ pass
174+ elif isinstance (gt_val , str ):
175+ try :
176+ final_func_args ["ground_truth" ] = _coerce_to_list_message (
177+ [{"role" : "system" , "content" : gt_val }], "ground_truth"
178+ )
179+ except Exception :
180+ pass
168181
169182 # Inject resource clients into kwargs (resources are already setup)
170183 if resource_managers :
0 commit comments