From 6d0dfa9e0bbebf7a5d4ebb76c8069332f68fb0e1 Mon Sep 17 00:00:00 2001 From: Caleb Biddulph Date: Wed, 3 Dec 2025 23:17:49 -0800 Subject: [PATCH] Fix two bugs in bootstrap_trace.py Previously, bootstrap_trace_data would capture execution traces in the `prediction` parameter of wrapped_metric, but then discarded them. Metrics would always receive trace=None instead of the actual trace. This would break metrics that use the trace. Also fixed attempted division of two lists, dividing their lengths instead. --- dspy/teleprompt/bootstrap_trace.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dspy/teleprompt/bootstrap_trace.py b/dspy/teleprompt/bootstrap_trace.py index 2f0cc60cd1..8645d56998 100644 --- a/dspy/teleprompt/bootstrap_trace.py +++ b/dspy/teleprompt/bootstrap_trace.py @@ -51,10 +51,10 @@ def bootstrap_trace_data( ) def wrapped_metric(example, prediction, trace=None): - prediction, _ = prediction + prediction, captured_trace = prediction if isinstance(prediction, FailedPrediction): return prediction.format_reward or format_failure_score - return metric(example, prediction, trace) if metric else True + return metric(example, prediction, captured_trace) if metric else True # Use `object.__getattribute__` to bypass the custom hook `Module.__getattribute__` so that we avoid # the warning that `forward` is not accessed through `__call__`. @@ -87,7 +87,7 @@ def patched_forward(program_to_use: Module, **kwargs): failed_pred = FailedPrediction( completion_text=completion_str, format_reward=format_failure_score - + (failure_score - format_failure_score) * (present / expected), + + (failure_score - format_failure_score) * (len(present) / len(expected)), ) else: failed_pred = FailedPrediction(completion_text=completion_str, format_reward=format_failure_score)