{"record":{"id":"327d9352e69ff64a","repo":"stanfordnlp/CoreNLP","slug":"could-not-parse-input-format-inputformat","errorCode":null,"errorMessage":"Could not parse input format: ${inputFormat}","messagePattern":"Could not parse input format: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/StanfordCoreNLPServer.java","lineNumber":343,"sourceCode":"        // We use to trim. But now we don't. It seems like doing that is illegitimate. text = text.trim();\n\n        // Read the annotation\n        Annotation annotation = new Annotation(text);\n        // Set the date (if provided)\n        if (date != null) {\n          annotation.set(CoreAnnotations.DocDateAnnotation.class, date);\n        }\n        return annotation;\n      case \"serialized\":\n        String inputSerializerName = props.getProperty(\"inputSerializer\", ProtobufAnnotationSerializer.class.getName());\n        if (!inputSerializerName.equals(ProtobufAnnotationSerializer.class.getName())) {\n          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.\");\n        }\n        AnnotationSerializer serializer = new ProtobufAnnotationSerializer();\n        Pair<Annotation, InputStream> pair = serializer.read(httpExchange.getRequestBody());\n        return pair.first;\n      default:\n        throw new IOException(\"Could not parse input format: \" + inputFormat);\n    }\n  }\n\n  private String getContentType(Headers headers) {\n    String contentType = URL_ENCODED;\n    if (headers.containsKey(\"Content-type\")) {\n      contentType = headers.getFirst(\"Content-type\").split(\";\")[0].trim();\n    }\n    return contentType;\n  }\n\n  private String getEncoding(Headers headers) {\n    // The default encoding by the HTTP standard is ISO-8859-1, but most\n    // real users of CoreNLP would likely assume UTF-8 by default.\n    String defaultEncoding = this.strict ? \"ISO-8859-1\" : \"UTF-8\";\n    if (headers.containsKey(\"Content-type\")) {\n      String[] charsetPair = Arrays.stream(headers.getFirst(\"Content-type\").split(\";\"))\n          .map(x -> x.split(\"=\"))","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/StanfordCoreNLPServer.java#L325-L361","documentation":"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.","triggerScenarios":"POSTing to StanfordCoreNLPServer with the inputFormat property set to an unhandled string (e.g. 'json' as input, 'xml', or a typo like 'txt').","commonSituations":"Assuming the server accepts JSON input (it accepts JSON only as output); typos in inputFormat; clients echoing back output formats as input formats.","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"],"exampleFix":"// before\ncurl -d '...' 'localhost:9000/?properties={\"inputFormat\":\"json\",\"annotators\":\"ner\"}'\n// after\ncurl -d '...' 'localhost:9000/?properties={\"inputFormat\":\"text\",\"annotators\":\"ner\"}'","handlingStrategy":"validation","validationCode":"String in = props.getProperty(\"inputFormat\", \"text\");\nif (!in.equals(\"text\") && !in.equals(\"serialized\")) {\n  throw new IllegalArgumentException(\"inputFormat must be text or serialized, got: \" + in);\n}","typeGuard":null,"tryCatchPattern":"try {\n  postToServer(props, body);\n} catch (IOException e) {\n  if (e.getMessage().startsWith(\"Could not parse input format\")) {\n    props.setProperty(\"inputFormat\", \"text\");\n    postToServer(props, body);\n  } else throw e;\n}","preventionTips":["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"],"tags":["http-server","input-format","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}