@@ -1526,11 +1526,12 @@ async def generate_content(
15261526 try :
15271527 prompt_data = json .loads (json_match .group (1 ))
15281528 prompt_text = prompt_data .get ('prompt' , prompt_data .get ('image_prompt' , prompt_text ))
1529- except Exception :
1529+ except Exception as parse_error :
1530+ # Best-effort JSON extraction from markdown code block; on failure,
1531+ # fall back to the original prompt_text without interrupting image generation.
15301532 logger .debug (
1531- "Failed to parse JSON image prompt from markdown code block; "
1532- "continuing with original prompt_text." ,
1533- exc_info = True
1533+ "Failed to parse JSON from markdown code block for image prompt: %s" ,
1534+ parse_error ,
15341535 )
15351536
15361537 # Build product description for image generation context
@@ -1595,8 +1596,13 @@ async def generate_content(
15951596 for v in results ["violations" ]
15961597 )
15971598 except (json .JSONDecodeError , KeyError ):
1598- # Failed to parse compliance response JSON; violations will remain empty
1599- logger .debug ("Could not parse compliance violations from response" , exc_info = True )
1599+ # If the compliance response is not valid JSON or missing expected keys,
1600+ # continue without structured violations data but log for observability.
1601+ logger .debug (
1602+ "Could not parse structured compliance violations from response; "
1603+ "proceeding without 'violations' / 'requires_modification'." ,
1604+ exc_info = True ,
1605+ )
16001606
16011607 except Exception as e :
16021608 logger .exception (f"Error generating content: { e } " )
@@ -1764,13 +1770,10 @@ async def regenerate_image(
17641770 prompt_data = json .loads (json_match .group (1 ))
17651771 prompt_text = prompt_data .get ('prompt' , prompt_text )
17661772 change_summary = prompt_data .get ('change_summary' , modification_request )
1767- except Exception :
1768- # If JSON extraction fails here, fall back to the original
1769- # prompt_text and change_summary values set earlier.
1773+ except Exception as parse_error :
17701774 logger .debug (
1771- "Failed to parse JSON from markdown in regenerate_image; "
1772- "using original prompt_text and modification_request." ,
1773- exc_info = True
1775+ "Failed to parse JSON from image modification response fallback: %s" ,
1776+ parse_error ,
17741777 )
17751778
17761779 results ["image_prompt" ] = prompt_text
0 commit comments