{"record":{"id":"0af708821f42c3aa","repo":"BerriAI/litellm","slug":"pages-must-be-between-pages-min-and-pages-max","errorCode":null,"errorMessage":"pages must be between {PAGES_MIN} and {PAGES_MAX}, got {self.pages}","messagePattern":"pages must be between (.+?) and (.+?), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/apiserpent/search/defaults.py","lineNumber":49,"sourceCode":"    \"\"\"\n\n    engine: SearchEngine = \"google\"\n    country: str = \"us\"\n    num: int = 10\n    format: ResponseFormat = \"full\"\n    pages: int | None = None\n    freshness: Freshness | None = None\n    safe: SafeSearch | None = None\n    language: str | None = None\n    pixel_position: bool | None = None\n\n    def __post_init__(self) -> None:\n        # num's deep-search floor (NUM_MIN_DEEP) is endpoint-specific and enforced\n        # in the transform layer; here we only bound the absolute range.\n        if not NUM_MIN <= self.num <= NUM_MAX:\n            raise ValueError(f\"num must be between {NUM_MIN} and {NUM_MAX}, got {self.num}\")\n        if self.pages is not None and not PAGES_MIN <= self.pages <= PAGES_MAX:\n            raise ValueError(f\"pages must be between {PAGES_MIN} and {PAGES_MAX}, got {self.pages}\")\n\n    def to_request_params(self) -> dict:\n        \"\"\"Return non-None fields as request params, booleans lowercased.\"\"\"\n        params: Final[dict] = {}\n        for key, value in asdict(self).items():\n            if value is None:\n                continue\n            params[key] = str(value).lower() if isinstance(value, bool) else value\n        return params\n\n    @classmethod\n    def field_names(cls) -> set:\n        return set(cls.__dataclass_fields__.keys())\n\n\nQUICK_SEARCH_PATH: Final = \"/api/search/quick\"\nDEEP_SEARCH_PATH: Final = \"/api/search\"\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/apiserpent/search/defaults.py#L31-L67","documentation":"Companion validation in the apiserpent search defaults: when 'pages' (page count for multi-page fetches) is provided it must be an int in [1, 10]. None is allowed and means single-page; anything outside the range raises at construction time in __post_init__.","triggerScenarios":"Constructing SearchDefaults with pages=0, pages=11+, or a negative value. pages=0 (perhaps intended as 'no paging') is rejected — omit the field or use None instead.","commonSituations":"Config files with pages: 0 as a 'disabled' sentinel; arithmetic that derives pages from a desired total result count (e.g. total_results/10 with a large total); copying example configs with unsupported values.","solutions":["Set pages to a value from 1 to 10, or leave it out entirely for single-page behavior.","Compute pages as min(10, ceil(desired_results / num)).","If you truly need more than 10 pages, issue multiple search calls client-side."],"exampleFix":"# before\nparams = SearchDefaults(num=50, pages=25)\n\n# after\nparams = SearchDefaults(num=100, pages=5)  # same 500-result budget within limits","handlingStrategy":"validation","validationCode":"PAGES_MIN, PAGES_MAX = 1, 10\n\ndef clamp_pages(pages: int | None) -> int | None:\n    if pages is None:\n        return None\n    return max(PAGES_MIN, min(pages, PAGES_MAX))","typeGuard":"def is_valid_pages(pages: object) -> bool:\n    return pages is None or (isinstance(pages, int) and not isinstance(pages, bool) and 1 <= pages <= 10)","tryCatchPattern":"try:\n    params = SearchDefaults(num=num, pages=pages)\nexcept ValueError:\n    params = SearchDefaults(num=num, pages=max(1, min(pages or 1, 10)))","preventionTips":["Never use pages=0 as a 'disabled' sentinel — omit the field instead.","Derive pages with min(10, ceil(desired_results / num)).","Validate search config files at load time with the same 1..10 rule."],"tags":["apiserpent","search","validation","pagination"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}