crewAIInc/crewAI · error · ValueError

Empty response from Serper API

Error message

Empty response from Serper API

What it means

SerperDevTool raises ValueError("Empty response from Serper API") in _make_api_request when requests.post succeeds (HTTP 2xx) and response.json() parses to an empty object. The tool treats a 200 with a falsy JSON body as a terminal error rather than returning empty results.

Source

Thrown at lib/crewai-tools/src/crewai_tools/tools/serper_dev_tool/serper_dev_tool.py:264

            payload["location"] = self.location
        if self.locale != "":
            payload["hl"] = self.locale

        headers = {
            "X-API-KEY": os.environ["SERPER_API_KEY"],
            "content-type": "application/json",
        }

        response = None
        try:
            response = requests.post(
                search_url, headers=headers, json=payload, timeout=10
            )
            response.raise_for_status()
            results = response.json()
            if not results:
                logger.error("Empty response from Serper API")
                raise ValueError("Empty response from Serper API")
            return dict(results)
        except requests.exceptions.RequestException as e:
            error_msg = f"Error making request to Serper API: {e}"
            if response is not None and hasattr(response, "content"):
                error_msg += f"\nResponse content: {response.content.decode('utf-8', errors='replace')}"
            logger.error(error_msg)
            raise
        except json.JSONDecodeError as e:
            if response is not None and hasattr(response, "content"):
                logger.error(f"Error decoding JSON response: {e}")
                logger.error(
                    f"Response content: {response.content.decode('utf-8', errors='replace')}"
                )
            else:
                logger.error(
                    f"Error decoding JSON response: {e} (No response content available)"
                )
            raise

View on GitHub (pinned to 754d7323be)

Solutions

  1. Retry the tool call — a 200-with-empty-body is typically transient.
  2. Inspect the payload your code sends (the dict built from search_query/search_type and options) for parameters that could suppress results.
  3. Check Serper status (https://serper.dev) and your account quota; if it persists, capture the raw request and report to Serper support.
Defensive patterns

Strategy: retry

Try / catch

import time
for attempt in range(3):
    try:
        return serper_tool._run(search_query=q)
    except ValueError as e:
        if "Empty response" not in str(e) or attempt == 2:
            raise
        time.sleep(2 ** attempt)

Prevention

When it happens

Trigger: A POST to https://google.serper.dev/search or /news returns HTTP 200 with an empty JSON body ({}). This is rare but can happen with malformed payloads the API silently accepts, or transient API-side glitches.

Common situations: Usually transient Serper-side behavior or an edge-case payload (e.g. num=0 or an unsupported parameter combination). Most users who see this hit it intermittently during high-volume runs.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/7ee2d276aab4724b. Report an issue: GitHub.