stanfordnlp/CoreNLP · error · RuntimeException
Expected nPrune, found:
Error message
Expected nPrune, found:
What it means
Options.readData reads a serialized (text-format) parser Options block line by line and expects a fixed schema. Each section must start with an expected prefix; when the line does not match '^nPrune.*' it throws RuntimeException('Expected nPrune, found: ...'), meaning the file's option section is out of order or written by an incompatible format version.
Solutions
- Use a parser model file that matches your library version (re-download the official model jar for your release).
- Retrain/regenerate the grammar file with the current parser version.
- Check that the file was not truncated or edited; restore from a clean copy.
- Pin the library version to the one the model was built with (check the Options serialVersionUID / release notes).
Example fix
// before
LexicalizedParser.loadModel("old-v1-englishPCFG.ser.gz"); // with parser 3.9.x
// after
LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz"); // matching version Defensive patterns
Strategy: validation
Validate before calling
try (BufferedReader in = Files.newBufferedReader(modelPath)) {
String line;
boolean ok = false;
while ((line = in.readLine()) != null) if (line.startsWith("nPrune")) { ok = true; break; }
if (!ok) throw new IllegalStateException("Model file options section missing nPrune line: " + modelPath);
} Try / catch
try {
parser = LexicalizedParser.loadModel(path);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Expected nPrune")) {
throw new IOException("Incompatible/corrupt model file: " + path, e);
}
throw e;
} Prevention
- Load model files shipped for your exact parser version.
- Never hand-edit serialized grammar/option text files.
- Verify checksums of downloaded model artifacts.
- Record which library version produced any custom-trained models.
When it happens
Trigger: Loading a parser model/grammar text file (via readData during parser loading) whose options section has a line where the 'nPrune' field is expected but a different field appears — typically a stale or corrupted model file, or a file written by a different parser version.
Common situations: Mixing model files and library versions (e.g., loading a model trained with an older/newer Stanford Parser), manually edited grammar files, or truncated/mangled file transfers.
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
- Expected blank line, found:
- format error in embeddings
- format error unexpected featureFactory line:
- expecting BEGIN block; got end of file.
- expecting BEGIN block; got
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/9219c4f65bc68810.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/lexparser/Options.java:1265
freeDependencies = Boolean.parseBoolean(value);
line = in.readLine();
value = line.substring(line.indexOf(' ') + 1);
directional = Boolean.parseBoolean(value);
line = in.readLine();
value = line.substring(line.indexOf(' ') + 1);
genStop = Boolean.parseBoolean(value);
line = in.readLine();
value = line.substring(line.indexOf(' ') + 1);
distance = Boolean.parseBoolean(value);
line = in.readLine();
value = line.substring(line.indexOf(' ') + 1);
coarseDistance = Boolean.parseBoolean(value);
line = in.readLine();
value = line.substring(line.indexOf(' ') + 1);
dcTags = Boolean.parseBoolean(value);
line = in.readLine();
if ( ! line.matches("^nPrune.*")) {
throw new RuntimeException("Expected nPrune, found: " + line);
}
value = line.substring(line.indexOf(' ') + 1);
nodePrune = Boolean.parseBoolean(value);
line = in.readLine(); // get rid of last line
if (line.length() != 0) {
throw new RuntimeException("Expected blank line, found: " + line);
}
}
private static final long serialVersionUID = 4L;
} // end class Options
View on GitHub (pinned to 1b7edd19c4)