{"record":{"id":"baaaa48a77303f7d","repo":"BerriAI/litellm","slug":"query-is-required-for-vertex-ai-rerank","errorCode":null,"errorMessage":"query is required for Vertex AI rerank","messagePattern":"query is required for Vertex AI rerank","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/vertex_ai/rerank/transformation.py","lineNumber":117,"sourceCode":"        # If 'Authorization' is provided in headers, it overrides the default.\n        if \"Authorization\" in headers:\n            default_headers[\"Authorization\"] = headers[\"Authorization\"]\n\n        # Merge other headers, overriding any default ones except Authorization\n        return {**default_headers, **headers}\n\n    def transform_rerank_request(\n        self,\n        model: str,\n        optional_rerank_params: dict,\n        headers: dict,\n        litellm_params: dict | None = None,\n    ) -> dict:\n        \"\"\"\n        Transform the request from Cohere format to Vertex AI Discovery Engine format\n        \"\"\"\n        if \"query\" not in optional_rerank_params:\n            raise ValueError(\"query is required for Vertex AI rerank\")\n        if \"documents\" not in optional_rerank_params:\n            raise ValueError(\"documents is required for Vertex AI rerank\")\n\n        query: Final = optional_rerank_params[\"query\"]\n        documents: Final = optional_rerank_params[\"documents\"]\n        top_n: Final = optional_rerank_params.get(\"top_n\", None)\n        return_documents: Final = optional_rerank_params.get(\"return_documents\", True)\n\n        # Convert documents to records format\n        records: Final = []\n        for idx, document in enumerate(documents):\n            if isinstance(document, str):\n                content = document\n                title = \" \".join(document.split()[:3])  # First 3 words as title\n            else:\n                # Handle dict format\n                content = document.get(\"text\", str(document))\n                title = document.get(\"title\", \" \".join(content.split()[:3]))","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/rerank/transformation.py#L99-L135","documentation":"ValueError raised in transform_rerank_request when 'query' is absent from the rerank parameters. LiteLLM exposes rerank in the Cohere format where both query and documents are mandatory; the Vertex AI Discovery Engine ranking API has no default query, so the request cannot be transformed.","triggerScenarios":"Calling litellm.rerank with a vertex_ai model without a query argument, or with the query renamed/nested (e.g. 'q', 'text', or tucked inside another dict).","commonSituations":"Migrating from search APIs with different parameter names; building params dynamically and skipping empty queries; schema confusion between rerank and retrieval APIs.","solutions":["Pass query='...' to litellm.rerank","Check for renamed keys like q or search_query in your params dict","Reject empty queries upstream instead of forwarding them"],"exampleFix":"# before\nlitellm.rerank(model='vertex_ai/semantic-ranker', documents=docs)\n\n# after\nlitellm.rerank(model='vertex_ai/semantic-ranker', query='what is litellm?', documents=docs)","handlingStrategy":"validation","validationCode":"def valid_rerank_params(params: dict) -> bool:\n    return bool(params.get('query'))","typeGuard":"def is_rerank_request(value: dict) -> bool:\n    return isinstance(value, dict) and isinstance(value.get('query'), str) and bool(value['query'].strip())","tryCatchPattern":"try:\n    resp = litellm.rerank(model=model, **params)\nexcept ValueError as e:\n    if 'query is required' in str(e):\n        raise SystemExit('Missing rerank query')\n    raise","preventionTips":["Require query in your own API schema before calling rerank","Normalize parameter names (q/search_query -> query) in one adapter","Reject empty queries early instead of forwarding them"],"tags":["vertex-ai","rerank","request-validation","missing-parameter"],"backgroundTag":"missing-required-parameter","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T10:36:37.832Z"}