File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -123,9 +123,25 @@ async def evaluate_program(
123123 metrics [f"llm_{ name } " ] = value * self .config .llm_feedback_weight
124124
125125 elapsed = time .time () - start_time
126+
127+ # Safe formatting of metrics to prevent formatting errors
128+ def safe_format_metric_value (value ):
129+ """Safely format a metric value for logging."""
130+ try :
131+ if isinstance (value , (int , float )) and not isinstance (value , bool ):
132+ import math
133+ if math .isnan (value ) or math .isinf (value ):
134+ return str (value )
135+ return f"{ value :.4f} "
136+ else :
137+ return str (value )
138+ except (ValueError , TypeError ):
139+ return str (value )
140+
141+ metrics_str = ', ' .join (f'{ name } ={ safe_format_metric_value (value )} ' for name , value in metrics .items ())
142+
126143 logger .info (
127- f"Evaluated program{ program_id_str } in { elapsed :.2f} s: "
128- f"{ ', ' .join (f'{ name } ={ value :.4f} ' for name , value in metrics .items ())} "
144+ f"Evaluated program{ program_id_str } in { elapsed :.2f} s: { metrics_str } "
129145 )
130146
131147 return metrics
You can’t perform that action at this time.
0 commit comments