{"record":{"id":"406ec35e4b89004e","repo":"stanfordnlp/CoreNLP","slug":"cannot-deserialize-kbp-triples-with-this-method","errorCode":null,"errorMessage":"Cannot deserialize KBP triples with this method!","messagePattern":"Cannot deserialize KBP triples with this method!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/ProtobufAnnotationSerializer.java","lineNumber":1584,"sourceCode":"    List<CoreLabel> tokens = proto.getTokenList().stream().map(this::fromProto).collect(Collectors.toList());\n    lossySentence.set(TokensAnnotation.class, tokens);\n    setSentenceTokenAnnotations(lossySentence, proto, tokens, null);\n    // Add entailed sentences\n    if (proto.getEntailedSentenceCount() > 0) {\n      List<SentenceFragment> entailedSentences = proto.getEntailedSentenceList().stream().map(frag -> fromProto(frag, lossySentence.get(CollapsedDependenciesAnnotation.class))).collect(Collectors.toList());\n      lossySentence.set(NaturalLogicAnnotations.EntailedSentencesAnnotation.class, entailedSentences);\n    }\n    // Add entailed clauses\n    if (proto.getEntailedClauseCount() > 0) {\n      List<SentenceFragment> entailedClauses = proto.getEntailedClauseList().stream().map(frag -> fromProto(frag, lossySentence.get(CollapsedDependenciesAnnotation.class))).collect(Collectors.toList());\n      lossySentence.set(NaturalLogicAnnotations.EntailedClausesAnnotation.class, entailedClauses);\n    }\n    // Add relation triples\n    if (proto.getOpenieTripleCount() > 0) {\n      throw new IllegalStateException(\"Cannot deserialize OpenIE triples with this method!\");\n    }\n    if (proto.getKbpTripleCount() > 0) {\n      throw new IllegalStateException(\"Cannot deserialize KBP triples with this method!\");\n    }\n    // Add chinese characters\n    if (proto.getCharacterCount() > 0) {\n      List<CoreLabel> sentenceCharacters = proto.getCharacterList().stream().map(this::fromProto).collect(Collectors.toList());\n      lossySentence.set(SegmenterCoreAnnotations.CharactersAnnotation.class, sentenceCharacters);\n    }\n    // Add text -- missing by default as it's populated from the Document\n    lossySentence.set(TextAnnotation.class, recoverOriginalText(tokens, proto));\n\n    // add section info\n    if (proto.hasSectionName())\n      lossySentence.set(SectionAnnotation.class, proto.getSectionName());\n    if (proto.hasSectionDate())\n      lossySentence.set(SectionDateAnnotation.class, proto.getSectionDate());\n    if (proto.hasSectionAuthor())\n      lossySentence.set(AuthorAnnotation.class, proto.getSectionAuthor());\n    if (proto.hasSectionIndex())\n      lossySentence.set(SectionIndexAnnotation.class, proto.getSectionIndex());","sourceCodeStart":1566,"sourceCodeEnd":1602,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/ProtobufAnnotationSerializer.java#L1566-L1602","documentation":"ProtobufAnnotationSerializer.fromProto(CoreMap) refuses to deserialize sentences that carry KBP relation triples (RelationTriplesAnnotation from the kbp annotator). The lossy sentence-level conversion cannot reconstruct these triples, so their presence triggers an explicit IllegalStateException instead of silently dropping data.","triggerScenarios":"Calling ProtobufAnnotationSerializer.fromProto(CoreNLPProtos.Sentence) on a Sentence proto whose getKbpTripleCount() > 0, i.e. the pipeline was run with the kbp annotator and only the sentence protos were serialized.","commonSituations":"Streaming sentence protos from a server annotated with kbp, then deserializing with the lossy sentence-only API; mixed pipelines that enable kbp/openie but still use the older sentence-level serialization helpers.","solutions":["Use the document-level deserialization path (fromProto(CoreNLPProtos.Document)) so KBP triples are reconstructed.","Remove the kbp annotator from the pipeline, or clear KBP triple fields, before sentence-level serialization.","Catch IllegalStateException and re-issue deserialization at the document level."],"exampleFix":"// before\nCoreMap sentence = serializer.fromProto(sentenceProto); // throws when KBP triples present\n// after\nAnnotation doc = serializer.fromProto(docProto); // full-document deserialization preserves KBP triples","handlingStrategy":"validation","validationCode":"if (sentenceProto.getKbpTripleCount() > 0) {\n  throw new IllegalArgumentException(\"Sentence proto carries KBP triples; use document-level deserialization\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  cm = serializer.fromProto(sentenceProto);\n} catch (IllegalStateException e) {\n  cm = serializer.fromProto(documentProto).get(CoreAnnotations.SentencesAnnotation.class).get(idx);\n}","preventionTips":["Avoid sentence-only serialization for pipelines with kbp enabled","Validate the proto's triple counts before lossy deserialization","Document which annotations your serialization path drops so pipelines are configured accordingly"],"tags":["serialization","protobuf","kbp","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}