stanfordnlp/CoreNLP · error · java.lang.IllegalArgumentException

Unknown annotation key:

Error message

Unknown annotation key: 

What it means

Thrown by ComplexNodePattern.populate when the attribute key is not found in the lookup map of known annotation keys (attributes/custom parsers). The library cannot map the key to any CoreMap annotation or registered custom node pattern.

Solutions

  1. Fix the key spelling to a standard CoreMap attribute (word, tag, ner, lemma, etc.)
  2. Register the custom key via the TokensRegex environment (env with custom attribute parsers)
  3. Check for renamed keys after upgrading CoreNLP versions

Example fix

// before
{ wrd:/foo/ }
// after
{ word:/foo/ }
Defensive patterns

Strategy: validation

Validate before calling

Set<String> known = Set.of("word","tag","ner","lemma","normalized"); // plus your custom keys
if (!known.contains(key)) throw new IllegalArgumentException("Unknown TokensRegex attribute key: " + key);

Type guard

boolean isKnownAttribute(String key, Env env) { return env.getDefaults().containsKey(key); } // register custom keys in env defaults/parsers

Try / catch

try { node = ComplexNodePattern.valueOf(attr, value, env); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Unknown annotation key")) { log.error("Misspelled attribute: {}", attr); } throw e; }

Prevention

When it happens

Trigger: Using a misspelled or unregistered attribute name in a TokensRegex node expression, e.g. { wrd:foo } instead of { word:foo }, or a custom key that was never registered in the environment's default keys/custom parsers.

Common situations: Typos in rule files, upgrading CoreNLP where a key was renamed, or forgetting to register custom annotation keys when reusing rules across projects.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/ecec8753ede6c3fd. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ling/tokensregex/ComplexNodePattern.java:132

        } else if (value.startsWith("==")) {
          Double v = Double.parseDouble(value.substring(2));
          p.add(c, new NumericAnnotationPattern(v, NumericAnnotationPattern.CmpType.EQ));
        } else if (value.startsWith("!=")) {
          Double v = Double.parseDouble(value.substring(2));
          p.add(c, new NumericAnnotationPattern(v, NumericAnnotationPattern.CmpType.NE));
        } else if (value.startsWith(">")) {
          Double v = Double.parseDouble(value.substring(1));
          p.add(c, new NumericAnnotationPattern(v, NumericAnnotationPattern.CmpType.GT));
        } else if (value.startsWith("<")) {
          Double v = Double.parseDouble(value.substring(1));
          p.add(c, new NumericAnnotationPattern(v, NumericAnnotationPattern.CmpType.LT));
        } else if (value.matches("[A-Za-z0-9_+-.]+")) {
          p.add(c, new StringAnnotationPattern(value, env.defaultStringMatchFlags));
        } else {
          throw new IllegalArgumentException("Invalid value " + value + " for key: " + attr);
        }
      } else {
        throw new IllegalArgumentException("Unknown annotation key: " + attr);
      }
    }
  }

  public void add(K c, NodePattern pattern) {
    annotationPatterns.add(Pair.makePair(c, pattern));
  }

  @Override
  public boolean match(M token)
  {
    boolean matched = true;
    for (Pair<K,NodePattern> entry:annotationPatterns) {
      NodePattern annoPattern = entry.second;
      Object anno = getter.apply(token, entry.first);
      if (!annoPattern.match(anno)) {
        matched = false;
        break;

View on GitHub (pinned to 1b7edd19c4)