{"record":{"id":"d6d528b473f1d4d6","repo":"BoundaryML/baml","slug":"unexpected-type-for-enum-type-t","errorCode":null,"errorMessage":"unexpected type for enum type: %T","messagePattern":"unexpected type for enum type: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_enum_builder.go","lineNumber":54,"sourceCode":"\n\tenumValueBuilder, ok := result.(EnumValueBuilder)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for enum value builder: %T\", result)\n\t}\n\n\treturn enumValueBuilder, nil\n}\n\n// Type returns the type definition for this enum\nfunc (eb *enumBuilder) Type() (Type, error) {\n\tresult, err := raw_objects.CallMethod(eb, \"type_\", nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\ttyp, ok := result.(Type)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for enum type: %T\", result)\n\t}\n\n\treturn typ, nil\n}\n\n// ListValues returns all values in the enum\nfunc (eb *enumBuilder) ListValues() ([]EnumValueBuilder, error) {\n\tresult, err := raw_objects.CallMethod(eb, \"list_values\", nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\trawObjects, ok := result.([]raw_objects.RawPointer)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for enum value builders: %T\", result)\n\t}\n\n\tenumValueBuilders := make([]EnumValueBuilder, len(rawObjects))","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_enum_builder.go#L36-L72","documentation":"Type() on the enum builder calls into the BAML runtime via raw objects and expects the runtime method to return a value implementing the Type interface. If the FFI result cannot be asserted to Type, this error is thrown instead of panicking, indicating a mismatch between what the runtime returned and what the Go bindings expect.","triggerScenarios":"Calling Type() on an EnumBuilder when the underlying raw object's 'get_type'-style method returns an unexpected Go type — typically after a runtime/bindings version mismatch or if the enum itself failed to resolve in the runtime.","commonSituations":"Using a Go client package version that doesn't match the compiled BAML CFFI runtime; referencing an enum defined in a way the runtime can't materialize (e.g. enum from a different BAML project/variant); stale compiled runtime embedded via cgo.","solutions":["Regenerate/rebuild so the Go bindings and the BAML runtime (baml-cli generate-go / go generate) are from the same version","Verify the enum referenced actually exists in the loaded BAML source files","Check that no old .so/cffi artifact is cached in the build (clean rebuild with go clean)","Update github.com/eython/baml or boundaryml baml Go package and runtime to matching latest versions"],"exampleFix":"// before: mixing baml runtime v0.x with Go bindings v0.y\n// go.mod: github.com/boundaryml/baml v0.202.0 but runtime v0.198.0\n// after\n// go.mod: github.com/boundaryml/baml v0.202.0\n// run: go mod tidy && go clean && go generate ./...","handlingStrategy":"try-catch","validationCode":"// verify the enum exists before use\n// enums, err := bamlRuntime.ListEnums() ; ensure \"MyEnum\" is present","typeGuard":"func asType(v any) (Type, bool) { t, ok := v.(Type); return t, ok }","tryCatchPattern":"typ, err := enumBuilder.Type()\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for enum type\") {\n        // rebuild runtime / regenerate Go bindings\n    }\n    return fmt.Errorf(\"enum type lookup failed: %w\", err)\n}","preventionTips":["Keep Go bindings and BAML runtime versions identical (regenerate together)","Run go clean before builds after upgrading BAML","Verify enums exist in baml_src before referencing them in Go"],"tags":["go","type-assertion","baml-runtime","version-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}