Skip to content

Your lightweight open-source personal agent.

fix(providers): handle empty choices in custom provider response

Jiajun Xie2eb0c283e9a3
diff --git a/nanobot/providers/custom_provider.py b/nanobot/providers/custom_provider.py
index e177e55d9..4bdeb5429 100644
--- a/nanobot/providers/custom_provider.py
+++ b/nanobot/providers/custom_provider.py
@@ -54,6 +54,11 @@ class CustomProvider(LLMProvider):
return LLMResponse(content=f"Error: {e}", finish_reason="error")
def _parse(self, response: Any) -> LLMResponse:
+ if not response.choices:
+ return LLMResponse(
+ content="Error: API returned empty choices. This may indicate a temporary service issue or an invalid model response.",
+ finish_reason="error"
+ )
choice = response.choices[0]
msg = choice.message
tool_calls = [