stanfordnlp/CoreNLP · error · RuntimeException

Error (line %d): 10 fields expected but %d are present

Error message

Error (line %d): 10 fields expected but %d are present

What it means

GrammaticalStructure's CoNLL-X reader requires every non-empty input line to contain exactly 10 tab-separated fields (CoNLLX_FieldCount). When a line has a different field count, the reader throws this RuntimeException so malformed corpora are caught immediately rather than producing corrupt dependency trees. CoNLL-X format is fixed at 10 columns (id, form, lemma, cpostag, postag, feats, head, deprel, phead, pdeprel), so any deviation means the file is not valid CoNLL-X.

Solutions

  1. Inspect the reported line number in the file and fix the field count to exactly 10 tab-separated columns, keeping empty columns as empty strings between tabs.
  2. Ensure separators are actual tab characters ('\t'), not spaces — convert with e.g. sed or awk if needed.
  3. Strip header/comment lines (lines starting with '#') before passing the stream to the reader.
  4. Pre-validate the file yourself: check every non-empty line has 10 fields and report a friendly error before invoking the library.

Example fix

// before (space-separated line)
1	He	PRP	2	nsubj
// after (10 tab-separated fields, empties preserved)
1	He	_	PRP	PRP	_	2	nsubj	_	_
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate a CoNLL-X file before reading
for (String line : Files.readAllLines(path)) {
  if (line.isEmpty()) continue;
  int n = line.split("\t", -1).length;
  if (n != 10) throw new IllegalArgumentException(
    "Line not 10 tab-separated fields (" + n + "): " + line);
}

Try / catch

try {
  GrammaticalStructure gs = EnglishGrammaticalStructure.readCoNLLXGrammaticalStructure(reader);
} catch (RuntimeException e) {
  if (e.getMessage() != null && e.getMessage().contains("10 fields expected")) {
    log.error("Malformed CoNLL-X input: " + e.getMessage());
  } else throw e;
}

Prevention

When it happens

Trigger: Calling GrammaticalStructure reading methods such as readCoNLLXGrammaticalStructure (or constructors from a BufferedReader) on a line whose split("\t") yields != 10 fields, e.g. space-separated instead of tab-separated files, truncated lines, or files with a header/comment row.

Common situations: Feeding CoNLL-U or other tab formats with fewer/more columns; converting a dependency file through a text editor that converted tabs to spaces or trimmed trailing tabs (field 10 empty); joining fields with single tabs after pre-processing left empty columns collapsed.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/trees/GrammaticalStructure.java:1076

   * Read in a file containing a CoNLL-X dependency treebank and return a
   * corresponding list of GrammaticalStructures.
   *
   * @throws IOException
   */
  public static List<GrammaticalStructure> readCoNLLXGrammaticalStructureCollection(String fileName, Map<String, GrammaticalRelation> shortNameToGRel, GrammaticalStructureFromDependenciesFactory factory) throws IOException {
    try (BufferedReader r = IOUtils.readerFromString(fileName)) {
      LineNumberReader reader = new LineNumberReader(r);
      List<GrammaticalStructure> gsList = new LinkedList<>();

      List<List<String>> tokenFields = new ArrayList<>();

      for (String inline = reader.readLine(); inline != null;
           inline = reader.readLine()) {
        if (!inline.isEmpty()) {
          // read in a single sentence token by token
          List<String> fields = Arrays.asList(inline.split("\t"));
          if (fields.size() != CoNLLX_FieldCount) {
            throw new RuntimeException(String.format("Error (line %d): 10 fields expected but %d are present", reader.getLineNumber(), fields.size()));
          }
          tokenFields.add(fields);
        } else {
          if (tokenFields.isEmpty())
            continue; // skip excess empty lines

          gsList.add(buildCoNLLXGrammaticalStructure(tokenFields, shortNameToGRel, factory));
          tokenFields = new ArrayList<>();
        }
      }

      return gsList;
    }
  }

  public static GrammaticalStructure buildCoNLLXGrammaticalStructure(List<List<String>> tokenFields,
                                Map<String, GrammaticalRelation> shortNameToGRel,
                                GrammaticalStructureFromDependenciesFactory factory) {

View on GitHub (pinned to 1b7edd19c4)