microsoft/semantic-kernel · error · ServiceInvalidRequestError

offset must be less than 10.

Error message

offset must be less than 10.

What it means

Brave caps the offset at 9 (so skip + top stays within the API's result-depth limit); the connector enforces skip <= 9 client-side and raises ServiceInvalidRequestError for skip > 9. This reflects Brave's deep-pagination limit, not an arbitrary connector choice.

Source

Thrown at python/semantic_kernel/connectors/brave.py:252

            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 <= 0:
            raise ServiceInvalidRequestError("count value must be greater than 0.")
        if options.top >= 21:
            raise ServiceInvalidRequestError("count value must be less than 21.")

        if options.skip < 0:
            raise ServiceInvalidRequestError("offset must be greater than or equal to 0.")
        if options.skip > 9:
            raise ServiceInvalidRequestError("offset must be less than 10.")

    def _get_url(self) -> str:
        return DEFAULT_URL

    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_request_parameters(self, query: str, options: SearchOptions) -> dict[str, str | int | bool]:
        params: dict[str, str | int] = {"q": query or "", "count": options.top, "offset": options.skip}
        if not options.filter:
            return params
        filters = options.filter

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Keep skip within [0, 9]; combine with top <= 20 to stay within Brave's max result depth (skip + top <= ~10 offset).
  2. For deeper result sets, narrow the query or accept Brave's pagination ceiling rather than increasing offset.
  3. Clamp computed offsets to 9 before calling search.

Example fix

// before
results = await connector.search(query, skip=20)
// after
results = await connector.search(query, skip=min(9, computed_offset))
Defensive patterns

Strategy: validation

Validate before calling

if skip > 9:
    raise ValueError("Brave caps offset at 9")
results = await connector.search(query, skip=min(9, skip))

Type guard

def is_valid_skip(skip: int) -> bool:
    return isinstance(skip, int) and 0 <= skip <= 9

Prevention

When it happens

Trigger: Calling search() with skip > 9, e.g. skip=10 or higher to reach page 3+. The check at brave.py:252-253 fires in _validate_options.

Common situations: Attempting deep pagination beyond what Brave returns; computing skip as page_number * page_size and exceeding 9.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/e88bc97fea35baea. Report an issue: GitHub.