stanfordnlp/CoreNLP · error · RuntimeException
Unexpected number of field
Error message
Unexpected number of field {fields.length}, expected >= {FIELDS_MIN} for line ({filename},{lineCnt}): {line} What it means
DocumentIterator.next() splits each non-blank line of the CoNLL file on the delimiter and requires at least FIELDS_MIN tab-separated fields to extract document id, part number, word, etc. A line with fewer fields than FIELDS_MIN is malformed, so it throws a RuntimeException including the file name, line count, and raw line to pinpoint the bad row.
Solutions
- Open the file at the reported line (from the message: filename,lineCnt) and fix or remove the malformed row, restoring all required tab-separated columns.
- Ensure no text editor or transfer step (e.g. git autocrlf, upload normalization) stripped trailing tabs from the corpus.
- Confirm the file is the correct CoNLL-2011 format matching the FIELDS_MIN expectation; re-obtain the original corpus if not.
- Run a pre-check script that counts fields per line and reports lines below the required count before running the reader.
- If generating files yourself, terminate each row with the full column set including trailing empty fields.
Example fix
// before (line stripped to 2 fields) // XYZ 1 // after (full CoNLL row with all FIELDS_MIN columns) // XYZ 1 1 word POS PARSE PRED COREF...
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check every line has enough tab-separated fields
try (BufferedReader r = Files.newBufferedReader(Paths.get(corpusPath))) {
String line; int n = 0;
while ((line = r.readLine()) != null) {
if (!line.trim().isEmpty() && line.split("\t").length < 10 /* FIELDS_MIN */)
throw new IllegalStateException("Line " + (n+1) + " has too few fields: " + line);
n++;
}
} Prevention
- Preserve trailing tabs when saving TSV/CoNLL files (disable trim-on-save).
- Verify corpus format matches the reader's expected column count before ingest.
- Run a field-count linter over generated corpus files.
- Transfer corpora with binary-safe methods (git lfs, checksums) to avoid silent edits.
When it happens
Trigger: Calling DocumentIterator (via CoNLL2011DocumentReader.nextDoc / dcoref pipeline) over a corpus file that contains a line with too few columns — e.g. a blank-ish line with only a word, a header line, or a row where trailing tabs were stripped.
Common situations: Editors or upload pipelines trimming trailing tabs from TSV/CoNLL files; mixing CoNLL formats (CoNLL-2010 vs 2011 vs 2012 have different column counts); accidentally feeding a non-CoNLL text file as the corpus path.
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
- Error extracting labelled spans for column
- adjustFinalToken: Unexpected final char: |
- Bad data format:
- Both parse.model and parse.executable properties must be…
- Cannot cast " + classname + " into " + type.getName()
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/b1284646b1558a81.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/dcoref/CoNLL2011DocumentReader.java:658
line = line.trim();
if (line.length() != 0) {
if (line.startsWith(docStart)) {
// Start of new document
if (document != null) {
logger.warning("Unexpected begin document at line (\" + filename + \",\" + lineCnt + \")");
}
document = new Document();
document.documentIdPart = line.substring(docStartLength);
} else if (line.startsWith("#end document")) {
annotateDocument(document);
docCnt++;
return document;
// End of document
} else {
assert document != null;
String[] fields = delimiterPattern.split(line);
if (fields.length < FIELDS_MIN) {
throw new RuntimeException("Unexpected number of field " + fields.length +
", expected >= " + FIELDS_MIN + " for line (" + filename + "," + lineCnt + "): " + line);
}
String curDocId = fields[FIELD_DOC_ID];
String partNo = fields[FIELD_PART_NO];
if (document.getDocumentID() == null) {
document.setDocumentID(curDocId);
document.setPartNo(partNo);
} else {
// Check documentID didn't suddenly change on us
assert(document.getDocumentID().equals(curDocId));
assert(document.getPartNo().equals(partNo));
}
curSentWords.add(fields);
}
} else {
// Current sentence has ended, new sentence is about to be started
if (curSentWords.size() > 0) {
assert document != null;View on GitHub (pinned to 1b7edd19c4)