{"record":{"id":"a1c237772c8a56a0","repo":"BoundaryML/baml","slug":"union-selected-type-selected-is-not-a-member-of-declared","errorCode":null,"errorMessage":"Union selected type `{selected}` is not a member of declared union `{union}`","messagePattern":"Union selected type `(.+?)` is not a member of declared union `(.+?)`","errorType":"error_code","errorClass":"CtypesError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bridge_ctypes/src/error.rs","lineNumber":36,"sourceCode":"    MapEntryMissingKey,\n\n    /// Carries only the input length, not the input itself — untrusted hex\n    /// blobs can be up to the FFI decode cap (~67M chars), and embedding\n    /// them in error messages bloats logs and exposes payload contents.\n    #[error(\"Invalid bigint hex string ({len} bytes)\")]\n    InvalidBigint { len: usize },\n\n    /// Carries only the input length for over-cap decimal type literals, so a\n    /// hostile descriptor cannot amplify logs by echoing its full payload.\n    #[error(\"Invalid decimal bigint literal ({len} bytes)\")]\n    InvalidBigintLiteral { len: usize },\n\n    #[error(\n        \"Invalid InboundValue.value_type: a root union or optional does not identify one exact selected type\"\n    )]\n    InvalidInboundValueTypeRootUnion,\n\n    #[error(\"Union selected type `{selected}` is not a member of declared union `{union}`\")]\n    UnionSelectedTypeNotMember { selected: String, union: String },\n\n    #[error(\"Internal error: {0}\")]\n    InternalError(String),\n}\n","sourceCodeStart":18,"sourceCodeEnd":42,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bridge_ctypes/src/error.rs#L18-L42","documentation":"CtypesError::UnionSelectedTypeNotMember { selected, union } is raised when an InboundValue claims a union selected type that is not actually one of the declared union's members. The decoder checks the selection against the declared union descriptor and refuses values that name a foreign or renamed variant, protecting against schema skew and malformed payloads.","triggerScenarios":"Decoding an inbound value where value_type/selected names a type absent from the declared union's member list — e.g. after renaming or removing a union member, or crossing bridge/library version boundaries.","commonSituations":"BAML schema updated (member added/renamed/removed) but the producer still sends the old selected-type name; two libraries at different versions disagreeing on union members; typos in hand-built descriptors.","solutions":["Re-align the producer's schema with the bridge: regenerate bindings after any union member change.","Check the exact member names (the error names `selected` and `union`) and fix the selected value or the descriptor.","Upgrade both sides to matching versions so the union definition agrees.","Validate selections against the declared union in the host before the FFI call."],"exampleFix":"// before\nselected = \"Image\"  # removed from union in new schema\nsend_inbound(union=\"Media\", selected=selected)\n// after\nselected = \"ImageUrl\"  # current member of Media\nsend_inbound(union=\"Media\", selected=selected)","handlingStrategy":"validation","validationCode":"def ensure_union_member(declared_union: set[str], selected: str):\n    if selected not in declared_union:\n        raise ValueError(f\"{selected} is not a member of the declared union\")","typeGuard":null,"tryCatchPattern":"try:\n    val = bridge.decode_inbound(buf, len(buf))\nexcept BridgeError as e:\n    if \"is not a member of declared union\" in str(e):\n        raise ValueError(\"schema skew: regenerate producer bindings for the union\") from e\n    raise","preventionTips":["Regenerate bindings on both sides whenever union members change","Validate selected variant names against the current schema before FFI calls","Keep producer and bridge on the same version in deployment"],"tags":["union","schema","decoding","ffi"],"backgroundTag":"invalid-enum-value","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}