BoundaryML/baml · error
unexpected type for enum value builders: %T
Error message
unexpected type for enum value builders: %T
What it means
ListValues() asks the runtime for all values of an enum and expects a slice of raw_objects.RawPointer, each of which must also implement EnumValueBuilder. This error fires when the FFI result fails the first assertion to []raw_objects.RawPointer, meaning the runtime returned something other than the expected list of enum-value handles.
Source
Thrown at engine/language_client_go/pkg/rawobjects_enum_builder.go:69
typ, ok := result.(Type)
if !ok {
return nil, fmt.Errorf("unexpected type for enum type: %T", result)
}
return typ, nil
}
// ListValues returns all values in the enum
func (eb *enumBuilder) ListValues() ([]EnumValueBuilder, error) {
result, err := raw_objects.CallMethod(eb, "list_values", nil)
if err != nil {
return nil, err
}
rawObjects, ok := result.([]raw_objects.RawPointer)
if !ok {
return nil, fmt.Errorf("unexpected type for enum value builders: %T", result)
}
enumValueBuilders := make([]EnumValueBuilder, len(rawObjects))
for i, rawObject := range rawObjects {
enumValueBuilders[i] = rawObject.(EnumValueBuilder)
}
return enumValueBuilders, nil
}
// Value gets a specific value from the enum
func (eb *enumBuilder) Value(name string) (EnumValueBuilder, error) {
args := map[string]interface{}{
"name": name,
}
result, err := raw_objects.CallMethod(eb, "value", args)
if err != nil {
return nil, errView on GitHub (pinned to bd85ce9dee)
Solutions
- Rebuild so Go bindings and BAML runtime versions match (go generate / regenerate Go client)
- Confirm the enum has static values declared in .baml files before listing
- Re-create the enum builder from a fresh BamlRuntime rather than reusing a stale handle
- Update the BAML Go package to the latest version
Example fix
// before
enumBuilder := runtime.EnsureEnum("MyEnum")
values, err := enumBuilder.ListValues() // error if handle is stale
// after
runtime, _ := baml.NewBamlRuntimeFromFiles("./baml_src", nil, nil)
values, err := runtime.EnsureEnum("MyEnum").ListValues() Defensive patterns
Strategy: try-catch
Validate before calling
values, err := enumBuilder.ListValues()
if err != nil && strings.Contains(err.Error(), "unexpected type") { /* rebuild bindings */ } Type guard
func asRawSlice(v any) ([]raw_objects.RawPointer, bool) { s, ok := v.([]raw_objects.RawPointer); return s, ok } Try / catch
values, err := enumBuilder.ListValues()
if err != nil {
return fmt.Errorf("listing enum values: %w", err) // includes this error wrapped
} Prevention
- Regenerate the Go client whenever the BAML CLI version changes
- Create enum builders from a fresh runtime, not stale handles
- Declare enum values statically in .baml when you need ListValues
When it happens
Trigger: Calling ListValues() on an EnumBuilder whose runtime 'list_values' method returns a non-slice or wrong element type — usually a bindings/runtime version skew or a corrupted/invalid enum object handle.
Common situations: Go bindings regenerated against a newer runtime than the linked one; enum defined with dynamic type builder where values aren't listable; passing a stale EnumBuilder handle after the runtime context was reset.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- unexpected type for enum type: %T
- unexpected type for collector creation: %T
- unexpected type for media creation: %T
- unexpected type for type builder creation: %T
- unexpected type for enum value builder: %T
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/161ce9bf6b32a679.
Report an issue: GitHub.