stanfordnlp/CoreNLP · error · IllegalArgumentException

Unknown output format

Error message

Unknown output format ${outputFormat}

What it means

StanfordCoreNLP.getDefaultExtension maps each OutputFormat enum (JSON, XML, CONLLU, TEXT, TAGGED, INLINEXML, SERIALIZED, CUSTOM) to a file extension; a value outside the known enum constants hits the default branch and throws IllegalArgumentException. In practice this means an unrecognized/unknown outputFormat value was supplied.

Solutions

  1. Use one of the supported outputFormat values: json, xml, text, tagged, conllu, inlinexml, serialized, or custom.
  2. Correct the typo in the outputFormat property (e.g. outputFormat=text not txt).
  3. Align CoreNLP jar versions between producer and consumer if a new OutputFormat constant is involved.

Example fix

// before
props.setProperty("outputFormat", "txt");
// after
props.setProperty("outputFormat", "text");
Defensive patterns

Strategy: validation

Validate before calling

String fmt = props.getProperty("outputFormat", "json").toLowerCase();
List<String> allowed = Arrays.asList("json","xml","text","tagged","conllu","inlinexml","serialized","custom");
if (!allowed.contains(fmt)) throw new IllegalArgumentException("Unsupported outputFormat: " + fmt);

Try / catch

try {
  pipeline.processToOutputFile(...);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Unknown output format")) {
    props.setProperty("outputFormat", "json"); // safe default
  } else throw e;
}

Prevention

When it happens

Trigger: Setting the 'outputFormat' property to an unsupported string so it fails to resolve to a known OutputFormat, or programmatically passing an OutputFormat value not handled by the switch after a library upgrade.

Common situations: Typo'd formats like outputFormat=txt (should be text) or outputFormat=yaml; using a format constant from a newer CoreNLP version with an older switch implementation.

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


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

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/StanfordCoreNLP.java:101

 * @author Steven Bethard
 */

public class StanfordCoreNLP extends AnnotationPipeline  {

  public enum OutputFormat { TEXT, TAGGED, XML, JSON, CONLL, CONLLU, INLINEXML, SERIALIZED, CUSTOM }

  private static String getDefaultExtension(OutputFormat outputFormat) {
    switch (outputFormat) {
      case XML: return ".xml";
      case JSON: return ".json";
      case CONLL: return ".conll";
      case CONLLU: return ".conllu";
      case TEXT: return ".out";
      case TAGGED: return ".tag";
      case INLINEXML: return ".inxml";
      case SERIALIZED: return ".ser.gz";
      case CUSTOM: return ".out";
      default: throw new IllegalArgumentException("Unknown output format " + outputFormat);
    }
  }


  /**
   * An annotator name and its associated signature.
   * Used in {@link #GLOBAL_ANNOTATOR_CACHE}.
   */
  public static class AnnotatorSignature {
    public final String name;
    public final String signature;

    public AnnotatorSignature(String name, String signature) {
      this.name = name;
      this.signature = signature;
    }

    @Override

View on GitHub (pinned to 1b7edd19c4)