BoundaryML/baml · error
unexpected type for enum value builder: %T
Error message
unexpected type for enum value builder: %T
What it means
EnumBuilder.AddValue delegates to an internal helper that creates the enum value builder, then asserts the returned value implements EnumValueBuilder. If it does not, this error is thrown. It indicates the runtime's generic object factory returned an unexpected wrapper type when adding a value to a dynamic enum.
Source
Thrown at engine/language_client_go/pkg/rawobjects_enum_builder.go:39
func newEnumBuilder(ptr int64, rt unsafe.Pointer) EnumBuilder {
bldr := enumBuilder{raw_objects.FromPointer(ptr, rt), llmRenderableObject{}}
bldr.llmRenderableObject = llmRenderableObject{&bldr}
return &bldr
}
// AddValue adds a new value to the enum
func (eb *enumBuilder) AddValue(value string) (EnumValueBuilder, error) {
args := map[string]interface{}{
"value": value,
}
result, err := raw_objects.CallMethod(eb, "add_value", args)
if err != nil {
return nil, err
}
enumValueBuilder, ok := result.(EnumValueBuilder)
if !ok {
return nil, fmt.Errorf("unexpected type for enum value builder: %T", result)
}
return enumValueBuilder, nil
}
// Type returns the type definition for this enum
func (eb *enumBuilder) Type() (Type, error) {
result, err := raw_objects.CallMethod(eb, "type_", nil)
if err != nil {
return nil, err
}
typ, ok := result.(Type)
if !ok {
return nil, fmt.Errorf("unexpected type for enum type: %T", result)
}
return typ, nilView on GitHub (pinned to bd85ce9dee)
Solutions
- Align the Go SDK module and native BAML runtime to one consistent version (`go mod tidy`, reinstall)
- Rebuild or re-download the native runtime binary
- Read the %T value in the message to identify the wrong type returned and report upstream if reproducible
Defensive patterns
Strategy: try-catch
Type guard
func asEnumValueBuilder(v any) (EnumValueBuilder, bool) {
evb, ok := v.(EnumValueBuilder)
return evb, ok
} Try / catch
evb, err := enumBuilder.AddValue("ACTIVE")
if err != nil {
if strings.Contains(err.Error(), "unexpected type for enum value builder") {
return nil, fmt.Errorf("baml bindings/runtime version mismatch: %w", err)
}
return nil, err
} Prevention
- Keep the baml Go module and native runtime from the same release
- Exercise enum/type-builder paths in a startup smoke test to catch binding drift early
- When reporting, include the %T value from the error message
When it happens
Trigger: Calling AddValue on a runtime-constructed enum builder when the internal creation call returns a non-EnumValueBuilder result — a bindings/runtime version mismatch or a dispatch bug in the raw object factory.
Common situations: Mixed Go SDK / native runtime versions after partial upgrade; custom engine builds; hitting it in tests like TestTypeBuilderSkipEnumValue signals broken bindings rather than test input issues.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- unexpected type for collector creation: %T
- unexpected type for media creation: %T
- unexpected type for type builder creation: %T
- unexpected type for enum type: %T
- unexpected type for enum value builders: %T
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/322885b9a6c2a273.
Report an issue: GitHub.