apache/beam · error · ValueError

Missing type in ML transform spec {spec}

Error message

Missing type in ML transform spec {spec}

What it means

_config_to_obj, which materializes ML transform providers from YAML specs, found no 'type' key in the spec dict; without it there is no provider class to look up, so the spec cannot be turned into a transform object.

Source

Thrown at sdks/python/apache_beam/yaml/yaml_ml.py:591

  return (
      pcoll | RunInference(
          model_handler=KeyedModelHandler(
              model_handler_provider.underlying_handler()).with_preprocess_fn(
                  model_handler_provider._preprocess_fn_internal()).
          with_postprocess_fn(
              model_handler_provider._postprocess_fn_internal()),
          inference_args=inference_args)
      | beam.Map(
          lambda row: beam.Row(
              **{
                  **row[0]._asdict(), str(inference_tag): row[1]
              })).with_output_types(schema))


def _config_to_obj(spec):
  if 'type' not in spec:
    raise ValueError(f"Missing type in ML transform spec {spec}")
  if 'config' not in spec:
    raise ValueError(f"Missing config in ML transform spec {spec}")
  constructor = _transform_constructors.get(spec['type'])
  if constructor is None:
    raise ValueError("Unknown ML transform type: %r" % spec['type'])
  return constructor(**spec['config'])


@beam.ptransform.ptransform_fn
def ml_transform(
    pcoll,
    write_artifact_location: Optional[str] = None,
    read_artifact_location: Optional[str] = None,
    transforms: Optional[list[Any]] = None):
  if MLTransform is None:
    raise ValueError(
        'No MLTransform found. Please install tensorflow-transform or '
        'sentence-transformers to use this transform.')

View on GitHub (pinned to 12126d8942)

Solutions

  1. Add 'type' naming the ML transform, e.g. type: RunInference
  2. Fix YAML indentation so type sits inside the transform spec
  3. Validate the spec dict before constructing

Example fix

# before
- name: inference
  config: {model_handler: {...}}
# after
- name: inference
  type: RunInference
  config: {model_handler: {...}}
Defensive patterns

Strategy: validation

Validate before calling

def check_spec(spec):
    if 'type' not in spec:
        raise ValueError(f'ML transform spec needs type: {spec}')

Type guard

def has_type(spec):
    return isinstance(spec, dict) and 'type' in spec

Prevention

When it happens

Trigger: Passing an ml_transform spec dict (or the transform under yaml 'transforms') that lacks 'type', e.g. {'config': {...}} only.

Common situations: YAML indentation placing 'type' outside the transform mapping; omitting type when copying examples; building specs programmatically and forgetting the field.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/0b5538ce72baab26. Report an issue: GitHub.