apache/beam · error · ValueError

inspection_template_name or inspection_config must be…

Error message

inspection_template_name or inspection_config must be specified

What it means

CloudDLPRemovePII's constructor found neither an inspection_template_name nor an inspection_config, so it has no description of what sensitive info to detect. It is the empty-side of the template/config mutual-exclusion validation.

Solutions

  1. Provide inspection_template_name='projects/PROJECT/locations/LOCATION/inspectTemplates/TEMPLATE_ID' or an inline inspection_config=dlp.InspectConfig(...)
  2. Verify the config file actually populates one of the two inspection options
  3. Ensure string config values are not silently stripped to None

Example fix

// before
opts = CloudDLPOptions(project='p', deidentification_config=dcfg)

// after
opts = CloudDLPOptions(project='p', deidentification_config=dcfg,
    inspection_config=dlp.InspectConfig(info_types=[...]))
Defensive patterns

Strategy: validation

Validate before calling

if inspect_config is None and inspect_template is None:
    raise ValueError('CloudDLPOptions needs inspection_template_name or inspection_config')

Try / catch

try:
    options = CloudDLPOptions(project=p, deidentification_config=c)
except ValueError as e:
    if 'inspection_template_name or inspection_config' in str(e):
        options = CloudDLPOptions(project=p, deidentification_config=c,
            inspection_config=dlp.InspectConfig())

Prevention

When it happens

Trigger: Calling CloudDLPOptions(project=..., deidentification_template_name=...) with neither inspection_config nor inspection_template_name supplied.

Common situations: Only configuring deidentification and forgetting inspection; config loader dropping the inspection block; copying an example that used a template variable left unset.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at sdks/python/apache_beam/ml/gcp/cloud_dlp.py:111

    self.timeout = timeout
    if deidentification_template_name is not None \
        and deidentification_config is not None:
      raise ValueError(
          'Both deidentification_template_name and '
          'deidentification_config were specified.'
          ' Please specify only one of these.')
    elif deidentification_template_name is None \
        and deidentification_config is None:
      raise ValueError(
          'deidentification_template_name or '
          'deidentification_config must be specified.')
    elif deidentification_template_name is not None:
      self.config['deidentify_template_name'] = deidentification_template_name
    else:
      self.config['deidentify_config'] = deidentification_config

    if inspection_config is None and inspection_template_name is None:
      raise ValueError(
          'inspection_template_name or inspection_config must be specified')
    if inspection_template_name is not None:
      self.config['inspect_template_name'] = inspection_template_name
    if inspection_config is not None:
      self.config['inspect_config'] = inspection_config

  def expand(self, pcoll):
    if self.project is None:
      self.project = pcoll.pipeline.options.view_as(GoogleCloudOptions).project
    if self.project is None:
      raise ValueError(
          'GCP project name needs to be specified in "project" pipeline option')
    return (
        pcoll
        | ParDo(_DeidentifyFn(self.config, self.timeout, self.project)))


@typehints.with_input_types(str)

View on GitHub (pinned to 12126d8942)