Skip to content

Commit 825bb2a

Browse files
committed
feat(translator): add validation for empty string responses from LLM
- Check for empty or whitespace-only responses in addition to None checks - Raise ValueError with descriptive message when model returns empty content - Prevents silent failures when translation API returns empty strings
1 parent 6aa7f5b commit 825bb2a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ 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+
# Validate content is not empty
198+
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."
204+
)
205+
206+
# Convert to string if needed
207+
content_str = str(content) if not isinstance(content, str) else content
208+
197209
# Save LLM output
198210
self._save_llm_call_output(content_str, "translate")
199211

0 commit comments

Comments
 (0)