xai-org/x-algorithm · error · SemanticCheckFailure
expecting the input to be of String or List type but receive
Error message
expecting the input to be of String or List type but received: %s for %s
What it means
Slice()'s semantic validation requires the first argument's static typeBase to be Object, String, or List. Other types (Map, Set, Long, etc.) fail at build time with this message, which includes the offending type and the expression text.
Source
Thrown at botmaker/src/java/com/twitter/botmaker/function/collection/Slice.java:68
return SIGNATURE;
}
@Override
protected CacheLevel getCacheLevel() {
return CacheLevel.Global;
}
public Slice(String exprText, ImmutableList<ASTNode> children) throws SemanticCheckFailure {
super(exprText, validateType(children));
}
private static ImmutableList<ASTNode> validateType(ImmutableList<ASTNode> children)
throws SemanticCheckFailure {
Class<?> inputType = children.get(0).getReturnType().typeBase;
if (!Object.class.equals(inputType)
&& !String.class.equals(inputType)
&& !List.class.equals(inputType)) {
throw new SemanticCheckFailure(mkErrorMessage(inputType));
}
return children;
}
@Override
protected Object apply(
Context<Runtime> context, Object input, Long beginIndex, Long endIndex) {
if (input instanceof String) {
return ((String) input).substring(beginIndex.intValue(), endIndex.intValue());
} else if (input instanceof List) {
return Collections.unmodifiableList(new ArrayList<>(
((List) input).subList(beginIndex.intValue(), endIndex.intValue())));
} else {
throw new IllegalArgumentException(mkErrorMessage(input.getClass()));
}
}
@OverrideView on GitHub (pinned to 24c60942c5)
Solutions
- Convert to a List first (e.g. ToList/Set-to-list conversion) before slicing
- Use ToSet+Contains or map accessors for Maps/Sets instead of Slice
- Verify the first argument's return type is List or String
Example fix
// before Slice(mySet, 0, 2) // after Slice(ToList(mySet), 0, 2)
Defensive patterns
Strategy: type-guard
Validate before calling
// rule-language: convert before slicing Slice(ToList(setVal), 0, 2)
Type guard
// host code Class<?> base = children.get(0).getReturnType().typeBase; boolean ok = Object.class.equals(base) || String.class.equals(base) || List.class.equals(base);
Prevention
- Slice only Strings and Lists
- Convert Sets/Maps to Lists first
When it happens
Trigger: Calling Slice(myMap, 0, 1), Slice(someSet, 0, 1), or Slice(42, 0, 1) at rule-build time.
Common situations: Assuming Slice works on any collection; refactoring input from List to Set/Map without updating the Slice call.
Related errors
- Contains expects input of String, Map, Set or Collection typ
- Copy function only supports Map or StructTuple.
- StructTuple field %s expects type %s, but %s received.
- Count expects input of String, Map or Collection types but %
- Type %s does not support index accessor
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/6ee5689deb932dc7.
Report an issue: GitHub.