stanfordnlp/CoreNLP · error · IOException
Could not parse input format
Error message
Could not parse input format: ${inputFormat} What it means
getDocument() switches on the request's inputFormat property; any value other than the handled cases (text, serialized, etc.) hits the default branch and throws IOException with the unrecognized value. The server cannot decode the POSTed request body.
Solutions
- Set inputFormat to text or serialized (check the supported cases in getDocument for your version)
- Remove the inputFormat property to use the default (text)
- If sending structured input, use the Protobuf serialized format produced by CoreNLP's own serializer
Example fix
// before
curl -d '...' 'localhost:9000/?properties={"inputFormat":"json","annotators":"ner"}'
// after
curl -d '...' 'localhost:9000/?properties={"inputFormat":"text","annotators":"ner"}' Defensive patterns
Strategy: validation
Validate before calling
String in = props.getProperty("inputFormat", "text");
if (!in.equals("text") && !in.equals("serialized")) {
throw new IllegalArgumentException("inputFormat must be text or serialized, got: " + in);
} Try / catch
try {
postToServer(props, body);
} catch (IOException e) {
if (e.getMessage().startsWith("Could not parse input format")) {
props.setProperty("inputFormat", "text");
postToServer(props, body);
} else throw e;
} Prevention
- Only use inputFormat=text or serialized for the CoreNLP server
- Remember the server does not accept JSON as input, only as output
- Centralize request-properties construction in one validated helper
When it happens
Trigger: POSTing to StanfordCoreNLPServer with the inputFormat property set to an unhandled string (e.g. 'json' as input, 'xml', or a typo like 'txt').
Common situations: Assuming the server accepts JSON input (it accepts JSON only as output); typos in inputFormat; clients echoing back output formats as input formats.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Unhandled input format for scenegraph
- Array lengths don't match
- Attempt to make ObjectBank with empty file list
- Called headPreTerminal on a leaf:
- Can't have null components!
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/327d9352e69ff64a.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/pipeline/StanfordCoreNLPServer.java:343
// We use to trim. But now we don't. It seems like doing that is illegitimate. text = text.trim();
// Read the annotation
Annotation annotation = new Annotation(text);
// Set the date (if provided)
if (date != null) {
annotation.set(CoreAnnotations.DocDateAnnotation.class, date);
}
return annotation;
case "serialized":
String inputSerializerName = props.getProperty("inputSerializer", ProtobufAnnotationSerializer.class.getName());
if (!inputSerializerName.equals(ProtobufAnnotationSerializer.class.getName())) {
throw new IOException("Specifying an inputSerializer other than ProtobufAnnotationSerializer is now deprecated for security reasons. See https://github.com/stanfordnlp/CoreNLP/security/advisories/GHSA-wv35-hv9v-526p If you have need for a different class, please post about your use case on the CoreNLP github.");
}
AnnotationSerializer serializer = new ProtobufAnnotationSerializer();
Pair<Annotation, InputStream> pair = serializer.read(httpExchange.getRequestBody());
return pair.first;
default:
throw new IOException("Could not parse input format: " + inputFormat);
}
}
private String getContentType(Headers headers) {
String contentType = URL_ENCODED;
if (headers.containsKey("Content-type")) {
contentType = headers.getFirst("Content-type").split(";")[0].trim();
}
return contentType;
}
private String getEncoding(Headers headers) {
// The default encoding by the HTTP standard is ISO-8859-1, but most
// real users of CoreNLP would likely assume UTF-8 by default.
String defaultEncoding = this.strict ? "ISO-8859-1" : "UTF-8";
if (headers.containsKey("Content-type")) {
String[] charsetPair = Arrays.stream(headers.getFirst("Content-type").split(";"))
.map(x -> x.split("="))View on GitHub (pinned to 1b7edd19c4)