harry0703/MoneyPrinterTurbo · error · ValueError
[{llm_provider}] returned empty response
Error message
[{llm_provider}] returned empty response What it means
Raised in the litellm branch when litellm.completion() returns a falsy response object. litellm normally raises its own exceptions on failure, so a falsy return is an SDK-contract anomaly — most often seen with drop_params=True silently stripping parameters on an incompatible provider, or mocked litellm in tests.
Source
Thrown at app/services/llm.py:323
)
return _extract_chat_completion_text(response, llm_provider)
if adapter == "litellm":
import litellm
if not model_name:
raise ValueError(
f"{llm_provider}: model_name is not set, please set it in the config.toml file."
)
response = litellm.completion(
model=model_name,
messages=[{"role": "user", "content": prompt}],
drop_params=True,
)
if not response:
raise ValueError(f"[{llm_provider}] returned empty response")
if not getattr(response, "choices", None):
raise ValueError(f"[{llm_provider}] returned empty response")
return _extract_chat_completion_text(response, llm_provider)
if adapter == "azure":
# Azure OpenAI SDK 使用 `azure_endpoint` 和 `api_version` 生成专用请求地址,
# 不能继续复用下面普通 OpenAI-compatible 的 `base_url` 初始化逻辑。
# 这里在 Azure 分支内完成请求并立即返回,避免客户端被后续 fallback
# 覆盖,导致用户配置的 Azure 凭证通过校验但实际请求没有被使用。
logger.info(f"requesting azure chat completion, model: {model_name}")
client = AzureOpenAI(
api_key=api_key,
api_version=api_version,
azure_endpoint=base_url,
)
response = client.chat.completions.create(
model=model_name, messages=[{"role": "user", "content": prompt}]View on GitHub (pinned to 1f9f19c202)
Solutions
- Check litellm logs/verbose output (litellm.set_verbose=True or check logger) for the routing failure that preceded the empty return
- Pin a known-good litellm version: the model-string routing contract changed between major versions; reinstall in a clean venv
- Verify the model string format for the target provider (e.g. 'groq/llama-3.1-8b-instant') and that the matching credentials env vars (GROQ_API_KEY, etc.) are set
- In tests, make the litellm.completion mock return a real ModelResponse with choices
Example fix
# before
response = litellm.completion(model=model_name, messages=[...], drop_params=True)
if not response:
raise ValueError(f"[{llm_provider}] returned empty response")
# after
response = litellm.completion(model=model_name, messages=[...], drop_params=True)
if not response:
raise ValueError(
f"[{llm_provider}] litellm returned empty response for model "
f"'{model_name}'; check provider prefix and credentials"
) Defensive patterns
Strategy: validation
Validate before calling
import litellm
if not hasattr(litellm, "completion"):
raise RuntimeError("litellm not installed")
# verify model routes: litellm.get_model_info or a 1-token dry run
resp = litellm.completion(model=model_name, messages=[{"role":"user","content":"hi"}], max_tokens=1)
assert resp and resp.choices Try / catch
except ValueError: — check the model string and credentials once, then fail; retrying an empty return from the same model usually repeats
Prevention
- Pin the litellm version; its return contract shifts between majors
- Dry-run litellm with max_tokens=1 when adding a new provider config
- Set required provider env keys (e.g. GROQ_API_KEY) before starting jobs
When it happens
Trigger: litellm.completion(model=..., messages=[...], drop_params=True) evaluating False under `if not response:` — e.g. a litellm version returning None on certain internal routing failures, unsupported model/provider strings falling through, or a test mock returning None.
Common situations: Upgrading litellm major versions (its return contract and exception behavior changed across releases); passing a model string litellm cannot resolve to any provider; unit tests patching litellm.completion without a return value; edge failure modes inside litellm's router.
Related errors
- {llm_provider}: unsupported llm provider
- {llm_provider}: api_key is not set, please set it in the con
- {llm_provider}: model_name is not set, please set it in the
- {llm_provider}: base_url is not set, please set it in the co
- {llm_provider}: {field.config_suffix} is not set, please set
AI-assisted analysis of harry0703/MoneyPrinterTurbo@1f9f19c202 (2026-08-14).
Data as JSON: /api/errors/41577e53477edc63.
Report an issue: GitHub.