From 4c256ba66c0211601778c95471139249b116c827 Mon Sep 17 00:00:00 2001 From: Ricardo-M-L Date: Wed, 8 Apr 2026 23:23:03 +0800 Subject: [PATCH 1/2] fix: correct demo index assignment in MIPROv2 optimizer Co-Authored-By: Claude Opus 4.6 (1M context) --- dspy/teleprompt/mipro_optimizer_v2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dspy/teleprompt/mipro_optimizer_v2.py b/dspy/teleprompt/mipro_optimizer_v2.py index 47acfd58ac..affeb03ff5 100644 --- a/dspy/teleprompt/mipro_optimizer_v2.py +++ b/dspy/teleprompt/mipro_optimizer_v2.py @@ -780,7 +780,7 @@ def _select_and_insert_instructions_and_demos( predictor.demos = demo_candidates[i][demos_idx] trial_logs[trial_num][f"{i}_predictor_demos"] = demos_idx chosen_params.append(f"Predictor {i}: Few-Shot Set {demos_idx}") - raw_chosen_params[f"{i}_predictor_demos"] = instruction_idx + raw_chosen_params[f"{i}_predictor_demos"] = demos_idx return chosen_params, raw_chosen_params From e40900af6ffd4242cf27378502022e3e512beaf1 Mon Sep 17 00:00:00 2001 From: Ricardo-M-L Date: Fri, 1 May 2026 13:47:36 +0800 Subject: [PATCH 2/2] fix: raise ValueError instead of UnboundLocalError when no valid program found get_program_with_highest_avg_score would fall through to a return that references undefined variables when sorted_results was empty. Now raises a clear ValueError with context. --- dspy/teleprompt/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dspy/teleprompt/utils.py b/dspy/teleprompt/utils.py index be82f207ec..a4d7be724c 100644 --- a/dspy/teleprompt/utils.py +++ b/dspy/teleprompt/utils.py @@ -139,8 +139,7 @@ def get_program_with_highest_avg_score(param_score_dict, fully_evaled_param_comb return program, mean, key, params - # If no valid program is found, we return the last valid one that we found - return program, mean, key, params + raise ValueError("No valid program found in param_score_dict") def calculate_last_n_proposed_quality(