fix(translate): add EXPLORE logging for LLM JSON parse failures

Preview + executor now log the raw LLM response (first 1000 chars)
when JSON parsing fails, enabling debugging of malformed LLM output.

Previously ValueErrors from JSON parse failures were silently returned
as 400 without any diagnostic data in logs.
This commit is contained in:
2026-05-15 09:15:36 +03:00
parent a74c50206a
commit 7947700188
4 changed files with 412 additions and 0 deletions

View File

@@ -999,8 +999,10 @@ class TranslationExecutor:
try:
data = json.loads(match.group(1))
except json.JSONDecodeError:
logger.explore("LLM response was not valid JSON (after markdown extraction)", extra={"src": "executor", "response_preview": response_text[:1000]})
raise ValueError("LLM response was not valid JSON")
else:
logger.explore("LLM response was not valid JSON (no markdown block)", extra={"src": "executor", "response_preview": response_text[:1000]})
raise ValueError("LLM response was not valid JSON")
rows = data.get("rows", [])

View File

@@ -1005,8 +1005,10 @@ class TranslationPreview:
try:
data = json.loads(match.group(1))
except json.JSONDecodeError:
logger.explore("LLM response was not valid JSON (after markdown extraction)", extra={"src": "preview", "response_preview": response_text[:1000]})
raise ValueError("LLM response was not valid JSON")
else:
logger.explore("LLM response was not valid JSON (no markdown block)", extra={"src": "preview", "response_preview": response_text[:1000]})
raise ValueError("LLM response was not valid JSON")
rows = data.get("rows", [])