stanfordnlp/CoreNLP · error · IllegalArgumentException

First line of input file should be header definition

Error message

First line of input file should be header definition

What it means

KBPRelationExtractor.readDataset parses a tab-separated CoNLL-style KBP test file. The first line must be a header starting with '#'; otherwise the file format is wrong and it throws an IllegalArgumentException.

Solutions

  1. Add a '#'-prefixed header line as the first line of the dataset file
  2. Verify you are pointing at the official KBP CoNLL-format file, not a derived/filtered copy
  3. Check whether your preprocessing pipeline stripped the comment/header lines
  4. Peek with head -n 1 file to confirm the header before running

Example fix

// before
readDataset("test.tsv"); // first line is data → IllegalArgumentException
// after
// prepend header: '#' columns...
readDataset("test_with_header.tsv"); // first line: "# WORD	RE	...	OBJECT	..."
Defensive patterns

Strategy: validation

Validate before calling

try (BufferedReader r = new BufferedReader(new FileReader(file))) {
  String first = r.readLine();
  if (first == null || !first.startsWith("#"))
    throw new IllegalArgumentException(file + " missing '#' header line");
}

Try / catch

try {
  List<Pair<KBPInput, String>> data = readDataset(path);
} catch (IllegalArgumentException e) {
  log.error("KBP dataset malformed: " + e.getMessage());
  throw e;
}

Prevention

When it happens

Trigger: Calling readDataset (or the KBP eval main) with a file whose first line is data, blank, or lacks the '#'-prefixed header — e.g. a headerless CoNLL dump or a plain-text file.

Common situations: Files prepared without the header row; CSV vs TSV exports stripped of comment lines; Unix tooling (grep/sed) that dropped '#' lines as comments.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/ie/KBPRelationExtractor.java:363

   * @param conllInputFile The input file, formatted as a TSV
   * @return A list of examples.
   */
  @SuppressWarnings("StatementWithEmptyBody")
  static List<Pair<KBPInput, String>> readDataset(File conllInputFile) throws IOException {
    BufferedReader reader = IOUtils.readerFromFile(conllInputFile);
    List<Pair<KBPInput, String>> examples = new ArrayList<>();

    int i = 0;
    String relation = null;
    List<String> tokens = new ArrayList<>();
    Span subject = new Span(Integer.MAX_VALUE, Integer.MIN_VALUE);
    NERTag subjectNER = null;
    Span object = new Span(Integer.MAX_VALUE, Integer.MIN_VALUE);
    NERTag objectNER = null;

    String line = reader.readLine();
    if (!line.startsWith("#")) {
      throw new IllegalArgumentException("First line of input file should be header definition");
    }
    while ( (line = reader.readLine()) != null ) {
      String[] fields = line.split("\t");
      if (relation == null) {
        // Case: read the relation
        assert fields.length == 1;
        relation = fields[0];
      } else if (fields.length == 9) {
        // Case: read a token
        tokens.add(fields[0]);
        if ("SUBJECT".equals(fields[1])) {
          subject = new Span(Math.min(subject.start(), i), Math.max(subject.end(), i + 1));
          subjectNER = valueOf(fields[2].toUpperCase(Locale.ROOT));
        } else if ("OBJECT".equals(fields[3])) {
          object = new Span(Math.min(object.start(), i), Math.max(object.end(), i + 1));
          objectNER = valueOf(fields[4].toUpperCase(Locale.ROOT));
        } else if ("-".equals(fields[1]) && "-".equals(fields[3])) {
          // do nothing

View on GitHub (pinned to 1b7edd19c4)