{"record":{"id":"dbd2c61026ec3cfb","repo":"BerriAI/litellm","slug":"reranker-requires-2-sentences","errorCode":null,"errorMessage":"reranker requires 2+ sentences","messagePattern":"reranker requires 2\\+ sentences","errorType":"exception","errorClass":"HuggingFaceError","httpStatus":400,"severity":"error","filePath":"litellm/llms/huggingface/embedding/handler.py","lineNumber":87,"sourceCode":"    _client_session: httpx.Client | None = None\n    _aclient_session: httpx.AsyncClient | None = None\n\n    def __init__(self) -> None:\n        super().__init__()\n\n    def _transform_input_on_pipeline_tag(self, input: list, pipeline_tag: str | None) -> dict:\n        if pipeline_tag is None:\n            return {\"inputs\": input}\n        if pipeline_tag == \"sentence-similarity\" or pipeline_tag == \"similarity\":\n            if len(input) < 2:\n                raise HuggingFaceError(\n                    status_code=400,\n                    message=\"sentence-similarity requires 2+ sentences\",\n                )\n            return {\"inputs\": {\"source_sentence\": input[0], \"sentences\": input[1:]}}\n        elif pipeline_tag == \"rerank\":\n            if len(input) < 2:\n                raise HuggingFaceError(\n                    status_code=400,\n                    message=\"reranker requires 2+ sentences\",\n                )\n            return {\"inputs\": {\"query\": input[0], \"texts\": input[1:]}}\n        return {\"inputs\": input}  # default to feature-extraction pipeline tag\n\n    async def _async_transform_input(\n        self,\n        model: str,\n        task_type: str | None,\n        embed_url: str,\n        input: list,\n        optional_params: dict,\n    ) -> dict:\n        hf_task = await async_get_hf_task_embedding_for_model(model=model, task_type=task_type, api_base=HF_HUB_URL)\n\n        data: Final = self._transform_input_on_pipeline_tag(input=input, pipeline_tag=hf_task)\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/huggingface/embedding/handler.py#L69-L105","documentation":"When the resolved pipeline tag is 'rerank' (or task_type='rerank' is passed), the HF embedding handler reshapes input into {'query': input[0], 'texts': input[1:]} — the TEI rerank payload. With fewer than two inputs there is nothing to rank against the query, so HuggingFaceError(400) 'reranker requires 2+ sentences' is raised client-side before any request.","triggerScenarios":"litellm.embedding(model='hf/<cross-encoder-reranker>', input=['single string']) where the model's pipeline_tag is rerank; passing task_type='rerank' with a one-element input list to any HF model.","commonSituations":"Pointing litellm.embedding at a cross-encoder/reranker model; batch pipelines whose candidate list was filtered down to one item; misunderstanding that reranking via this route requires query plus at least one candidate as one call.","solutions":["Pass query plus candidates in one input list: input=[query, doc1, doc2, ...]","For real reranking workflows prefer litellm.rerank with a supported rerank provider/model","For plain embeddings use an embedding model (feature-extraction/embed pipeline tag) instead of a reranker","Guard input length before calling when lists are built dynamically"],"exampleFix":"# before\nlitellm.embedding(model=\"hf/BAAI/bge-reranker-base\", input=[\"what is litellm?\"])\n\n# after\nlitellm.embedding(\n    model=\"hf/BAAI/bge-reranker-base\",\n    input=[\"what is litellm?\", \"a proxy for 100+ LLMs\"],\n)","handlingStrategy":"validation","validationCode":"def ok_for_rerank_model(input_list: list[str], pipeline_tag: str) -> bool:\n    if pipeline_tag == \"rerank\":\n        return len(input_list) >= 2\n    return True\n\nassert ok_for_rerank_model(input, \"rerank\"), \"need query + at least one candidate text\"","typeGuard":"def is_valid_hf_embedding_input(inputs: list, pipeline_tag: str | None) -> bool:\n    if pipeline_tag is None:\n        return True\n    if pipeline_tag in (\"sentence-similarity\", \"similarity\", \"rerank\"):\n        return len(inputs) >= 2\n    return True","tryCatchPattern":null,"preventionTips":["Use litellm.rerank (with a rerank provider) for ranking workloads instead of the embedding route","Do not point litellm.embedding at cross-encoder/reranker models for plain embeddings","Guard dynamically-built input lists to ensure at least query + one candidate before calling"],"tags":["huggingface","embeddings","rerank","input-validation","litellm"],"backgroundTag":"input-validation-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}