stanfordnlp/CoreNLP · error

Could not annotate via server!

Error message

Could not annotate via server!

What it means

StanfordCoreNLPClient.annotate caught a Throwable while sending the annotation request to the CoreNLP server (connection failure, HTTP error, bad response, timeout, etc.). If fallbackToLocalPipeline is enabled it retries locally; otherwise the Throwable is stored in ExceptionAnnotation on the annotation and this message is logged.

Solutions

  1. Verify the server is running and reachable: check the configured -host/-port (default http://localhost:9000)
  2. Read the attached Throwable (logged after the message or in ExceptionAnnotation) for the real cause
  3. Start the server with matching annotators/properties and compatible CoreNLP version
  4. Enable fallbackToLocalPipeline=true to annotate locally when the server fails
  5. Check payload size/timeouts; split very large documents into smaller requests

Example fix

// before
props.setProperty("annotators", "tokenize,ssplit,pos");
StanfordCoreNLPClient client = new StanfordCoreNLPClient(props, "http://localhost", 9001, 2);
// after
props.setProperty("annotators", "tokenize,ssplit,pos");
props.setProperty("fallbackToLocalPipeline", "true");
StanfordCoreNLPClient client = new StanfordCoreNLPClient(props, "http://localhost", 9000, 2);
Defensive patterns

Strategy: fallback

Validate before calling

// health check before annotating
HttpURLConnection c = (HttpURLConnection) new URL(serverUrl + "/ping").openConnection();
c.setConnectTimeout(3000);
if (c.getResponseCode() != 200) throw new IllegalStateException("CoreNLP server unreachable at " + serverUrl);

Try / catch

try {
    client.annotate(annotation);
} catch (Throwable t) {
    log.err("Could not annotate via server!", t);
    new StanfordCoreNLP(props).annotate(annotation); // local fallback
}

Prevention

When it happens

Trigger: Using StanfordCoreNLPClient with -backends/server URL where the server is down, wrong port, rejecting the request (e.g. unsupported serializer, oversized payload, annotator not loaded on server), or the connection drops mid-call; doAnnotation throwing inside annotate().

Common situations: Server not started or wrong -server/-port; request exceeding server's max payload or timeout; client/server CoreNLP version mismatch; firewall/proxy blocking the HTTP call; forgetting to start the server before running the client.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/StanfordCoreNLPClient.java:463

        serializer.write(annotation, os);
        os.close();
        byte[] message = os.toByteArray();
        // 1.2 Create the query params

        String queryParams = String.format("properties=%s",
                                           URLEncoder.encode(StanfordCoreNLPClient.this.propsAsJSON, "utf-8"));

        // 2. Create a connection
        URL serverURL = new URL(backend.protocol, backend.host, backend.port,
                                StanfordCoreNLPClient.this.path + '?' + queryParams);

        // 3. Do the annotation
        //    This method has two contracts:
        //    1. It should call the two relevant callbacks
        //    2. It must not throw an exception
        doAnnotation(annotation, backend, serverURL, message);
      } catch (Throwable t) {
        log.err("Could not annotate via server!", t);
        if (fallbackToLocalPipeline) {
          log.info("Trying to annotate locally...");
          StanfordCoreNLP corenlp = new StanfordCoreNLP(properties);
          corenlp.annotate(annotation);
        } else {
          annotation.set(CoreAnnotations.ExceptionAnnotation.class, t);
        }
      } finally {
        callback.accept(annotation);
        isFinishedCallback.accept(backend);
      }
    }).start());
  }

  static final int MAX_TRIES=3;

  /**
   * Actually try to perform the annotation on the server side.

View on GitHub (pinned to 1b7edd19c4)