Skip to content

Commit 4b8ac2f

Browse files
committed
fix(translator): improve empty response handling and error messages
- Save debug output before validation to capture empty responses - Remove duplicate content_str conversion code - Enhance error messages with detailed debugging information - Add possible causes list for empty response troubleshooting
1 parent 825bb2a commit 4b8ac2f

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

tools/ai-markmap-agent/src/agents/translator.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,26 @@ def translate(self, content: str, output_type: str) -> str:
194194
# Convert to string if needed
195195
content_str = str(content) if not isinstance(content, str) else content
196196

197+
# Save LLM output BEFORE validation
198+
# This ensures we can debug empty responses by checking the saved file
199+
self._save_llm_call_output(content_str, "translate")
200+
197201
# Validate content is not empty
198202
if not content_str or len(content_str.strip()) == 0:
199-
raise ValueError(
200-
f"LLM returned empty response. "
201-
f"Model: {self.model_config.get('model')}, "
202-
f"Source: {self.source_language} → Target: {self.target_language}. "
203-
f"Check API response in debug output files."
203+
model_name = self.model_config.get('model', 'unknown')
204+
error_msg = (
205+
f"LLM returned empty response.\n"
206+
f" Model: {model_name}\n"
207+
f" Source: {self.source_language} → Target: {self.target_language}\n"
208+
f" Response length: {len(content_str)} chars\n"
209+
f" Debug output has been saved (check debug files for actual API response).\n"
210+
f" Possible causes:\n"
211+
f" 1. Invalid model name '{model_name}' (verify it's a valid model for your API provider)\n"
212+
f" 2. API quota/rate limit exceeded\n"
213+
f" 3. API returned empty content due to content filtering or safety checks\n"
214+
f" 4. Network/API connection issue"
204215
)
205-
206-
# Convert to string if needed
207-
content_str = str(content) if not isinstance(content, str) else content
208-
209-
# Save LLM output
210-
self._save_llm_call_output(content_str, "translate")
216+
raise ValueError(error_msg)
211217

212218
return content_str
213219

0 commit comments

Comments
 (0)