BerriAI/litellm · error · HuggingFaceError
sentence transformers requires 2+ sentences
Error message
sentence transformers requires 2+ sentences
What it means
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).
Source
Thrown at litellm/llms/huggingface/embedding/handler.py:148
else:
data[k] = v
return data
def _transform_input(
self,
input: list,
model: str,
call_type: Literal["sync", "async"],
optional_params: dict,
embed_url: str,
) -> dict:
data: dict = {}
## TRANSFORMATION ##
if "sentence-transformers" in model:
if len(input) == 0:
raise HuggingFaceError(
status_code=400,
message="sentence transformers requires 2+ sentences",
)
data = {"inputs": {"source_sentence": input[0], "sentences": input[1:]}}
else:
data = {"inputs": input}
task_type: Final = optional_params.pop("input_type", None)
if call_type == "sync":
hf_task: Final = get_hf_task_embedding_for_model(model=model, task_type=task_type, api_base=HF_HUB_URL)
elif call_type == "async":
return self._async_transform_input(model=model, task_type=task_type, embed_url=embed_url, input=input)
data = self._transform_input_on_pipeline_tag(input=input, pipeline_tag=hf_task)
if len(optional_params.keys()) > 0:
data = self._process_optional_params(data=data, optional_params=optional_params)View on GitHub (pinned to 6c2dcb801b)
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.
Example fix
# before
texts = chunk(doc) # may be []
resp = litellm.embedding(model='huggingface/sentence-transformers/all-MiniLM-L6-v2', input=texts)
# after
texts = chunk(doc)
if not texts:
return []
resp = litellm.embedding(model='huggingface/sentence-transformers/all-MiniLM-L6-v2', input=texts) Defensive patterns
Strategy: validation
Validate before calling
def safe_embed_texts(model: str, texts: list[str]):
if not texts:
return None # nothing to embed; skip the API call entirely
return texts Prevention
- Never pass an empty input list to embedding calls
- Add a unit test asserting embedding is not called with [] (mock the client)
When it happens
Trigger: 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.
Common situations: Upstream batching/chunking code produces an empty list (empty document, filtered-out batch) that is passed straight through to the embedding call.
Related errors
- Invalid task_type={task_type}. Expected one of={hf_tasks_emb
- sentence-similarity requires 2+ sentences
- Empty image_url string is not valid.
- reranker requires 2+ sentences
- {embeddings[error]}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/c4113a0b2e25c95a.
Report an issue: GitHub.