Skip to content

fix: raise ValueError instead of UnboundLocalError when no valid program found - #10219

Open
Ricardo-M-L wants to merge 2 commits into
stanfordnlp:mainfrom
Ricardo-M-L:fix/miprov2-demo-index-assignment
Open

Ricardo-M-L wants to merge 2 commits into
stanfordnlp:mainfrom
Ricardo-M-L:fix/miprov2-demo-index-assignment

Conversation

@Ricardo-M-L

Copy link
Copy Markdown
Contributor

This PR addresses: raise ValueError instead of UnboundLocalError when no valid program found

Ricardo-M-L and others added 2 commits April 8, 2026 23:23
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ram 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.
@greptile-apps

greptile-apps Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This change corrects MIPROv2 bookkeeping for selected few-shot demo sets and replaces an accidental local-variable failure with a clear error when no program remains eligible for selection.

Direct behavior checks exercised different instruction and demo indexes and confirmed that the selected demo index is retained. They also exercised empty and fully evaluated program sets, which now raise ValueError("No valid program found in param_score_dict") rather than UnboundLocalError. The focused teleprompt utility tests passed (4 passed). No defects were found.

Confidence Score: 5/5

The changed optimizer and utility behavior performed as intended under direct execution and focused tests.

A reproducible harness covered the formerly divergent instruction and demo indexes plus the empty and fully evaluated selection paths, and the focused utility suite completed successfully without a regression.

Files Needing Attention: No files need follow-up attention.

T-Rex T-Rex Logs

What T-Rex did

  • Ran the authored Python validation harness against the checked-out implementation with instruction index 1 and demo index 2, plus fully evaluated and empty program-selection inputs, and observed that the code recorded demo index 2 and raised the expected ValueError for both no-eligible-program cases, while a parent-logic reproduction raised UnboundLocalError.
  • Compared pre- and post-execution captures to verify the demo index handling and error messages: before capture showed the prior wrong demo raw value (1) and the empty-combo UnboundLocalError, while after capture showed the correct demo raw value (2) and the exact ValueError: No valid program found in param_score_dict for fully evaluated and empty inputs.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "fix: raise ValueError instead of Unbound..." | Re-trigger Greptile

@Ricardo-M-L

Copy link
Copy Markdown
Contributor Author

Friendly ping - this PR is small and ready for a look whenever someone has bandwidth.

Two independent one-line bugs, both currently reachable in MIPROv2:

  1. mipro_optimizer_v2.py:783 - raw_chosen_params is written with instruction_idx where the loop variable for the demo set is demos_idx. The key is f"{i}_predictor_demos", so it records the instruction index under a demo key. Silent corruption of the selected-params bookkeeping; any downstream reader that trusts raw_chosen_params gets the wrong few-shot set index. demos_idx is the correct value (it is the value assigned to trial_logs[trial_num] on the line above for the same key).

  2. utils.py:141-144 - the fallthrough after the loop returns program, mean, key, params, none of which are guaranteed to be bound if every entry in param_score_dict was filtered out. That raises UnboundLocalError, which is neither caught nor actionable. Replaced with an explicit ValueError naming the cause.

Scope: 2 files, +2/-3, no API or signature changes. Both changes are strictly error-path or bookkeeping corrections - successful optimization runs behave identically.

Happy to rebase if main has moved.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant