{"record":{"id":"03d17d2b5f896c6a","repo":"microsoft/semantic-kernel","slug":"count-value-must-be-less-than-or-equal-to-10","errorCode":null,"errorMessage":"count value must be less than or equal to 10.","messagePattern":"count value must be less than or equal to 10\\.","errorType":"validation","errorClass":"ServiceInvalidRequestError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/google_search.py","lineNumber":283,"sourceCode":"        headers = {\"user_agent\": SEMANTIC_KERNEL_USER_AGENT}\n        try:\n            async with AsyncClient(timeout=5) as client:\n                response = await client.get(full_url, headers=headers)\n                response.raise_for_status()\n                return GoogleSearchResponse.model_validate_json(response.text)\n        except HTTPStatusError as ex:\n            logger.error(f\"Failed to get search results: {ex}\")\n            raise ServiceInvalidRequestError(\"Failed to get search results.\") from ex\n        except RequestError as ex:\n            logger.error(f\"Client error occurred: {ex}\")\n            raise ServiceInvalidRequestError(\"A client error occurred while getting search results.\") from ex\n        except Exception as ex:\n            logger.error(f\"An unexpected error occurred: {ex}\")\n            raise ServiceInvalidRequestError(\"An unexpected error occurred while getting search results.\") from ex\n\n    def _validate_options(self, options: SearchOptions) -> None:\n        if options.top > 10:\n            raise ServiceInvalidRequestError(\"count value must be less than or equal to 10.\")\n\n    def _parse_filter_lambda(self, filter_lambda: Callable | str) -> list[dict[str, str]]:\n        \"\"\"Parse a string lambda or string expression into a list of {field: value} dicts using AST.\"\"\"\n        expr = filter_lambda if isinstance(filter_lambda, str) else getsource(filter_lambda).strip()\n        tree = ast.parse(expr, mode=\"eval\")\n        node = tree.body\n        visitor = SearchLambdaVisitor(valid_parameters=QUERY_PARAMETERS)\n        visitor.visit(node)\n        return visitor.filters\n\n    def _build_query(self, query: str, options: SearchOptions) -> str:\n        params = {\n            \"key\": self.settings.api_key.get_secret_value(),\n            \"cx\": self.settings.engine_id,\n            \"num\": options.top,\n            \"start\": options.skip,\n        }\n        # parse the filter lambdas to query parameters","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/google_search.py#L265-L301","documentation":"_validate_options enforces options.top <= 10 because the Google Custom Search API num parameter accepts at most 10 results per request. Anything larger raises ServiceInvalidRequestError before the HTTP call is made.","triggerScenarios":"Calling search(query, top=11) or any value greater than 10; passing SearchOptions(top=25); paging logic that computes a window larger than 10.","commonSituations":"Porting defaults from connectors that allow larger pages (e.g. Bing); UI defaulting to 20/50 results; bulk-export scripts requesting many results per call.","solutions":["Set top to 10 or less per call.","For more results, paginate using skip (mapped to the API start param) in steps of <= 10.","Clamp user-supplied counts before calling search."],"exampleFix":"# before\nresults = await google.search('skates', top=25)  # -> [1306]\n\n# after\ntop = min(requested_top, 10)\nall_items = []\nfor skip in range(0, requested_top, top):\n    res = await google.search('skates', top=top, skip=skip, include_total_count=True)\n    all_items.extend(res.results)","handlingStrategy":"validation","validationCode":"def safe_top(requested: int) -> int:\n    if requested < 1:\n        raise ValueError('top must be >= 1')\n    return min(requested, 10)  # Google Custom Search max is 10","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceInvalidRequestError\ntry:\n    results = await google.search(query, top=top)\nexcept ServiceInvalidRequestError as ex:\n    if 'less than or equal to 10' in str(ex):\n        results = await google.search(query, top=10)\n    else:\n        raise","preventionTips":["Clamp user-supplied counts to <= 10 before calling search.","Page through results with skip in increments of <= 10 instead of raising top."],"tags":["google-search","validation","pagination"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}