xai-org/x-algorithm · error · SemanticCheckFailure

field name %s is not an underscore followed by a number for

Error message

field name %s is not an underscore followed by a number for tuple class %s

What it means

TupleType.getFieldType only accepts tuple positional names of the form '_' followed by a number ('_1', '_2', ...). Any other name throws SemanticCheckFailure.

Source

Thrown at botmaker/src/java/com/twitter/botmaker/compiler/types/TupleType.java:56

                typeParams,
                NON_GENERIC_TYPE_ID,
                serializer)
        ));
  }

  @Override
  public Set<String> getFieldNames() {
    Set<String> fieldNames = Sets.newHashSetWithExpectedSize(typeParams.size());
    for (int i = 0; i < typeParams.size(); ++i) {
      fieldNames.add("_" + (i + 1));
    }
    return ImmutableSet.copyOf(fieldNames);
  }

  @Override
  public Type getFieldType(String fieldName) throws SemanticCheckFailure {
    if (!fieldName.startsWith("_")) {
      throw new SemanticCheckFailure(
          String.format(
              "field name %s is not an underscore followed by a number for tuple class %s",
              fieldName,
              toString()));
    }

    try {
      return typeParams.get(Integer.valueOf(fieldName.substring(1)) - 1);
    } catch (Throwable t) {
      throw new SemanticCheckFailure(t);
    }
  }

  @Override
  public boolean isSetValue(Tuple obj, String fieldName) {
    try {
      return (fieldName.startsWith("_"))
          && Integer.valueOf(fieldName.substring(1)) - 1 < typeParams.size();

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Use positional names '_1', '_2', ... matching tuple arity
  2. Switch the type to a StructTuple if named access is required
  3. Verify the tuple's arity via getTypeParams/getFieldNames before access

Example fix

// before
tupleType.getFieldType("user_id");
// after
tupleType.getFieldType("_1");
Defensive patterns

Strategy: type-guard

Validate before calling

if (!fieldName.matches("_\\d+")) throw new IllegalArgumentException("use _N names");

Type guard

boolean isPositionalName(String s) { return s.matches("_\\d+"); }

Try / catch

catch SemanticCheckFailure; rewrite named access to positional or switch to StructTuple type

Prevention

When it happens

Trigger: Calling getFieldType on a plain Tuple (not StructTuple) type with a named field like 'user_id' or '_abc' that is not underscore-plus-digits.

Common situations: Rules written with named field access on anonymous positional tuple types; assuming StructTuple semantics on a Tuple; schema change from StructTuple to Tuple.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/f93137d6164ec8c0. Report an issue: GitHub.