stanfordnlp/CoreNLP · error · RuntimeException

ERROR: Invalid dependency node line

Error message

ERROR: Invalid dependency node line: ${line}

What it means

CustomAnnotationSerializer.loadDependencyGraph reads the first line of the dependency graph file as a tab-separated node list. Each line must have at least 3 tab-separated fields (docId, sentenceIndex, then one or more node entries). If the split yields fewer than 3 fields, the line is malformed and a RuntimeException is thrown.

Solutions

  1. Regenerate the dependency graph file with CustomAnnotationSerializer from a pipeline run so the format is correct
  2. Check the offending line has 3+ tab-separated fields: docId, sentence index, and node entries
  3. Verify the file being loaded was produced by CustomAnnotationSerializer and not another format
  4. Confirm consistent CoreNLP versions between writer and reader of the serialized data

Example fix

// before: passing arbitrary text file
parser.loadDependencyGraph(new BufferedReader(new FileReader("tokens.txt")));
// after: pass a file produced by CustomAnnotationSerializer
AnnotationSerializer serializer = new CustomAnnotationSerializer();
Pair<Annotation, InputStream> pair = serializer.read(new FileInputStream("serialized.ser.gz"));
Defensive patterns

Strategy: validation

Validate before calling

String line = reader.readLine().trim();
int tabs = line.split("\t", -1).length;
if (line.length() > 0 && tabs < 3) throw new IllegalArgumentException("Bad dependency node line: " + line);

Type guard

static boolean isValidNodeLine(String line) {
  return line == null || line.length() == 0 || line.split("\t", -1).length >= 3;
}

Try / catch

try {
  Pair<Annotation, InputStream> p = serializer.read(in);
} catch (RuntimeException e) {
  if (e.getMessage().startsWith("ERROR: Invalid dependency node line")) {
    // regenerate the serialized file
  } else throw e;
}

Prevention

When it happens

Trigger: Loading a dependency graph file whose first non-empty line has fewer than 3 tab-separated fields — e.g. a truncated file, a corrupted serialized annotation, or a file written by a different/incompatible serializer.

Common situations: Manually editing dependency graph files and dropping a tab; passing a non-annotation file (e.g. plain text or a sentence-per-line file) to loadDependencyGraph; mixed CoreNLP versions where the serialization format changed.

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


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/aa5f0990a4daa299. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/CustomAnnotationSerializer.java:67

  public CustomAnnotationSerializer() {
    this(true, false);
  }

  public CustomAnnotationSerializer(boolean compress, boolean haveAnte) {
    this.compress = compress;
    this.haveExplicitAntecedent = haveAnte;
  }


  private static IntermediateSemanticGraph loadDependencyGraph(BufferedReader reader) throws IOException {
    IntermediateSemanticGraph graph = new IntermediateSemanticGraph();

    // first line: list of nodes
    String line = reader.readLine().trim();
    // System.out.println("PARSING LINE: " + line);
    if(line.length() > 0){
      String [] bits = line.split("\t");
      if(bits.length < 3) throw new RuntimeException("ERROR: Invalid dependency node line: " + line);
      String docId = bits[0];
      if(docId.equals("-")) docId = "";
      int sentIndex = Integer.parseInt(bits[1]);
      for(int i = 2; i < bits.length; i ++){
        String bit = bits[i];
        String[] bbits = bit.split("-");
        int copyAnnotation = -1;
        boolean isRoot = false;
        if(bbits.length > 3){
          throw new RuntimeException("ERROR: Invalid format for dependency graph: " + line);
        } else if(bbits.length == 2){
          copyAnnotation = Integer.parseInt(bbits[1]);
        } else if(bbits.length == 3){
          copyAnnotation = Integer.parseInt(bbits[1]);
          isRoot = bbits[2].equals("R");
        }
        int index = Integer.parseInt(bbits[0]);
        graph.nodes.add(new IntermediateNode(docId, sentIndex, index, copyAnnotation, isRoot));

View on GitHub (pinned to 1b7edd19c4)