stanfordnlp/CoreNLP · error · IllegalArgumentException
Not enough columns for format
Error message
Not enough columns for format ${format} What it means
formatCsv builds output strings from a user-supplied format where $N refers to the Nth tab-separated column of the input line. If the format references a column index beyond the number of fields actually present, it throws IllegalArgumentException("Not enough columns for format ..."), reporting the format string.
Solutions
- Ensure input lines contain at least as many tab-separated columns as the highest $N in the csvFormat
- Lower the column indices in -csvFormat to reference existing columns
- Check the input for rows with missing trailing fields
Example fix
// before
props.setProperty("csvFormat", "$3\t$4"); // input only has 3 columns (0-2)
// after
props.setProperty("csvFormat", "$2\t$3"); // wait: use indices < fields.length, e.g. $0\t$1 Defensive patterns
Strategy: validation
Validate before calling
int maxIdx = 0; Matcher m = Pattern.compile("\\$(\\d)").matcher(csvFormat); while (m.find()) maxIdx = Math.max(maxIdx, Integer.parseInt(m.group(1))); if (fields.length <= maxIdx) throw new IllegalStateException("csvFormat needs " + (maxIdx+1) + " columns, line has " + fields.length); Type guard
null
Try / catch
try { String out = testExamples(...); } catch (IllegalArgumentException e) { log.error("csvFormat references missing column: " + e.getMessage()); } Prevention
- Match csvFormat indices to the actual input column count
- Ensure test files keep all columns used by the format
- Handle missing gold-answer columns with $c defaults only when goldAnswerColumn < fields.length
When it happens
Trigger: Calling testExamples/testExample with a -csvFormat like "$4\t$5" on an input line that only has 3 tab-separated columns, or a format index >= fields.length.
Common situations: csvFormat written for a training file with more columns than the test/prediction input; input lines with missing trailing columns; format indices being 1-based vs 0-based confusion (format uses digit characters mapped directly, field = digit).
Related errors
- Unrecognized format specification in
- Line format error at line
- Error: Line has too few tab-separated columns
- Dataset could not be loaded
- addFeature was called with a features object that is…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/51d31f7bb2f2d9d7.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/classify/ColumnDataClassifier.java:803
} else {
writeAnswer(example, answer, dist);
}
}
updatePerformanceStatistics(example, answer, dist, contingency, cl, sim);
}
private String formatCsv(String format, String[] fields, String answer) {
StringBuilder out = new StringBuilder();
for (int i = 0, len = format.length(); i < len; i++) {
char ch = format.charAt(i);
if (ch == '%' && i + 1 < len) {
char ch2 = format.charAt(i + 1);
if (ch2 >= '0' && ch2 <= '9') {
int field = ch2 - '0';
if (field < fields.length) {
out.append(fields[field]);
} else {
throw new IllegalArgumentException("Not enough columns for format " + format);
}
} else if (ch2 == 'c') {
if (answer != null) {
out.append(answer);
} else if (globalFlags.goldAnswerColumn < fields.length) {
out.append(fields[globalFlags.goldAnswerColumn]);
} else {
out.append("Class");
}
} else if (ch2 == 'n') {
out.append('\n');
} else {
throw new IllegalArgumentException("Unrecognized format specification in " + format);
}
i++; // have also dealt with next character giving format
} else {
out.append(ch);
}View on GitHub (pinned to 1b7edd19c4)