{"record":{"id":"092a3abb7b3f99ee","repo":"BerriAI/litellm","slug":"invalid-hf-task-task-valid-formats-hf-task","errorCode":null,"errorMessage":"Invalid hf task - {task}. Valid formats - {hf_tasks}.","messagePattern":"Invalid hf task - (.+?)\\. Valid formats - (.+?)\\.","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/llms/huggingface/embedding/transformation.py","lineNumber":211,"sourceCode":"        elif model in conversational_models:\n            return \"conversational\", model\n        elif \"roneneldan/TinyStories\" in model:\n            return \"text-generation\", model\n        else:\n            return \"text-generation-inference\", model  # default to tgi\n\n    def transform_request(\n        self,\n        model: str,\n        messages: list[AllMessageValues],\n        optional_params: dict,\n        litellm_params: dict,\n        headers: dict,\n    ) -> dict:\n        task: Final = litellm_params.get(\"task\", None)\n        ## VALIDATE API FORMAT\n        if task is None or not isinstance(task, str) or task not in hf_task_list:\n            raise Exception(f\"Invalid hf task - {task}. Valid formats - {hf_tasks}.\")\n\n        ## Load Config\n        config: Final = litellm.HuggingFaceEmbeddingConfig.get_config()\n        for k, v in config.items():\n            if (\n                k not in optional_params\n            ):  # completion(top_k=3) > huggingfaceConfig(top_k=3) <- allows for dynamic variables to be passed in\n                optional_params[k] = v\n\n        ### MAP INPUT PARAMS\n        #### HANDLE SPECIAL PARAMS\n        special_params: Final = self.get_special_options_params()\n        special_params_dict: Final = {}\n        # Create a list of keys to pop after iteration\n        keys_to_pop: Final = []\n\n        for k, v in optional_params.items():\n            if k in special_params:","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/huggingface/embedding/transformation.py#L193-L229","documentation":"Raised by the HuggingFace chat transformation when litellm_params['task'] is missing, not a string, or not one of the supported tasks: 'text-generation-inference', 'conversational', 'text-classification', 'text-generation' (defined in litellm/llms/huggingface/common_utils.py). It guards request building before any HTTP call.","triggerScenarios":"Calling completion() with custom_llm_provider='huggingface' (or model='huggingface/...') without task=..., or passing task='embedding' / task='sentence-similarity' / a typo like 'text-generation_inference'.","commonSituations":"Users assume the task is inferred from the model id; in this transformation path it must be passed explicitly. Typos or using a newer HF pipeline name not in the allow-list also trigger it.","solutions":["Pass a valid task: litellm.completion(model='huggingface/<model>', messages=..., task='text-generation-inference').","Use one of exactly: text-generation-inference, conversational, text-classification, text-generation.","For embeddings/rerank, use litellm.embedding / litellm.rerank instead of the completion path."],"exampleFix":"# before\nlitellm.completion(model='huggingface/meta-llama/Llama-3.2-3B-Instruct', messages=messages)\n\n# after\nlitellm.completion(model='huggingface/meta-llama/Llama-3.2-3B-Instruct', messages=messages, task='text-generation-inference')","handlingStrategy":"validation","validationCode":"HF_TASKS = {'text-generation-inference', 'conversational', 'text-classification', 'text-generation'}\n\ndef validate_hf_task(task: str | None) -> str:\n    if task not in HF_TASKS:\n        raise ValueError(f'task must be one of {sorted(HF_TASKS)}, got {task!r}')\n    return task","typeGuard":"def is_valid_hf_task(task: object) -> bool:\n    return isinstance(task, str) and task in {'text-generation-inference', 'conversational', 'text-classification', 'text-generation'}","tryCatchPattern":null,"preventionTips":["Centralize HF task selection in one config constant","Add a startup assertion that validates configured tasks against the allow-list"],"tags":["huggingface","completion","validation","task-parameter"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}