{"record":{"id":"51d31f7bb2f2d9d7","repo":"stanfordnlp/CoreNLP","slug":"not-enough-columns-for-format-format","errorCode":null,"errorMessage":"Not enough columns for format ${format}","messagePattern":"Not enough columns for format (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/classify/ColumnDataClassifier.java","lineNumber":803,"sourceCode":"      } else {\n        writeAnswer(example, answer, dist);\n      }\n    }\n    updatePerformanceStatistics(example, answer, dist, contingency, cl, sim);\n  }\n\n  private String formatCsv(String format, String[] fields, String answer) {\n    StringBuilder out = new StringBuilder();\n    for (int i = 0, len = format.length(); i < len; i++) {\n      char ch = format.charAt(i);\n      if (ch == '%' && i + 1 < len) {\n        char ch2 = format.charAt(i + 1);\n        if (ch2 >= '0' && ch2 <= '9') {\n          int field = ch2 - '0';\n          if (field < fields.length) {\n            out.append(fields[field]);\n          } else {\n            throw new IllegalArgumentException(\"Not enough columns for format \" + format);\n          }\n        } else if (ch2 == 'c') {\n          if (answer != null) {\n            out.append(answer);\n          } else if (globalFlags.goldAnswerColumn < fields.length) {\n            out.append(fields[globalFlags.goldAnswerColumn]);\n          } else {\n            out.append(\"Class\");\n          }\n        } else if (ch2 == 'n') {\n          out.append('\\n');\n        } else {\n          throw new IllegalArgumentException(\"Unrecognized format specification in \" + format);\n        }\n        i++; // have also dealt with next character giving format\n      } else {\n        out.append(ch);\n      }","sourceCodeStart":785,"sourceCodeEnd":821,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/classify/ColumnDataClassifier.java#L785-L821","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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"],"exampleFix":"// before\nprops.setProperty(\"csvFormat\", \"$3\\t$4\"); // input only has 3 columns (0-2)\n// after\nprops.setProperty(\"csvFormat\", \"$2\\t$3\"); // wait: use indices < fields.length, e.g. $0\\t$1","handlingStrategy":"validation","validationCode":"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);","typeGuard":"null","tryCatchPattern":"try { String out = testExamples(...); } catch (IllegalArgumentException e) { log.error(\"csvFormat references missing column: \" + e.getMessage()); }","preventionTips":["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"],"tags":["java","column-data-classifier","format-specification"],"backgroundTag":"index-out-of-range","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}