Summary
Annotations.UnmarshalJSON (message/annotation.go) decodes via jsonx.UnmarshalDiscriminatedUnionSlice[Annotation], which errors on an unrecognized Type. Because annotations are nested inside content, an unknown annotation type from a newer service fails the entire message unmarshal, dropping all content rather than just the one unknown annotation.
Reproduction
data := []byte(`{"Contents":[{"Annotations":[{"Type":"futureAnno"}],"Text":"hi","Type":"text"}],"Role":"assistant"}`)
var m message.Message
err := json.Unmarshal(data, &m)
// err: "unsupported content type: futureAnno" — the whole message is lost
Impact
A forward-compatibility gap: when the service adds a new annotation (or annotated-region) kind, older SDK builds fail to deserialize any message carrying it, instead of degrading gracefully. AnnotatedRegions has the same shape and behavior.
Question / possible directions
This is a behavior/semantics decision, so raising as an issue rather than a PR:
- Give
Annotations / AnnotatedRegions a forward-compatible fallback (e.g. a raw-annotation type that preserves the unknown JSON), mirroring how unknown content types are handled, or
- Skip unknown-type entries in the slice rather than erroring the whole message.
Happy to send a PR for whichever direction you prefer.
Summary
Annotations.UnmarshalJSON(message/annotation.go) decodes viajsonx.UnmarshalDiscriminatedUnionSlice[Annotation], which errors on an unrecognizedType. Because annotations are nested inside content, an unknown annotation type from a newer service fails the entire message unmarshal, dropping all content rather than just the one unknown annotation.Reproduction
Impact
A forward-compatibility gap: when the service adds a new annotation (or annotated-region) kind, older SDK builds fail to deserialize any message carrying it, instead of degrading gracefully.
AnnotatedRegionshas the same shape and behavior.Question / possible directions
This is a behavior/semantics decision, so raising as an issue rather than a PR:
Annotations/AnnotatedRegionsa forward-compatible fallback (e.g. a raw-annotation type that preserves the unknown JSON), mirroring how unknown content types are handled, orHappy to send a PR for whichever direction you prefer.