apache/beam · error · IllegalArgumentException

Either inspectTemplateName or inspectConfig must be supplied

Error message

Either inspectTemplateName or inspectConfig must be supplied!

What it means

DLPInspectText's builder (Apache Beam Google Cloud DLP extension) requires at least one way to tell the DLP service what to inspect: either an inline InspectConfig or the name of a stored inspect template. The build() method throws this IllegalArgumentException when autoBuild() produced an instance with both fields null, because the subsequent DLP inspect call would be invalid.

Source

Thrown at sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/DLPInspectText.java:141

     * Sets delimiter to be used when splitting values from input strings into columns.
     *
     * @param delimiter Delimiter to be used when splitting values from input strings into columns.
     */
    public abstract Builder setColumnDelimiter(String delimiter);

    /**
     * Sets list of column names if the input KV value is a delimited row.
     *
     * @param headerColumns List of column names if the input KV value is a delimited row.
     */
    public abstract Builder setHeaderColumns(PCollectionView<List<String>> headerColumns);

    abstract DLPInspectText autoBuild();

    public DLPInspectText build() {
      DLPInspectText inspectText = autoBuild();
      if (inspectText.getInspectTemplateName() == null && inspectText.getInspectConfig() == null) {
        throw new IllegalArgumentException(
            "Either inspectTemplateName or inspectConfig must be supplied!");
      }
      if (inspectText.getBatchSizeBytes() > DLP_PAYLOAD_LIMIT_BYTES) {
        throw new IllegalArgumentException(
            String.format(
                "Batch size is too large! It should be smaller or equal than %d.",
                DLP_PAYLOAD_LIMIT_BYTES));
      }
      if (inspectText.getColumnDelimiter() == null && inspectText.getHeaderColumns() != null) {
        throw new IllegalArgumentException(
            "Column delimiter should be set if headers are present.");
      }
      if (inspectText.getHeaderColumns() == null && inspectText.getColumnDelimiter() != null) {
        throw new IllegalArgumentException(
            "Column headers should be supplied when delimiter is present.");
      }
      return inspectText;
    }

View on GitHub (pinned to 12126d8942)

Solutions

  1. Call .setInspectTemplateName("projects/YOUR_PROJECT/locations/LOCATION/inspectTemplates/TEMPLATE_ID") with a template created in Cloud DLP.
  2. Or call .setInspectConfig(InspectConfig.newBuilder()...build()) to supply an inline inspection configuration.
  3. If building from application config, validate that at least one of the two config keys is present before constructing the builder.

Example fix

// before
DLPInspectText inspect = DLPInspectText.newBuilder()
    .setProjectId("my-project")
    .build(); // throws
// after
DLPInspectText inspect = DLPInspectText.newBuilder()
    .setProjectId("my-project")
    .setInspectTemplateName("projects/my-project/locations/global/inspectTemplates/my-template")
    .build();
Defensive patterns

Strategy: validation

Validate before calling

if (inspectTemplateName == null && inspectConfig == null) {
  throw new IllegalArgumentException("Provide either inspectTemplateName or inspectConfig before building DLPInspectText");
}

Try / catch

try {
  DLPInspectText inspect = DLPInspectText.newBuilder()...build();
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("inspectTemplateName or inspectConfig")) {
    // supply a default inspect config and retry the build
  }
}

Prevention

When it happens

Trigger: Calling DLPInspectText.newBuilder()...build() without calling either .setInspectTemplateName(String) or .setInspectConfig(InspectConfig) before building.

Common situations: Developers assume a default inspection config exists, copy a builder snippet and delete the template/config line, or build the transform programmatically from config where both optional keys were absent.

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/2b712efeb593c2e6. Report an issue: GitHub.