{"record":{"id":"42fa61997e91f40d","repo":"apache/beam","slug":"task-type-must-be-one-of-task-type-inputs-got-task-type","errorCode":null,"errorMessage":"task_type must be one of {TASK_TYPE_INPUTS}, got {task_type}","messagePattern":"task_type must be one of (.+?), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/transforms/embeddings/vertex_ai.py","lineNumber":111,"sourceCode":"\n\nclass _VertexAITextEmbeddingHandler(RemoteModelHandler):\n  \"\"\"\n  Note: Intended for internal use and guarantees no backwards compatibility.\n  \"\"\"\n  def __init__(\n      self,\n      model_name: str,\n      title: Optional[str] = None,\n      task_type: str = DEFAULT_TASK_TYPE,\n      project: Optional[str] = None,\n      location: Optional[str] = None,\n      credentials: Optional[Credentials] = None,\n      **kwargs):\n    vertexai.init(project=project, location=location, credentials=credentials)\n    self.model_name = model_name\n    if task_type not in TASK_TYPE_INPUTS:\n      raise ValueError(\n          f\"task_type must be one of {TASK_TYPE_INPUTS}, got {task_type}\")\n    self.task_type = task_type\n    self.title = title\n\n    super().__init__(\n        namespace='VertexAITextEmbeddingHandler',\n        retry_filter=_retry_on_appropriate_gcp_error,\n        **kwargs)\n\n  def request(\n      self,\n      batch: Sequence[str],\n      model: TextEmbeddingModel,\n      inference_args: Optional[dict[str, Any]] = None):\n    embeddings = []\n    batch_size = _BATCH_SIZE\n    for i in range(0, len(batch), batch_size):\n      text_batch_strs = batch[i:i + batch_size]","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/transforms/embeddings/vertex_ai.py#L93-L129","documentation":"VertexAITextEmbeddings validates that task_type is a member of the TASK_TYPE_INPUTS set of supported Vertex AI embedding task types. An unknown or misspelled task_type is rejected at construction with ValueError before any API call is made.","triggerScenarios":"Constructing VertexAITextEmbeddings(model_name=..., task_type='embedding' or any value not in TASK_TYPE_INPUTS).","commonSituations":"Typos like 'retrival_query' vs 'RETRIEVAL_QUERY'; copying task_type values from another embedding provider (e.g. OpenAI) that Vertex AI doesn't accept; lowercasing a valid enum value.","solutions":["Use a valid task_type such as 'RETRIEVAL_QUERY', 'RETRIEVAL_DOCUMENT', 'SEMANTIC_SIMILARITY', 'CLASSIFICATION', 'CLUSTERING' (match the TASK_TYPE_INPUTS set exactly, uppercase).","Import TASK_TYPE_INPUTS from apache_beam.ml.transforms.embeddings.vertex_ai and pick from it programmatically.","Omit task_type if a default is acceptable."],"exampleFix":"// before\nhandler = VertexAITextEmbeddings(columns=['text'], task_type='retrieval_query')\n// after\nhandler = VertexAITextEmbeddings(columns=['text'], task_type='RETRIEVAL_QUERY')","handlingStrategy":"validation","validationCode":"from apache_beam.ml.transforms.embeddings.vertex_ai import TASK_TYPE_INPUTS\nassert task_type in TASK_TYPE_INPUTS, f'{task_type} not in {TASK_TYPE_INPUTS}'","typeGuard":null,"tryCatchPattern":"try:\n    handler = VertexAITextEmbeddings(columns=['text'], task_type=my_task)\nexcept ValueError as e:\n    if 'task_type' in str(e):\n        handler = VertexAITextEmbeddings(columns=['text'], task_type=list(TASK_TYPE_INPUTS)[0])","preventionTips":["Pick task_type from TASK_TYPE_INPUTS, never hardcode","Keep enum values uppercase"],"tags":["python","vertex-ai","embeddings","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}