microsoft/semantic-kernel · error · ServiceInvalidRequestError
A client error occurred while getting search results.
Error message
A client error occurred while getting search results.
What it means
If httpx raises a RequestError the request never completed successfully. This covers connection failures, DNS errors, TLS problems, and timeouts; the connector uses AsyncClient(timeout=5), a hard five-second cap. The error is logged and re-raised as ServiceInvalidRequestError('A client error occurred while getting search results.').
Source
Thrown at python/semantic_kernel/connectors/google_search.py:276
logger.info(
f"Received request for google web search with \
params:\nnum_results: {options.top}\noffset: {options.skip}"
)
full_url = f"{CUSTOM_SEARCH_URL}{self._build_query(query, options)}"
headers = {"user_agent": SEMANTIC_KERNEL_USER_AGENT}
try:
async with AsyncClient(timeout=5) as client:
response = await client.get(full_url, headers=headers)
response.raise_for_status()
return GoogleSearchResponse.model_validate_json(response.text)
except HTTPStatusError as ex:
logger.error(f"Failed to get search results: {ex}")
raise ServiceInvalidRequestError("Failed to get search results.") from ex
except RequestError as ex:
logger.error(f"Client error occurred: {ex}")
raise ServiceInvalidRequestError("A client error occurred while getting search results.") from ex
except Exception as ex:
logger.error(f"An unexpected error occurred: {ex}")
raise ServiceInvalidRequestError("An unexpected error occurred while getting search results.") from ex
def _validate_options(self, options: SearchOptions) -> None:
if options.top > 10:
raise ServiceInvalidRequestError("count value must be less than or equal to 10.")
def _parse_filter_lambda(self, filter_lambda: Callable | str) -> list[dict[str, str]]:
"""Parse a string lambda or string expression into a list of {field: value} dicts using AST."""
expr = filter_lambda if isinstance(filter_lambda, str) else getsource(filter_lambda).strip()
tree = ast.parse(expr, mode="eval")
node = tree.body
visitor = SearchLambdaVisitor(valid_parameters=QUERY_PARAMETERS)
visitor.visit(node)
return visitor.filters
def _build_query(self, query: str, options: SearchOptions) -> str:View on GitHub (pinned to c028a0c7dc)
Solutions
- Verify connectivity to https://www.googleapis.com from the host.
- Configure proxy via HTTP_PROXY/HTTPS_PROXY env vars or a corporate trust store for TLS.
- Retry transient RequestErrors with exponential backoff (the 5s timeout is hardcoded in the connector).
- If timeouts are chronic, search less frequently or pre-warm results asynchronously.
Example fix
# before
results = await google.search('skates') # timeout/proxy -> [1304]
# after
for attempt in range(4):
try:
results = await google.search('skates')
break
except ServiceInvalidRequestError as ex:
if not isinstance(ex.__cause__, RequestError):
raise
await asyncio.sleep(1.5 ** attempt)
else:
raise Defensive patterns
Strategy: retry
Try / catch
from httpx import RequestError
from semantic_kernel.exceptions import ServiceInvalidRequestError
for attempt in range(4):
try:
results = await google.search(query, top=top)
break
except ServiceInvalidRequestError as ex:
if not isinstance(ex.__cause__, RequestError):
raise
if attempt == 3:
raise
await asyncio.sleep(1.5 ** attempt) Prevention
- Confirm outbound HTTPS to www.googleapis.com works from the host.
- Configure HTTP_PROXY/HTTPS_PROXY in corporate networks.
- Retry transient connection/timeout errors with backoff; the connector's 5s timeout is fixed.
When it happens
Trigger: No network connectivity; DNS resolution failure for www.googleapis.com; ConnectTimeout/ReadTimeout because the call exceeded 5 seconds; corporate proxy or self-signed TLS interception blocking the request.
Common situations: Offline or sandboxed dev environment; corporate proxy not configured (HTTP_PROXY/HTTPS_PROXY); slow or flaky mobile/satellite link; Google API occasionally slow under load.
Related errors
- Timeout waiting for OAuth callback
- Polling timed out for run id: `{run.id}` and thread id: `{th
- A client error occurred while getting search results.
- Failed to get search results.
- An unexpected error occurred while getting search results.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/05a58d0c89c051e0.
Report an issue: GitHub.