stanfordnlp/CoreNLP · error · java.lang.IllegalArgumentException
Unknown format
Error message
Unknown format
What it means
CoreLabel.toString(Format format) supports only a fixed set of Format enum values (e.g. VALUE, WORD, TAG, MAP, VALUE_TAG, etc.). If a caller passes a null or unhandled format value, the switch's default branch throws IllegalArgumentException("Unknown format " + format). This is a defensive guard against invalid format requests rather than a data problem.
Solutions
- Check the format string/value passed; use only constants defined in CoreLabel.OutputFormat (or AbstractMapLabel.Format) that this version supports.
- Null-check or default the format: Format f = fmt == null ? Format.VALUE : fmt.
- Call the no-arg toString() instead of toString(format) when you just want the value.
- Upgrade Stanford CoreNLP if the desired format constant exists only in newer releases.
Example fix
// before
String s = label.toString(Format.valueOf(config.get("fmt"))); // IAE if unknown/null
// after
String s = label.toString("VALUE".equals(config.get("fmt")) ? Format.VALUE : Format.VALUE); Defensive patterns
Strategy: validation
Validate before calling
// Allowed formats for CoreLabel.toString(Format)
Set<CoreLabel.OutputFormat> allowed = EnumSet.allOf(CoreLabel.OutputFormat.class);
if (format == null || !allowed.contains(format)) {
format = CoreLabel.OutputFormat.VALUE; // safe default
}
String s = label.toString(format); Type guard
boolean isKnownFormat(CoreLabel.OutputFormat f) {
return f != null && EnumSet.allOf(CoreLabel.OutputFormat.class).contains(f);
} Try / catch
try {
return label.toString(format);
} catch (IllegalArgumentException e) {
log.warn("Unknown label format " + format + ", using VALUE");
return label.toString(CoreLabel.OutputFormat.VALUE);
} Prevention
- Only pass Format constants referenced directly from the enum, never valueOf of arbitrary strings.
- Null-check formats parsed from configuration before calling toString(Format).
- Prefer the no-arg toString() when you only need the label value.
- Verify the Format constant exists in your pinned CoreNLP version; enum constants are added across releases.
When it happens
Trigger: Calling label.toString(Format) with a Format value not covered by the switch — most commonly Format.valueOf on a typo'd name, a null Format after parsing a format string, or a Format constant from a different/newer CoreLabel.Format enum than this StanNLP version supports.
Common situations: Configuring an output format via a user-supplied string and passing it unvalidated to toString(Format); version skew where an older Stanford CoreNLP build lacks a newer Format enum constant that configuration references.
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
- Unknown clique: " + clique
- Sentence.toSentence: lengths differ
- Invalid arguments to
- CoreMap must have either a Calendar or DocDate annotation
- Unsupported subScoreType
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/f2741e1e192c426e.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/CoreLabel.java:856
case LEMMA_INDEX:
buf.append(lemma());
Integer index = this.get(CoreAnnotations.IndexAnnotation.class);
if (index != null) {
buf.append('-').append((index).intValue());
}
Integer emptyIndex = this.get(CoreAnnotations.EmptyIndexAnnotation.class);
if (emptyIndex != null && emptyIndex != 0) {
buf.append('.').append((emptyIndex).intValue());
}
break;
case ALL:{
for (Class en: this.keySet()) {
buf.append(';').append(en).append(':').append(this.get(en));
}
break;
}
default:
throw new IllegalArgumentException("Unknown format " + format);
}
return buf.toString();
}
private static final Comparator<Class<?>> asClassComparator =
Comparator.comparing(Class::getName);
}
View on GitHub (pinned to 1b7edd19c4)