{"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":"validation","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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/huggingface/embedding/handler.py#L19-L55","documentation":"The sync HF embedding helper validates an explicitly passed task_type against the allowed set ('sentence-similarity', 'feature-extraction', 'rerank', 'embed', 'similarity', matching HF pipeline tags and TEI endpoints). Any other value raises a plain Exception before any request is made. If task_type is omitted, it is auto-derived from the model's pipeline_tag via the Hub API.","triggerScenarios":"litellm.embedding(model='hf/<model>', input=[...], task_type='<bad>') with a value outside the set — e.g. 'text-embedding', 'embedding', or an OpenAI-style task name. Raised from the synchronous path (line 37).","commonSituations":"Copy-pasting task_type names from other providers (OpenAI/Azure/Vertex); assuming a free-form string; mismatched casing ('Embed'); passing the task name of a different HF model family.","solutions":["Use one of the exact allowed values: sentence-similarity, feature-extraction, rerank, embed, similarity","Omit task_type entirely to auto-detect from the model's pipeline_tag on the Hub","For plain embeddings, 'embed' (TEI endpoint) or 'feature-extraction' are the right choices","Check the literal hf_tasks_embeddings in litellm/llms/huggingface/embedding/handler.py if unsure"],"exampleFix":"# before\nlitellm.embedding(model=\"hf/BAAI/bge-m3\", input=[\"hello\"], task_type=\"text-embedding\")\n\n# after\nlitellm.embedding(model=\"hf/BAAI/bge-m3\", input=[\"hello\"], task_type=\"embed\")\n# or omit task_type to auto-detect the pipeline tag","handlingStrategy":"validation","validationCode":"ALLOWED = {\"sentence-similarity\", \"feature-extraction\", \"rerank\", \"embed\", \"similarity\"}\n\nif task_type is not None and task_type not in ALLOWED:\n    raise ValueError(f\"task_type must be one of {sorted(ALLOWED)}\")","typeGuard":"HF_TASK_TYPES = {\"sentence-similarity\", \"feature-extraction\", \"rerank\", \"embed\", \"similarity\"}\n\ndef is_valid_hf_task_type(t: str | None) -> bool:\n    return t is None or t in HF_TASK_TYPES","tryCatchPattern":null,"preventionTips":["Centralize the allowed set as a constant shared across all embedding call sites","Prefer omitting task_type and letting pipeline_tag auto-detection choose","Add a unit test asserting your config's task_type values are within the literal set"],"tags":["huggingface","embeddings","task-type","invalid-parameter","litellm"],"backgroundTag":"invalid-argument-value","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}