From 6dff05585408d552c9ec40c5cda59a26a1cffb0b Mon Sep 17 00:00:00 2001 From: Varun Nuthalapati Date: Sat, 25 Apr 2026 11:58:05 -0700 Subject: [PATCH] fix: prevent UnboundLocalError in ExperienceSummarizer.get_summary 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 #189 --- ufo/experience/summarizer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ufo/experience/summarizer.py b/ufo/experience/summarizer.py index 1c0308c73..7afd1e5f4 100644 --- a/ufo/experience/summarizer.py +++ b/ufo/experience/summarizer.py @@ -74,12 +74,12 @@ def get_summary(self, prompt_message: list) -> Tuple[dict, float]: ) try: response_json = json_parser(response_string) - except: + except Exception: response_json = None # Restructure the response + summary = dict() if response_json: - summary = dict() summary["example"] = {} for key in [ "Observation",