{"record":{"id":"4bfcbb96c070b628","repo":"BoundaryML/baml","slug":"error-decoding-value-type-alias-not-found","errorCode":null,"errorMessage":"error decoding value, type alias not found: ","messagePattern":"error decoding value, type alias not found: ","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/baml_go/serde/decode.go","lineNumber":460,"sourceCode":"\t\treturn reflect.SliceOf(goElementType)\n\t}\n\n\tif map_, ok := type_.(*cffi.CFFIFieldTypeHolder_MapType); ok {\n\t\tmapType := map_.MapType\n\t\tgoKeyType := convertFieldTypeToGoType(mapType.KeyType, typeMap)\n\t\tgoValueType := convertFieldTypeToGoType(mapType.ValueType, typeMap)\n\t\tif goValueType == typeMap.typeMap[\"INTERNAL.nil\"] {\n\t\t\treturn reflect.TypeOf(map[string]any{})\n\t\t}\n\t\treturn reflect.MapOf(goKeyType, goValueType)\n\t}\n\n\tif typeAlias, ok := type_.(*cffi.CFFIFieldTypeHolder_TypeAliasType); ok {\n\t\tname := typeAlias.TypeAliasType.Name.Name\n\t\tnamespace := typeAlias.TypeAliasType.Name.Namespace.String()\n\t\tgoType, ok := typeMap.typeMap[namespace+\".\"+name]\n\t\tif !ok {\n\t\t\tpanic(\"error decoding value, type alias not found: \" + namespace + \".\" + name)\n\t\t}\n\t\treturn goType\n\t}\n\n\t// any is weird in go, (alias for interface{})\n\tif _, ok := type_.(*cffi.CFFIFieldTypeHolder_NullType); ok {\n\t\tif _, ok := typeMap.typeMap[\"INTERNAL.nil\"]; ok {\n\t\t\treturn reflect.TypeOf((*interface{})(nil)).Elem()\n\t\t}\n\t\treturn reflect.TypeOf((*interface{})(nil))\n\t}\n\tif _, ok := type_.(*cffi.CFFIFieldTypeHolder_AnyType); ok {\n\t\treturn reflect.TypeOf((*interface{})(nil)).Elem()\n\t}\n\n\tpanic(\"error decoding value, unknown field type: \" + fmt.Sprintf(\"%+v\", fieldType))\n}\n","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/serde/decode.go#L442-L478","documentation":"While converting a CFFI type descriptor to a Go type, the decoder resolves a TypeAliasType by looking up \"<namespace>.<name>\" in the TypeMap. This panic means the type alias referenced by the Rust engine is not present in the Go TypeMap — usually because the Go client was generated before the alias was added or renamed in the .baml file.","triggerScenarios":"Decoding a value whose declared type is a BAML type alias (type Foo = ...) that the generated TypeMap does not contain, e.g. after adding `type MyAlias = string | int` to the baml file without regenerating the Go client, or when the alias namespace from the engine does not match the generated map keys.","commonSituations":"Renaming or adding type aliases in .baml files and running old generated code; multiple baml projects where an alias namespace differs from the generated Go package namespace; version skew between the baml runtime and CLI.","solutions":["Run `baml-cli generate` to regenerate the Go client so the TypeMap includes the alias under the expected namespace.name key","Verify the alias name/namespace in the .baml file matches what was generated (rename it back or regenerate after renames)","Align baml CLI and Go runtime dependency versions (go get -u github.com/boundaryml/baml/... and reinstall the CLI)","If a dynamic fallback is desired, check whether your baml version supports dynamic types and register the alias in the TypeMap when constructing it"],"exampleFix":"// before (baml): alias added but Go client stale\ntype Price = int | float\n\n// after: regenerate\n// terminal:\n// baml-cli generate  # TypeMap now contains \"baml.Price\" -> generated Go type\n// then rebuild the Go app","handlingStrategy":"validation","validationCode":"// Pre-check that every alias used in baml_src exists in the generated TypeMap\nfunc validateAliases(tm baml_go.TypeMap, aliases []string) error {\n\tfor _, a := range aliases {\n\t\tif _, ok := tm.TypeMap[a]; !ok {\n\t\t\treturn fmt.Errorf(\"type alias %q missing from generated client — run baml-cli generate\", a)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Regenerate the Go client whenever a type alias is added or renamed in .baml files","Verify go.mod points at the same baml version as the installed CLI","Avoid hand-editing generated baml_go code"],"tags":["go","ffi","deserialization","type-alias","baml"],"backgroundTag":"unexpected-response-shape","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"}