apache/beam · error · IllegalArgumentException

Received an empty YAML string, but output schema contains re

Error message

Received an empty YAML string, but output schema contains required fields: %s

What it means

YamlUtils.toBeamRow converts a YAML string to a Beam Row. An empty/blank YAML string yields no mapping, which is acceptable only if every field in the target schema is nullable (producing Row.nullRow). If the schema has any non-nullable (required) fields, this IllegalArgumentException is thrown listing them.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/YamlUtils.java:74

          .put(Schema.TypeName.STRING, str -> str)
          .put(Schema.TypeName.BYTES, str -> BaseEncoding.base64().decode(str))
          .build();

  public static Row toBeamRow(@Nullable String yamlString, Schema schema) {
    return toBeamRow(yamlString, schema, false);
  }

  public static Row toBeamRow(
      @Nullable String yamlString, Schema schema, boolean convertNamesToCamelCase) {
    if (yamlString == null || yamlString.isEmpty()) {
      List<Field> requiredFields =
          schema.getFields().stream()
              .filter(field -> !field.getType().getNullable())
              .collect(Collectors.toList());
      if (requiredFields.isEmpty()) {
        return Row.nullRow(schema);
      } else {
        throw new IllegalArgumentException(
            String.format(
                "Received an empty YAML string, but output schema contains required fields: %s",
                requiredFields));
      }
    }
    Yaml yaml = new Yaml();
    Object yamlMap = yaml.load(yamlString);

    Preconditions.checkArgument(
        yamlMap instanceof Map,
        "Expected a YAML mapping but got type '%s' instead.",
        Preconditions.checkNotNull(yamlMap).getClass());

    return toBeamRow(
        (Map<String, Object>) Preconditions.checkNotNull(yamlMap), schema, convertNamesToCamelCase);
  }

  private static @Nullable Object toBeamValue(

View on GitHub (pinned to 12126d8942)

Solutions

  1. Provide a non-empty YAML mapping containing values for all required fields.
  2. Make the schema fields nullable if an empty document is legitimately representable.
  3. Check for empty input before calling toBeamRow and skip or default it.
  4. Fix upstream file reads that return empty strings for missing files.

Example fix

// before
Row row = YamlUtils.toBeamRow("", schema); // schema has required fields
// after
if (yamlString.trim().isEmpty()) {
  yamlString = "name: default\nage: 0"; // or make schema fields nullable
}
Row row = YamlUtils.toBeamRow(yamlString, schema);
Defensive patterns

Strategy: validation

Validate before calling

if (yamlString == null || yamlString.trim().isEmpty()) {
  List<String> required = schema.getFields().stream()
      .filter(f -> !f.getType().getNullable())
      .map(Schema.Field::getName)
      .collect(Collectors.toList());
  if (!required.isEmpty()) throw new IllegalArgumentException("Empty YAML, required: " + required);
}

Type guard

boolean canBeEmptyYaml(Schema schema) {
  return schema.getFields().stream().allMatch(f -> f.getType().getNullable());
}

Try / catch

try {
  return YamlUtils.toBeamRow(yamlString, schema);
} catch (IllegalArgumentException e) {
  if (e.getMessage() != null && e.getMessage().contains("empty YAML string")) {
    return substituteDefaultRow(schema); // fill required defaults
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling YamlUtils.toBeamRow("" or blank string, schema) where schema.getFields() contains at least one field with type.getNullable() == false.

Common situations: Parsing empty YAML documents/files or whitespace-only strings from sources (empty config files, blank lines read as documents) into rows with required fields.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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