stanfordnlp/CoreNLP · error · IllegalArgumentException
Unknown format
Error message
Unknown format
What it means
getAnnotations builds per-sentence annotations depending on the configured input format (stdin text vs file vs tree file). If the format value doesn't match any of its recognized cases, the default branch throws IllegalArgumentException("Unknown format " + inputFormat). It is an internal configuration validation on the input source mode.
Solutions
- Pass a supported -input format value exactly as documented (run with -help to list them).
- Fix casing/spelling of the format string on the command line.
- If calling programmatically, use the same enum/string constants the pipeline defines rather than free-form strings.
- If extending the library, add the new format as a case in getAnnotations' switch.
Example fix
// before java edu.stanford.nlp.sentiment.SentimentPipeline -input Trees -filelist list.txt // after java edu.stanford.nlp.sentiment.SentimentPipeline -input tree -filelist list.txt
Defensive patterns
Strategy: validation
Validate before calling
Set<String> validInputs = new HashSet<>(Arrays.asList("stdin", "file", "tree"));
if (!validInputs.contains(inputArg)) {
throw new IllegalArgumentException("input must be one of " + validInputs);
} Try / catch
try {
SentimentPipeline.main(args);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("Unknown format")) {
System.err.println("Check the -input value; run with -help for allowed formats");
} else throw e;
} Prevention
- Use the documented -input values verbatim (case-sensitive).
- Pin the library version in build/deploy scripts so format strings stay consistent.
- Prefer the pipeline's own constants/enums over hand-typed strings in programmatic use.
- Run -help once per version and store the accepted values in your config.
When it happens
Trigger: Calling getAnnotations (via annotations()) with an inputFormat value not handled by its switch, e.g. a malformed -input flag value on the command line or an enum constant added by custom code but not handled in this switch.
Common situations: Typo in the -input CLI value (e.g. 'trees' vs 'tree'); version drift where a newer/older SentimentPipeline recognizes different format strings; custom integrations passing their own format constants.
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 output format
- Unknown argument
- Please only specify one of -file, -fileList or -stdin
- You probably cannot read the serialized output, so printing…
- Unknown argument
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/d08ad4bf10172cd6.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/sentiment/SentimentPipeline.java:240
} else {
MemoryTreebank treebank = new MemoryTreebank("utf-8");
treebank.loadPath(filename, null);
trees = new ArrayList<>(treebank);
}
List<Annotation> annotations = Generics.newArrayList();
for (Tree tree : trees) {
CoreMap sentence = new Annotation(SentenceUtils.listToString(tree.yield()));
sentence.set(TreeCoreAnnotations.TreeAnnotation.class, tree);
List<CoreMap> sentences = Collections.singletonList(sentence);
Annotation annotation = new Annotation("");
annotation.set(CoreAnnotations.SentencesAnnotation.class, sentences);
annotations.add(annotation);
}
return annotations;
}
default:
throw new IllegalArgumentException("Unknown format " + inputFormat);
}
}
/** Runs the tree-based sentiment model on some text. */
public static void main(String[] args) throws IOException {
String parserModel = null;
String sentimentModel = null;
String filename = null;
String fileList = null;
boolean stdin = false;
boolean filterUnknown = false;
List<Output> outputFormats = Collections.singletonList(Output.ROOT);
Input inputFormat = Input.TEXT;
String tlppClass = DEFAULT_TLPP_CLASS;View on GitHub (pinned to 1b7edd19c4)