stanfordnlp/CoreNLP · error · IllegalStateException
Cannot deserialize KBP triples with this method!
Error message
Cannot deserialize KBP triples with this method!
What it means
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.
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.
Example fix
// before CoreMap sentence = serializer.fromProto(sentenceProto); // throws when KBP triples present // after Annotation doc = serializer.fromProto(docProto); // full-document deserialization preserves KBP triples
Defensive patterns
Strategy: validation
Validate before calling
if (sentenceProto.getKbpTripleCount() > 0) {
throw new IllegalArgumentException("Sentence proto carries KBP triples; use document-level deserialization");
} Try / catch
try {
cm = serializer.fromProto(sentenceProto);
} catch (IllegalStateException e) {
cm = serializer.fromProto(documentProto).get(CoreAnnotations.SentencesAnnotation.class).get(idx);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Cannot deserialize OpenIE triples with this method!
- Sorry, but parsers with rerankers cannot be saved to text…
- Keys are not being serialized
- Unknown language
- Empty label not supported
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/406ec35e4b89004e.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/pipeline/ProtobufAnnotationSerializer.java:1584
List<CoreLabel> tokens = proto.getTokenList().stream().map(this::fromProto).collect(Collectors.toList());
lossySentence.set(TokensAnnotation.class, tokens);
setSentenceTokenAnnotations(lossySentence, proto, tokens, null);
// Add entailed sentences
if (proto.getEntailedSentenceCount() > 0) {
List<SentenceFragment> entailedSentences = proto.getEntailedSentenceList().stream().map(frag -> fromProto(frag, lossySentence.get(CollapsedDependenciesAnnotation.class))).collect(Collectors.toList());
lossySentence.set(NaturalLogicAnnotations.EntailedSentencesAnnotation.class, entailedSentences);
}
// Add entailed clauses
if (proto.getEntailedClauseCount() > 0) {
List<SentenceFragment> entailedClauses = proto.getEntailedClauseList().stream().map(frag -> fromProto(frag, lossySentence.get(CollapsedDependenciesAnnotation.class))).collect(Collectors.toList());
lossySentence.set(NaturalLogicAnnotations.EntailedClausesAnnotation.class, entailedClauses);
}
// Add relation triples
if (proto.getOpenieTripleCount() > 0) {
throw new IllegalStateException("Cannot deserialize OpenIE triples with this method!");
}
if (proto.getKbpTripleCount() > 0) {
throw new IllegalStateException("Cannot deserialize KBP triples with this method!");
}
// Add chinese characters
if (proto.getCharacterCount() > 0) {
List<CoreLabel> sentenceCharacters = proto.getCharacterList().stream().map(this::fromProto).collect(Collectors.toList());
lossySentence.set(SegmenterCoreAnnotations.CharactersAnnotation.class, sentenceCharacters);
}
// Add text -- missing by default as it's populated from the Document
lossySentence.set(TextAnnotation.class, recoverOriginalText(tokens, proto));
// add section info
if (proto.hasSectionName())
lossySentence.set(SectionAnnotation.class, proto.getSectionName());
if (proto.hasSectionDate())
lossySentence.set(SectionDateAnnotation.class, proto.getSectionDate());
if (proto.hasSectionAuthor())
lossySentence.set(AuthorAnnotation.class, proto.getSectionAuthor());
if (proto.hasSectionIndex())
lossySentence.set(SectionIndexAnnotation.class, proto.getSectionIndex());View on GitHub (pinned to 1b7edd19c4)