Skip to content

fix: prevent UnboundLocalError in ExperienceSummarizer.get_summary#310

Open
nuthalapativarun wants to merge 1 commit intomicrosoft:pre-releasefrom
nuthalapativarun:fix/summarizer-unbound-local-error
Open

fix: prevent UnboundLocalError in ExperienceSummarizer.get_summary#310
nuthalapativarun wants to merge 1 commit intomicrosoft:pre-releasefrom
nuthalapativarun:fix/summarizer-unbound-local-error

Conversation

@nuthalapativarun
Copy link
Copy Markdown

Summary

  • Fix UnboundLocalError: cannot access local variable 'summary' in ExperienceSummarizer.get_summary
  • Replace bare except: with except Exception:

Changes

ufo/experience/summarizer.py — when json_parser raises an exception, response_json is set to None and the summary dict is never initialized inside the if response_json: block. The subsequent return summary, cost then raises UnboundLocalError.

Fix: initialize summary = dict() before the conditional block so it is always defined regardless of whether json_parser succeeds.

Reproduction

UserWarning: cannot access local variable 'summary' where it is not associated with a value

Occurs when the LLM returns a non-JSON response during experience summarization.

Related Issue

Fixes #189

When json_parser raises an exception, response_json is set to None and
the summary dict is never initialized, causing an UnboundLocalError on
the return statement.

Initialize summary before the conditional block so it is always defined.
Also replace bare except with except Exception.

Fixes microsoft#189
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