From 6c40f713a4f3765b1242cb631f0e79b9f7353735 Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Tue, 10 Feb 2026 00:50:10 +0000 Subject: [PATCH] fix: strip markdown code fences from LLM JSON response Gemini wraps JSON output in ```json fences which broke the parser. Co-Authored-By: Claude Opus 4.6 --- backend/app/services/ai_analysis.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/app/services/ai_analysis.py b/backend/app/services/ai_analysis.py index 7f3fc9f..00f0210 100644 --- a/backend/app/services/ai_analysis.py +++ b/backend/app/services/ai_analysis.py @@ -259,6 +259,9 @@ async def _call_openai(system: str, user_prompt: str) -> str: def _parse_clips(content: str, video_duration: float) -> list[dict]: """Parse LLM response into clip list, handling imperfect JSON.""" + # Strip markdown code fences (e.g. ```json ... ```) + content = re.sub(r"```(?:json)?\s*", "", content).strip() + # Try to extract JSON from response json_match = re.search(r"\{[\s\S]*\}", content) if not json_match: