{"record":{"id":"c7ec8fd8c8e5c71a","repo":"BerriAI/litellm","slug":"invalid-task-type-task-type-expected-one-of-hf","errorCode":null,"errorMessage":"Invalid task_type={task_type}. Expected one of={hf_tasks_embeddings}","messagePattern":"Invalid task_type=(.+?)\\. Expected one of=(.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/llms/huggingface/embedding/handler.py","lineNumber":37,"sourceCode":"from .transformation import HuggingFaceEmbeddingConfig\n\nconfig: Final = HuggingFaceEmbeddingConfig()\n\nHF_HUB_URL: Final = \"https://huggingface.co\"\n\nhf_tasks_embeddings: Final = (\n    Literal[  # pipeline tags + hf tei endpoints - https://huggingface.github.io/text-embeddings-inference/#/\n        \"sentence-similarity\", \"feature-extraction\", \"rerank\", \"embed\", \"similarity\"\n    ]\n)\n\n\ndef get_hf_task_embedding_for_model(model: str, task_type: str | None, api_base: str) -> str | None:\n    if task_type is not None:\n        if task_type in get_args(hf_tasks_embeddings):\n            return task_type\n        else:\n            raise Exception(f\"Invalid task_type={task_type}. Expected one of={hf_tasks_embeddings}\")\n    http_client: Final = HTTPHandler(concurrent_limit=1)\n\n    model_info: Final = http_client.get(url=f\"{api_base}/api/models/{model}\")\n\n    model_info_dict: Final = model_info.json()\n\n    pipeline_tag: Final[str | None] = model_info_dict.get(\"pipeline_tag\", None)\n\n    return pipeline_tag\n\n\nasync def async_get_hf_task_embedding_for_model(model: str, task_type: str | None, api_base: str) -> str | None:\n    if task_type is not None:\n        if task_type in get_args(hf_tasks_embeddings):\n            return task_type\n        else:\n            raise Exception(f\"Invalid task_type={task_type}. Expected one of={hf_tasks_embeddings}\")\n    http_client: Final = get_async_httpx_client(","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/huggingface/embedding/handler.py#L19-L55","documentation":"Raised by get_hf_task_embedding_for_model (sync path) when the caller passes a task_type that is not one of the supported embedding pipeline tags: 'sentence-similarity', 'feature-extraction', 'rerank', 'embed', 'similarity'. HF embedding routing uses the model's pipeline tag to pick the right TEI endpoint; an unknown task_type is rejected before any request is sent.","triggerScenarios":"Calling litellm.embedding(model='hf/<model>', ..., task_type='<bad>') with a value outside the allowed set — e.g. 'embedding', 'text-embedding', 'embeddings' (plural), or a chat tag like 'text-generation'. Exact string match only.","commonSituations":"Assuming the value is 'embedding' instead of 'embed'; copying task_type values from HF Hub UI labels that differ from the literal slugs; case mistakes ('Embed' vs 'embed'); parameter added defensively with a guessed default.","solutions":["Use one of the exact allowed strings: 'sentence-similarity', 'feature-extraction', 'rerank', 'embed', or 'similarity' (lowercase).","If unsure, omit task_type entirely — the function then queries the model's pipeline_tag from the Hub API and uses that automatically.","Most embeddings use cases should simply not pass task_type; set it only when the auto-detected tag is wrong."],"exampleFix":"# before\nlitellm.embedding(model='hf/BAAI/bge-large-en-v1.5', input=['hi'], task_type='embedding')\n# raises Exception: Invalid task_type=embedding\n\n# after — omit it and let it auto-detect\nlitellm.embedding(model='hf/BAAI/bge-large-en-v1.5', input=['hi'])\n# or use an allowed value: task_type='feature-extraction'\n","handlingStrategy":"validation","validationCode":"from typing import get_args\nfrom litellm.llms.huggingface.embedding.handler import hf_tasks_embeddings\n\nALLOWED_TASK_TYPES = set(get_args(hf_tasks_embeddings))\n# {'sentence-similarity','feature-extraction','rerank','embed','similarity'}\n\ndef valid_task_type(task_type: str | None) -> bool:\n    return task_type is None or task_type in ALLOWED_TASK_TYPES","typeGuard":"def is_valid_hf_task_type(v: str) -> bool:\n    \"\"\"Narrows a string to a HF embeddings task_type slug.\"\"\"\n    return v in {\"sentence-similarity\", \"feature-extraction\", \"rerank\", \"embed\", \"similarity\"}","tryCatchPattern":null,"preventionTips":["Default to omitting task_type — auto-detection via the model's pipeline_tag is usually correct.","If you accept task_type from config/user input, validate against the literal slug set above before the embedding call."],"tags":["huggingface","embeddings","task-type","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}