stanfordnlp/CoreNLP · error · IllegalArgumentException

unable to find sentences in

Error message

unable to find sentences in: ${annotation}

What it means

SentenceAnnotator's annotate() dispatches per-sentence work (optionally threaded) but requires the Annotation to already contain SentencesAnnotation; subclasses like ParserAnnotator run after sentence splitting. When the key is missing it throws IllegalArgumentException because a prerequisite annotator was not run.

Solutions

  1. Include 'ssplit' (and 'tokenize') before the sentence-level annotator: annotators=tokenize,ssplit,parse.
  2. Populate CoreAnnotations.SentencesAnnotation manually when feeding pre-segmented text.
  3. Run WordsToSentencesAnnotator explicitly if annotating incrementally outside StanfordCoreNLP.

Example fix

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

Strategy: validation

Validate before calling

if (!annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) {
  throw new IllegalStateException("Sentence-level annotator requires SentencesAnnotation; add ssplit to the pipeline");
}

Try / catch

try {
  annotator.annotate(annotation);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("unable to find sentences in")) {
    wordsToSentences.annotate(annotation);
    annotator.annotate(annotation);
  } else throw e;
}

Prevention

When it happens

Trigger: Running annotators that extend SentenceAnnotator (e.g. parse, sentiment, nlu) on an Annotation without SentencesAnnotation — typically when 'ssplit' is missing from the pipeline or annotate() is called directly.

Common situations: Pipelines like annotators=tokenize,parse (missing ssplit), calling SentenceAnnotator subclasses on a raw Annotation in tests, or clearing the annotation between stages.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/SentenceAnnotator.java:106

        List<CoreMap> failedSentences = wrapper.joinWithTimeout();
        while (wrapper.peek()) {
          wrapper.poll();
        }
        if (failedSentences != null) {
          for (CoreMap failed : failedSentences) {
            doOneFailedSentence(annotation, failed);
          }
        }
      } else {
        for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
          if (Thread.interrupted()) {
            throw new RuntimeInterruptedException();
          }
          doOneSentence(annotation, sentence);
        }
      }
    } else {
      throw new IllegalArgumentException("unable to find sentences in: " + annotation);
    }
  }

  protected abstract int nThreads();

  /**
   * The maximum time to run this annotator for, in milliseconds.
   */
  protected abstract long maxTime();

  /** annotation is included in case there is global information we care about */
  protected abstract void doOneSentence(Annotation annotation, CoreMap sentence);

  /**
   * Fills in empty annotations for trees, tags, etc if the annotator
   * failed or timed out.  Not supposed to do major processing.
   *
   * @param annotation The whole Annotation object, in case it is needed for context.

View on GitHub (pinned to 1b7edd19c4)