harry0703/MoneyPrinterTurbo · error · Exception

[{llm_provider}] returned an empty response

Error message

[{llm_provider}] returned an empty response

What it means

Raised in the qwen branch when dashscope.Generation.call() returns a falsy value (None, empty). Normally dashscope always returns a response object, so a falsy return means the SDK failed at a level below HTTP handling — misconfiguration of the SDK, an import/install problem, or an SDK bug.

Source

Thrown at app/services/llm.py:238

            dashscope.api_key = api_key
            response = dashscope.Generation.call(
                model=model_name, messages=[{"role": "user", "content": prompt}]
            )
            if response:
                if isinstance(response, GenerationResponse):
                    status_code = response.status_code
                    if status_code != 200:
                        raise Exception(
                            f'[{llm_provider}] returned an error response: "{response}"'
                        )

                    return _extract_qwen_generation_text(response)
                else:
                    raise Exception(
                        f'[{llm_provider}] returned an invalid response: "{response}"'
                    )
            else:
                raise Exception(f"[{llm_provider}] returned an empty response")

        if adapter == "gemini":
            from google import genai
            from google.genai import types

            http_options = types.HttpOptions(base_url=base_url) if base_url else None
            generation_config = types.GenerateContentConfig(
                temperature=0.5,
                top_p=1,
                top_k=1,
                max_output_tokens=2048,
                safety_settings=[
                    types.SafetySetting(
                        category="HARM_CATEGORY_HARASSMENT",
                        threshold="BLOCK_ONLY_HIGH",
                    ),
                    types.SafetySetting(
                        category="HARM_CATEGORY_HATE_SPEECH",

View on GitHub (pinned to 1f9f19c202)

Solutions

  1. Reinstall dashscope in a clean environment: pip install --force-reinstall dashscope
  2. If seen in tests, fix the mock: patch('dashscope.Generation.call', return_value=<valid GenerationResponse>)
  3. Reproduce once in isolation (small script calling dashscope.Generation.call) to determine if it is SDK-wide or config-specific
  4. If reproducible with a valid api_key, report to DashScope with the dashscope package version and switch llm_provider to an OpenAI-compatible fallback meanwhile

Example fix

# before
response = dashscope.Generation.call(model=model_name, messages=[...])
if response:
    ...
else:
    raise Exception(f"[{llm_provider}] returned an empty response")

# after
response = dashscope.Generation.call(model=model_name, messages=[...])
if response is None:
    raise RuntimeError(
        f"[qwen] dashscope returned None; dashscope version: "
        f"{getattr(dashscope, '__version__', 'unknown')}"
    )
Defensive patterns

Strategy: type-guard

Validate before calling

import dashscope
assert hasattr(dashscope, "Generation"), "dashscope SDK not installed or broken"

Type guard

def has_generation_response(resp) -> bool:
    return resp is not None

Try / catch

except Exception: — one retry is reasonable (transient SDK hiccup), then fail with SDK version info; do not loop on a stably-None return

Prevention

When it happens

Trigger: dashscope.Generation.call(...) evaluating False under `if response:` — e.g. a GenerationResponse with __bool__ defined oddly in some SDK versions, an SDK internal failure returning None, or a patched/mocked call returning None in tests.

Common situations: Broken dashscope installation (mixed versions in site-packages); monkeypatched dashscope in unit tests that forgot a return value; rare SDK versions where the response object's truthiness depends on success fields; intermittent SDK-level failures after network interruptions.

Related errors


AI-assisted analysis of harry0703/MoneyPrinterTurbo@1f9f19c202 (2026-08-14). Data as JSON: /api/errors/4722094aebb35e36. Report an issue: GitHub.