stanfordnlp/CoreNLP · error · RuntimeException

ERROR: Invalid format for dependency graph

Error message

ERROR: Invalid format for dependency graph: ${line}

What it means

Within loadDependencyGraph, each node entry (after docId and sentence index) is a token split on '-' with at most 3 parts (id, copy annotation, optional root flag 'R'). If a node entry splits into more than 3 parts, the entry format is invalid and a RuntimeException is thrown.

Solutions

  1. Fix the offending node entry so each is of form id, id-copyNum, or id-copyNum-R
  2. Regenerate the file with CustomAnnotationSerializer.write instead of manual editing
  3. Check for accidental extra hyphens in node ids in the input line
  4. Validate one line at a time with a small script splitting on tab then '-' before loading

Example fix

// before: line contains bad entry like "5-2-extra"
// 5	0	3-1	5-2-extra
// after: corrected node entries with valid id-copy[-R] form
// 5	0	3-1	5-2-R
Defensive patterns

Strategy: validation

Validate before calling

for (String entry : nodeFields) {
  int hyphens = entry.length() - entry.replace("-", "").length();
  if (hyphens > 2) throw new IllegalArgumentException("Bad node entry: " + entry);
}

Type guard

static boolean isValidNodeEntry(String entry) {
  String[] bbits = entry.split("-", -1);
  return bbits.length >= 1 && bbits.length <= 3;
}

Try / catch

try {
  serializer.read(in);
} catch (RuntimeException e) {
  if (e.getMessage().startsWith("ERROR: Invalid format for dependency graph")) {
    log.severe("Corrupt node entry; regenerate file");
  } else throw e;
}

Prevention

When it happens

Trigger: A node entry in the dependency graph's node line contains more than two '-' characters, e.g. a token id accidentally containing hyphens or a hand-edited/corrupted node entry.

Common situations: Hand-editing serialized dependency files; tokens whose serialized representation embeds '-' separators incorrectly; writing the graph with a custom formatter that deviates from the expected id-copyBits convention.

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/6e36137540477958. Report an issue: GitHub.

Appendix: source

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

  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));
      }
    }

    // second line: list of deps
    line = reader.readLine().trim();
    if(line.length() > 0){
      String [] bits = line.split("\t");
      for(String bit: bits){
        String [] bbits = bit.split(" ");
        if(bbits.length < 3 || bbits.length > 6){

View on GitHub (pinned to 1b7edd19c4)