{"record":{"id":"fd4fc563c44787ae","repo":"BerriAI/litellm","slug":"sentence-similarity-requires-2-sentences","errorCode":null,"errorMessage":"sentence-similarity requires 2+ sentences","messagePattern":"sentence-similarity requires 2\\+ sentences","errorType":"validation","errorClass":"HuggingFaceError","httpStatus":400,"severity":"error","filePath":"litellm/llms/huggingface/embedding/handler.py","lineNumber":80,"sourceCode":"\n    pipeline_tag: Final[str | None] = model_info_dict.get(\"pipeline_tag\", None)\n\n    return pipeline_tag\n\n\nclass HuggingFaceEmbedding(BaseLLM):\n    _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,","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/huggingface/embedding/handler.py#L62-L98","documentation":"Raised by the HuggingFace embedding handler when the model's pipeline tag is 'sentence-similarity' (or 'similarity') and the input list contains fewer than 2 strings. The sentence-similarity API shape requires one source_sentence plus at least one comparison sentence, so litellm refuses the call with HTTP 400 before sending a request.","triggerScenarios":"Calling litellm.embedding(model='huggingface/BAAI/bge-...', input=['only one sentence']) or input=[] on a model whose HuggingFace pipeline tag is sentence-similarity/similarity, or explicitly passing task='sentence-similarity' with a single-element input list.","commonSituations":"Developer reuses an embedding call written for feature-extraction models (which accept a single string) against a cross-encoder/similarity model; or splits a document and the chunking step yields one chunk.","solutions":["Pass at least 2 strings in the input list: the first becomes source_sentence, the rest become sentences to compare.","If you only want vector embeddings, use a feature-extraction model (e.g. sentence-transformers/all-MiniLM-L6-v2) instead of a similarity model.","If you intended cross-encoder scoring of one pair, still pass both members: input=[query, candidate]."],"exampleFix":"# before\nlitellm.embedding(model='huggingface/sentence-transformers/all-MiniLM-L6-v2', input=['hello world'])\n\n# after\nlitellm.embedding(model='huggingface/sentence-transformers/all-MiniLM-L6-v2', input=['hello world', 'hi there'])","handlingStrategy":"validation","validationCode":"def validate_similarity_input(input_list: list[str]) -> bool:\n    # sentence-similarity path needs a source sentence + >=1 comparison\n    return isinstance(input_list, list) and len(input_list) >= 2 and all(isinstance(x, str) and x.strip() for x in input_list)","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.embedding(model=model, input=texts)\nexcept litellm.llms.huggingface.common_utils.HuggingFaceError as e:\n    if 'requires 2+ sentences' in str(e):\n        raise ValueError(f'Need >=2 texts for similarity model {model}') from e\n    raise","preventionTips":["Check len(input) >= 2 before calling similarity-tagged models","Keep a model-to-pipeline-tag map in config so you know which models need pairs"],"tags":["huggingface","embeddings","validation","input-validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}