{"record":{"id":"3e20153cb3b95865","repo":"BoundaryML/baml","slug":"unsupported-type-for-baml-encoding-t-kind-s","errorCode":null,"errorMessage":"unsupported type for BAML encoding: %T (Kind: %s)","messagePattern":"unsupported type for BAML encoding: %T \\(Kind: (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/baml_go/serde/encode.go","lineNumber":190,"sourceCode":"\n\tcase reflect.Map:\n\t\tif rv.Type().Key().Kind() != reflect.String {\n\t\t\treturn nil, fmt.Errorf(\"map key type must be string, got %s\", rv.Type().Key().Kind())\n\t\t}\n\n\t\tencoded, err := encodeMap(rv)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"encoding map: %w\", err)\n\t\t}\n\t\treturn &cffi.HostValue{\n\t\t\tValue: &cffi.HostValue_MapValue{\n\t\t\t\tMapValue: encoded,\n\t\t\t},\n\t\t}, nil\n\n\tdefault:\n\t\t// Use originalValue's type for the error message as it's more accurate to the input\n\t\treturn nil, fmt.Errorf(\"unsupported type for BAML encoding: %T (Kind: %s)\", originalValue, rv.Kind())\n\t}\n}\n\n// --- Encoding helpers for specific types ---\n\n// encodeList now accepts and passes TypeMap\nfunc encodeList(value reflect.Value) (*cffi.HostListValue, error) {\n\tvalues := make([]*cffi.HostValue, value.Len())\n\tfor i := value.Len() - 1; i >= 0; i-- {\n\t\telemOffset, err := encodeValue(value.Index(i).Interface()) // Pass typeMap recursively\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"encoding list element %d: %w\", i, err)\n\t\t}\n\t\tvalues[i] = elemOffset\n\t}\n\n\treturn &cffi.HostListValue{\n\t\tValues: values,","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/serde/encode.go#L172-L208","documentation":"Catch-all rejection in encodeValue: the value's Go kind is not one BAML can encode (not string, int, float, bool, slice/array, or string-keyed map) and it implements no BAML serializer interface. The error names the concrete Go type and reflect kind so the offending field can be located.","triggerScenarios":"Passing structs without a BamlSerializer implementation, channels, funcs, complex numbers, pointers-to-structs lacking serializers, or time.Time-like types as baml function arguments or class fields.","commonSituations":"Passing time.Time directly; nested custom structs in class fields; using interface{} containers holding exotic types; forgetting to use generated baml types for custom classes.","solutions":["Convert the value to a supported type (string, number, bool, slice, string-keyed map)","Use the generated BAML client types for classes/enums/unions instead of raw Go structs","Implement the BamlSerializer (Encode/BamlTypeName) interface for custom types","For internal objects like media, use the provided baml types (e.g. types.Image) rather than custom structs"],"exampleFix":"// before\ntype Point struct{ X, Y int }\nb.Fn(ctx, Point{1, 2})\n// after\nb.Fn(ctx, map[string]any{\"x\": 1, \"y\": 2})","handlingStrategy":"type-guard","validationCode":"func checkEncodable(v any) error { switch v.(type) { case string, int, int64, float64, bool: return nil }; switch reflect.ValueOf(v).Kind() { case reflect.Slice, reflect.Array, reflect.Map: return nil; default: return fmt.Errorf(\"unsupported: %T\", v) } }","typeGuard":"func isBamlSerializable(v any) bool {\n  _, a := v.(BamlSerializer); _, b := v.(InternalBamlSerializer)\n  return a || b || isEncodablePrimitiveOrCollection(v)\n}","tryCatchPattern":"if err := b.Fn(ctx, in); err != nil {\n  if strings.Contains(err.Error(), \"unsupported type for BAML encoding\") { /* convert or serialize and retry */ }\n}","preventionTips":["Use generated BAML types for classes/enums/unions instead of raw structs","Convert time.Time and similar to strings before passing","Implement BamlSerializer for frequently used custom types","Audit baml call sites for non-primitive arguments"],"tags":["go","serialization","baml","type-restriction"],"backgroundTag":"type-mismatch","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"}