Skip to content

Unknown annotation discriminator type aborts the entire message unmarshal #513

Description

@PratikDhanave

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:

  1. 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
  2. Skip unknown-type entries in the slice rather than erroring the whole message.

Happy to send a PR for whichever direction you prefer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions