fix(ai): strip markdown code block from Anthropic response before JSON parse
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:
parent
e861f20342
commit
70a6b5e6ef
1 changed files with 4 additions and 0 deletions
|
|
@ -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", ""))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue