stanfordnlp/CoreNLP · error · IllegalArgumentException
Unknown output format
Error message
Unknown output format
What it means
In outputTree, after printing trees the code switches on the user-selected output format (e.g. root-only, scores); any value outside the known enum of formats falls into the default branch and throws IllegalArgumentException("Unknown output format " + output). The library validates the format only at output time, not at argument-parse time.
Solutions
- Use one of the accepted -output values (e.g. c, root, or scores).
- Check spelling/case and re-run with -help to list supported formats.
- In wrapper scripts, validate/interpolate the output value before invoking the pipeline.
- If a format you need is genuinely missing, extend the switch in outputTree with a new case instead of passing an ad-hoc string.
Example fix
// before java edu.stanford.nlp.sentiment.SentimentPipeline -model model.ser.gz -output tree -file in.txt // after java edu.stanford.nlp.sentiment.SentimentPipeline -model model.ser.gz -output scores -file in.txt
Defensive patterns
Strategy: validation
Validate before calling
Set<String> validOutputs = new HashSet<>(Arrays.asList("c", "root", "scores"));
if (!validOutputs.contains(outputArg)) {
throw new IllegalArgumentException("output must be one of " + validOutputs);
} Try / catch
try {
SentimentPipeline.main(args);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("Unknown output format")) {
System.err.println("Use -output with values: c, root, scores");
} else throw e;
} Prevention
- Check -help output for the exact -output values before scripting.
- Keep flag values in constants, not inline strings, in wrapper scripts.
- Beware version differences: verify format strings against the version you deploy.
- Validate the interpolated variable in scripts before invoking the pipeline.
When it happens
Trigger: Passing -output <value> to SentimentPipeline main with a value not among the recognized formats (c, root, scores), or invoking outputTree programmatically with an unrecognized Output output value.
Common situations: Typos like -output Scores or -output tree; copying a CLI invocation from docs of a different version where the flag values changed; wrapping the class in a script that interpolates an unset variable, producing an empty format string.
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 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/fdc3fef5b2c1c45d.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/sentiment/SentimentPipeline.java:180
Tree copy = tree.deepCopy();
setIndexLabels(copy, 0);
out.println(copy);
outputTreeVectors(out, tree, 0);
break;
}
case ROOT: {
out.println(" " + sentence.get(SentimentCoreAnnotations.SentimentClass.class));
break;
}
case PROBABILITIES: {
Tree copy = tree.deepCopy();
setIndexLabels(copy, 0);
out.println(copy);
outputTreeScores(out, tree, 0);
break;
}
default:
throw new IllegalArgumentException("Unknown output format " + output);
}
}
}
private static final String DEFAULT_TLPP_CLASS = "edu.stanford.nlp.parser.lexparser.EnglishTreebankParserParams";
private static void help() {
log.info("Known command line arguments:");
log.info(" -sentimentModel <model>: Which model to use");
log.info(" -parserModel <model>: Which parser to use");
log.info(" -file <filename>: Which file to process");
log.info(" -fileList <file>,<file>,...: Comma separated list of files to process. Output goes to file.out");
log.info(" -stdin: Process stdin instead of a file");
log.info(" -input <format>: Which format to input, TEXT or TREES. Will not process stdin as trees. If trees are not already binarized, they will be binarized with -tlppClass's headfinder, which means they must have labels in that treebank's tagset.");
log.info(" -output <format>: Which format to output, PENNTREES, VECTORS, PROBABILITIES, or ROOT. Multiple formats can be specified as a comma separated list.");
log.info(" -filterUnknown: remove unknown trees from the input. Only applies to TREES input, in which case the trees must be binarized with sentiment labels");
log.info(" -tlppClass: a class to use for building the binarizer if using non-binarized TREES as input. Defaults to " + DEFAULT_TLPP_CLASS);
}View on GitHub (pinned to 1b7edd19c4)