stanfordnlp/CoreNLP · error · java.lang.IllegalArgumentException
Provided mapping file is in wrong format: " + line
Error message
Provided mapping file is in wrong format: " + line
What it means
RegexNERSequenceClassifier.readEntries parses each non-blank mapping line as TAB-separated fields: regex (1-3 columns accepted: 2 to 4 total fields — regex, type, optional overwritable types, optional priority). A line whose field count is outside 2-4 triggers this IllegalArgumentException, identifying the offending line.
Solutions
- Ensure each line has exactly 2-4 TAB-separated fields: regex, type, optional overwrite list, optional priority.
- Replace space separators with real tab characters (awk -F'\t' 'NF<2||NF>4' file to find bad lines).
- Comment out or remove non-conforming lines (comments must start with #).
- Check for double tabs or trailing tab characters creating empty extra fields.
Example fix
// before (spaces, no type column) Apple Inc is_a_company // after (tabs, regex + type) Apple\s+Inc\tORGANIZATION
Defensive patterns
Strategy: validation
Validate before calling
// lint mapping lines before loading
try (Stream<String> lines = Files.lines(Paths.get(mappingPath))) {
List<String> bad = lines.filter(l -> !l.trim().isEmpty() && !l.startsWith("#"))
.filter(l -> { String[] p = l.split("\t", -1); return p.length < 2 || p.length > 4; })
.collect(Collectors.toList());
if (!bad.isEmpty()) throw new IllegalStateException("Bad mapping lines: " + bad);
} Try / catch
try {
classifier = new RegexNERSequenceClassifier(props, mapping, true, false);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("Provided mapping file is in wrong format")) {
log.severe("Fix mapping line: " + e.getMessage());
}
throw e;
} Prevention
- Author mapping files with real tab separators (spaces don't count).
- Run a lint pass (field count check) in CI for mapping files.
- Keep line format: regex<TAB>type[<TAB>overwritable][<TAB>priority].
- Strip headers/extra columns from spreadsheet exports.
When it happens
Trigger: Loading a regexner mapping file containing lines with fewer than 2 or more than 4 tab-separated fields — e.g. lines with no type column, comment/header lines not starting with '#', spaces used instead of tabs, or stray tabs in descriptions.
Common situations: Hand-edited or CSV-exported rule files using spaces instead of tabs, Excel/Sheets exports introducing extra columns, Windows line endings with embedded tabs, or documentation example lines left in the file.
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
- Bad data format:
- TokensRegexNERAnnotator ERROR: Line of provided mapping…
- Argument array lengths differ
- Array lengths don't match
- attempt to get word when sentence and lattice are null!
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/5b125111a2840ef7.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/regexp/RegexNERSequenceClassifier.java:284
* Creates a combined list of Entries using the provided mapping file, and sorts them by
* first by priority, then the number of tokens in the regex.
*
* @param mapping The Reader containing RegexNER mappings. It's lines are counted from 1
* @return a sorted list of Entries
*/
private static List<Entry> readEntries(BufferedReader mapping, boolean ignoreCase) throws IOException {
List<Entry> entries = new ArrayList<>();
int lineCount = 0;
for (String line; (line = mapping.readLine()) != null; ) {
lineCount ++;
// skip blank lines
if (line.trim().equals(""))
continue;
String[] split = line.split("\t");
if (split.length < 2 || split.length > 4)
throw new IllegalArgumentException("Provided mapping file is in wrong format: " + line);
String[] regexes = split[0].trim().split("\\s+");
String type = split[1].trim();
Set<String> overwritableTypes = Generics.newHashSet();
double priority = 0.0;
List<Pattern> tokens = new ArrayList<>();
if (split.length >= 3) {
overwritableTypes.addAll(Arrays.asList(split[2].trim().split(",")));
}
// by default, always consider overwriting the background symbol
overwritableTypes.add("O");
if (split.length == 4) {
try {
priority = Double.parseDouble(split[3].trim());
} catch(NumberFormatException e) {
throw new IllegalArgumentException("ERROR: Invalid line " + lineCount + " in regexner file " + mapping + ": \"" + line + "\"!", e);View on GitHub (pinned to 1b7edd19c4)