{"record":{"id":"c4113a0b2e25c95a","repo":"BerriAI/litellm","slug":"sentence-transformers-requires-2-sentences","errorCode":null,"errorMessage":"sentence transformers requires 2+ sentences","messagePattern":"sentence transformers requires 2\\+ sentences","errorType":"validation","errorClass":"HuggingFaceError","httpStatus":400,"severity":"error","filePath":"litellm/llms/huggingface/embedding/handler.py","lineNumber":148,"sourceCode":"            else:\n                data[k] = v\n\n        return data\n\n    def _transform_input(\n        self,\n        input: list,\n        model: str,\n        call_type: Literal[\"sync\", \"async\"],\n        optional_params: dict,\n        embed_url: str,\n    ) -> dict:\n        data: dict = {}\n\n        ## TRANSFORMATION ##\n        if \"sentence-transformers\" in model:\n            if len(input) == 0:\n                raise HuggingFaceError(\n                    status_code=400,\n                    message=\"sentence transformers requires 2+ sentences\",\n                )\n            data = {\"inputs\": {\"source_sentence\": input[0], \"sentences\": input[1:]}}\n        else:\n            data = {\"inputs\": input}\n\n            task_type: Final = optional_params.pop(\"input_type\", None)\n\n            if call_type == \"sync\":\n                hf_task: Final = get_hf_task_embedding_for_model(model=model, task_type=task_type, api_base=HF_HUB_URL)\n            elif call_type == \"async\":\n                return self._async_transform_input(model=model, task_type=task_type, embed_url=embed_url, input=input)\n\n            data = self._transform_input_on_pipeline_tag(input=input, pipeline_tag=hf_task)\n\n        if len(optional_params.keys()) > 0:\n            data = self._process_optional_params(data=data, optional_params=optional_params)","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/huggingface/embedding/handler.py#L130-L166","documentation":"Raised when the model name contains 'sentence-transformers' and the input list is empty. Note the message says '2+ sentences' but the code only checks len(input) == 0, so in practice it fires only for an empty input list; a single sentence is accepted (and silently sends an empty 'sentences' array to HF).","triggerScenarios":"litellm.embedding(model='huggingface/sentence-transformers/all-MiniLM-L6-v2', input=[]) — an empty list triggers the raise. A single-element input does NOT raise, despite the message.","commonSituations":"Upstream batching/chunking code produces an empty list (empty document, filtered-out batch) that is passed straight through to the embedding call.","solutions":["Guard your pipeline: skip or log-and-continue when the list of texts is empty before calling embedding().","If you genuinely need pairwise similarity, pass 2+ sentences (input[0] is source_sentence, the rest are compared).","For plain embeddings of N texts, be aware this path sends {source_sentence, sentences} — for a single text use a model without 'sentence-transformers' in the name or verify the response shape."],"exampleFix":"# before\ntexts = chunk(doc)  # may be []\nresp = litellm.embedding(model='huggingface/sentence-transformers/all-MiniLM-L6-v2', input=texts)\n\n# after\ntexts = chunk(doc)\nif not texts:\n    return []\nresp = litellm.embedding(model='huggingface/sentence-transformers/all-MiniLM-L6-v2', input=texts)","handlingStrategy":"validation","validationCode":"def safe_embed_texts(model: str, texts: list[str]):\n    if not texts:\n        return None  # nothing to embed; skip the API call entirely\n    return texts","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass an empty input list to embedding calls","Add a unit test asserting embedding is not called with [] (mock the client)"],"tags":["huggingface","embeddings","validation","empty-input","misleading-message"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}