@@ -1529,11 +1529,12 @@ async def generate_content(
15291529 try :
15301530 prompt_data = json .loads (json_match .group (1 ))
15311531 prompt_text = prompt_data .get ('prompt' , prompt_data .get ('image_prompt' , prompt_text ))
1532- except Exception :
1532+ except Exception as parse_error :
1533+ # Best-effort JSON extraction from markdown code block; on failure,
1534+ # fall back to the original prompt_text without interrupting image generation.
15331535 logger .debug (
1534- "Failed to parse JSON image prompt from markdown code block; "
1535- "continuing with original prompt_text." ,
1536- exc_info = True
1536+ "Failed to parse JSON from markdown code block for image prompt: %s" ,
1537+ parse_error ,
15371538 )
15381539
15391540 # Build product description for DALL-E context
@@ -1598,8 +1599,13 @@ async def generate_content(
15981599 for v in results ["violations" ]
15991600 )
16001601 except (json .JSONDecodeError , KeyError ):
1601- # Failed to parse compliance response JSON; violations will remain empty
1602- logger .debug ("Could not parse compliance violations from response" , exc_info = True )
1602+ # If the compliance response is not valid JSON or missing expected keys,
1603+ # continue without structured violations data but log for observability.
1604+ logger .debug (
1605+ "Could not parse structured compliance violations from response; "
1606+ "proceeding without 'violations' / 'requires_modification'." ,
1607+ exc_info = True ,
1608+ )
16031609
16041610 except Exception as e :
16051611 logger .exception (f"Error generating content: { e } " )
@@ -1767,13 +1773,10 @@ async def regenerate_image(
17671773 prompt_data = json .loads (json_match .group (1 ))
17681774 prompt_text = prompt_data .get ('prompt' , prompt_text )
17691775 change_summary = prompt_data .get ('change_summary' , modification_request )
1770- except Exception :
1771- # If JSON extraction fails here, fall back to the original
1772- # prompt_text and change_summary values set earlier.
1776+ except Exception as parse_error :
17731777 logger .debug (
1774- "Failed to parse JSON from markdown in regenerate_image; "
1775- "using original prompt_text and modification_request." ,
1776- exc_info = True
1778+ "Failed to parse JSON from image modification response fallback: %s" ,
1779+ parse_error ,
17771780 )
17781781
17791782 results ["image_prompt" ] = prompt_text
0 commit comments