{"record":{"id":"8f84b584a91381f5","repo":"apache/beam","slug":"huggingfacepipelinemodelhandler-requires-either-task-or","errorCode":null,"errorMessage":"HuggingFacePipelineModelHandler requires either 'task' or 'model' to be specified.","messagePattern":"HuggingFacePipelineModelHandler requires either 'task' or 'model' to be specified\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/yaml_ml.py","lineNumber":369,"sourceCode":"\n    handler_kwargs = {}\n    if inference_fn_obj:\n      handler_kwargs['inference_fn'] = inference_fn_obj\n\n    _handler = HuggingFacePipelineModelHandler(\n        task=task,\n        model=model,\n        device=device,\n        load_pipeline_args=load_pipeline_args,\n        **handler_kwargs,\n        **kwargs)\n\n    super().__init__(_handler, preprocess, postprocess)\n\n  @staticmethod\n  def validate(config):\n    if not config or (not config.get('task') and not config.get('model')):\n      raise ValueError(\n          \"HuggingFacePipelineModelHandler requires either 'task' or \"\n          \"'model' to be specified.\")\n\n  def inference_output_type(self):\n    return Any\n\n\n@beam.ptransform.ptransform_fn\ndef run_inference(\n    pcoll,\n    model_handler: dict[str, Any],\n    inference_tag: Optional[str] = 'inference',\n    inference_args: Optional[dict[str, Any]] = None) -> beam.PCollection[beam.Row]:  # pylint: disable=line-too-long\n  \"\"\"\n  A transform that takes the input rows, containing examples (or features), for\n  use on an ML model. The transform then appends the inferences\n  (or predictions) for those examples to the input row.\n","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/yaml_ml.py#L351-L387","documentation":"Static validation for the HuggingFace pipeline handler requires the YAML config to name at least one of 'task' (e.g. text-classification) or 'model' (hub id/path). If the config is empty or lacks both keys, validate() raises this ValueError.","triggerScenarios":"Calling HuggingFacePipelineModelHandler.validate with a config dict that is None/empty or contains neither 'task' nor 'model', e.g. YAML config: {} or config with only preprocess/postprocess.","commonSituations":"Omitting the config block entirely in a YAML pipeline; misspelling the key (e.g. 'model_id' or 'task_name'); nesting the values under the wrong level of YAML indentation.","solutions":["Add 'task' to the handler config, e.g. task: text-classification","Or add 'model' with a HuggingFace model id or local path","Check YAML indentation so task/model sit inside config","Fix key misspellings to exactly 'task' or 'model'"],"exampleFix":"# before\n- type: HuggingFacePipeline\n  config: {}\n# after\n- type: HuggingFacePipeline\n  config:\n    task: text-classification","handlingStrategy":"validation","validationCode":"def validate_hf_config(config):\n    if not isinstance(config, dict) or not (config.get('task') or config.get('model')):\n        raise ValueError(\"HuggingFace handler config needs 'task' or 'model'\")","typeGuard":"def is_valid_hf_config(config):\n    return isinstance(config, dict) and bool(config.get('task') or config.get('model'))","tryCatchPattern":null,"preventionTips":["Always specify 'task' or 'model' in the handler config","Lint YAML pipeline files before submission","Keep keys exactly 'task' and 'model'"],"tags":["python","apache-beam","yaml","huggingface","validation"],"backgroundTag":"missing-required-config-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}