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

  1. Pass a supported -input format value exactly as documented (run with -help to list them).
  2. Fix casing/spelling of the format string on the command line.
  3. If calling programmatically, use the same enum/string constants the pipeline defines rather than free-form strings.
  4. 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

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


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)