stanfordnlp/CoreNLP · error · RuntimeException

unable to find sentences in: " + annotation

Error message

unable to find sentences in: " + annotation

What it means

CharniakParserAnnotator.annotate() parses each sentence found in the Annotation; if SentencesAnnotation is absent there is nothing to parse and it throws this RuntimeException. Like other parsers it requires tokenization and sentence splitting as prerequisites.

Solutions

  1. Include 'tokenize,ssplit' before the parser in the annotators list
  2. Check pipeline ordering when composing annotators manually
  3. Ensure earlier annotators ran without exceptions that left the annotation empty

Example fix

// before
props.setProperty("annotators", "charniak");
// after
props.setProperty("annotators", "tokenize,ssplit,charniak");
Defensive patterns

Strategy: validation

Validate before calling

if (annotation.get(CoreAnnotations.SentencesAnnotation.class) == null) {
  throw new IllegalStateException("Run tokenize+ssplit before CharniakParserAnnotator");
}

Try / catch

try {
  parser.annotate(annotation);
} catch (RuntimeException e) {
  if (e.getMessage().startsWith("unable to find sentences")) {
    // rerun pipeline with tokenize,ssplit first
  } else throw e;
}

Prevention

When it happens

Trigger: Running the Charniak parser annotator on an Annotation with no CoreAnnotations.SentencesAnnotation, typically because tokenize/ssplit did not run first.

Common situations: Building a pipeline with only the parser annotator; incorrect annotator ordering; a previous annotator silently failing to add sentences.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/CharniakParserAnnotator.java:79

        if (VERBOSE) {
          log.info("Parsing: " + words);
        }
        int maxSentenceLength = parser.getMaxSentenceLength();
        // generate the constituent tree
        Tree tree; // initialized below
        if (maxSentenceLength <= 0 || words.size() < maxSentenceLength) {
          tree = parser.getBestParse(words);
        }
        else {
          tree = ParserUtils.xTree(words);
        }

        List<Tree> trees = Generics.newArrayList(1);
        trees.add(tree);
        ParserAnnotatorUtils.fillInParseAnnotations(VERBOSE, BUILD_GRAPHS, gsf, sentence, trees, GrammaticalStructure.Extras.NONE);
      }
    } else {
      throw new RuntimeException("unable to find sentences in: " + annotation);
    }
  }

  @Override
  public Set<Class<? extends CoreAnnotation>> requires() {
    return Collections.unmodifiableSet(new ArraySet<>(Arrays.asList(
        CoreAnnotations.TextAnnotation.class,
        CoreAnnotations.TokensAnnotation.class,
        CoreAnnotations.CharacterOffsetBeginAnnotation.class,
        CoreAnnotations.CharacterOffsetEndAnnotation.class,
        CoreAnnotations.SentencesAnnotation.class
    )));
  }

  @Override
  public Set<Class<? extends CoreAnnotation>> requirementsSatisfied() {
    return Collections.unmodifiableSet(new ArraySet<>(Arrays.asList(
        CoreAnnotations.PartOfSpeechAnnotation.class,

View on GitHub (pinned to 1b7edd19c4)