fix(ai): strip markdown code block from Anthropic response before JSON parse
Some checks failed
CI / backend (push) Has been cancelled
CI / frontend (push) Has been cancelled

Claude Haiku wraps JSON in ```json ... ``` blocks, causing json.loads to fail
silently. The except clause swallowed the error, leaving ai_title empty for all
303 sessions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-05-18 17:25:14 +01:00
parent e861f20342
commit 70a6b5e6ef

View file

@ -41,6 +41,10 @@ Return only valid JSON, no other text."""
try:
text = response.content[0].text.strip()
# Strip markdown code block if model wraps response (e.g. ```json ... ```)
if text.startswith("```"):
text = text.split("\n", 1)[1] if "\n" in text else text
text = text.rsplit("```", 1)[0].strip()
data = json.loads(text)
ai_title = str(data.get("title", ""))[:200]
ai_result = str(data.get("result", ""))