{"record":{"id":"2b54cd52bf915d8b","repo":"mlflow/mlflow","slug":"when-task-is-specified-as-inference-task-th","errorCode":null,"errorMessage":"When `task` is specified as `{inference_task}`, the signature would be set by MLflow. Please do not set the signature.","messagePattern":"When `task` is specified as `(.+?)`, the signature would be set by MLflow\\. Please do not set the signature\\.","errorType":"exception","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/transformers/llm_inference_utils.py","lineNumber":77,"sourceCode":"}\n\n_LLM_INFERENCE_TASK_TO_DATA_FIELD = {\n    _LLM_INFERENCE_TASK_CHAT: \"messages\",\n    _LLM_INFERENCE_TASK_COMPLETIONS: \"prompt\",\n}\n\n\ndef infer_signature_from_llm_inference_task(\n    inference_task: str, signature: ModelSignature | None = None\n) -> ModelSignature:\n    \"\"\"\n    Infers the signature according to the MLflow inference task.\n    Raises exception if a signature is given.\n    \"\"\"\n    inferred_signature = _SIGNATURE_FOR_LLM_INFERENCE_TASK[inference_task]\n\n    if signature is not None and signature != inferred_signature:\n        raise MlflowException(\n            f\"When `task` is specified as `{inference_task}`, the signature would \"\n            \"be set by MLflow. Please do not set the signature.\"\n        )\n    return inferred_signature\n\n\ndef convert_messages_to_prompt(messages: list[dict[str, Any]], tokenizer) -> str:\n    \"\"\"For the Chat inference task, apply chat template to messages to create prompt.\n\n    Args:\n        messages: List of message e.g. [{\"role\": user, \"content\": xxx}, ...]\n        tokenizer: The tokenizer object used for inference.\n\n    Returns:\n        The prompt string contains the messages.\n    \"\"\"\n    if not (isinstance(messages, list) and all(isinstance(msg, dict) for msg in messages)):\n        raise MlflowException(","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/transformers/llm_inference_utils.py#L59-L95","documentation":"Error \"When `task` is specified as `{inference_task}`, the signature would be set by MLflow. Please do not set the signature.\" thrown in mlflow/mlflow.","triggerScenarios":"Thrown at mlflow/transformers/llm_inference_utils.py:77 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}