stanfordnlp/CoreNLP · error · IllegalArgumentException
Unknown rule type:
Error message
Unknown rule type:
What it means
SequenceMatchRules.createRule looks up an AnnotationExtractRuleCreator registered in the Env for the given ruleType. When no creator is registered for the resolved rule type (ruleType attribute or env default), it throws IllegalArgumentException 'Unknown rule type: <type>'. The library only knows built-in types like 'composite', 'tokens', 'text'.
Solutions
- Use a built-in rule type: "composite", "tokens", or "text"
- Check spelling of the ruleType value in the rule file/attribute map
- Register a custom creator first via SequenceMatchRules.registerExtractRuleCreator(env, type, creator)
- Remove or correct a wrong ruleType in env.getDefaults()
Example fix
// before
attributes.put("ruleType", "token"); // unknown
// after
attributes.put("ruleType", SequenceMatchRules.TOKEN_PATTERN_RULE_TYPE); // "tokens" Defensive patterns
Strategy: validation
Validate before calling
Object rt = attributes.get("ruleType");
if (rt != null && !Set.of("composite","tokens","text").contains(rt)
&& SequenceMatchRules.lookupExtractRuleCreator(env, (String) rt) == null) {
throw new IllegalArgumentException("Unregistered ruleType: " + rt);
} Try / catch
try {
rule = SequenceMatchRules.createRule(env, attributes);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("Unknown rule type")) {
// log the offending ruleType and fall back to a built-in type
}
} Prevention
- Only use built-in ruleType values: composite, tokens, text
- Register custom creators before parsing rules
- Spell-check ruleType strings in rule files
- Check env defaults for a stale ruleType
When it happens
Trigger: Creating a rule with attributes.put("ruleType", "regex") (or any unregistered string) and calling SequenceMatchRules.createRule(env, attributes); a typo such as 'token' instead of 'tokens'; env defaults setting a ruleType with no registered creator.
Common situations: Typo in a TokensRegex rules file's ruleType field; using a custom rule type without calling SequenceMatchRules.registerExtractRuleCreator; copying rule syntax from another library.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Invalid annotation key
- Error creating composite rule: no annotation field
- Cannot determine annotation key for
- Unknown LogPriorType:
- unsupported language
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/99ad6d7f2f94ba5b.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/SequenceMatchRules.java:338
Map<String, Object> attributes;
cv = cv.simplifyNoTypeConversion(env);
attributes = new HashMap<>();//Generics.newHashMap();
for (String s:cv.getAttributes()) {
attributes.put(s, cv.getExpression(s));
}
return createExtractionRule(env, attributes);
}
protected static AnnotationExtractRule createExtractionRule(Env env, Map<String,Object> attributes) {
String ruleType = (String) Expressions.asObject(env, attributes.get("ruleType"));
if (ruleType == null && env != null) {
ruleType = (String) env.getDefaults().get("ruleType");
}
AnnotationExtractRuleCreator ruleCreator = lookupExtractRuleCreator(env, ruleType);
if (ruleCreator != null) {
return ruleCreator.create(env, attributes);
} else {
throw new IllegalArgumentException("Unknown rule type: " + ruleType);
}
}
public static AnnotationExtractRule createExtractionRule(Env env, String ruleType, Object pattern, Expression result) {
if (ruleType == null && env != null) {
ruleType = (String) env.getDefaults().get("ruleType");
}
AnnotationExtractRuleCreator ruleCreator = lookupExtractRuleCreator(env, ruleType);
if (ruleCreator != null) {
Map<String,Object> attributes = new HashMap<>();//Generics.newHashMap();
attributes.put("ruleType", ruleType);
attributes.put("pattern", pattern);
attributes.put("result", result);
return ruleCreator.create(env, attributes);
} else {
throw new IllegalArgumentException("Unknown rule type: " + ruleType);
}
}View on GitHub (pinned to 1b7edd19c4)