{"record":{"id":"e05750672f39d6c9","repo":"BoundaryML/baml","slug":"error-decoding-value-unknown-literal-type","errorCode":null,"errorMessage":"error decoding value, unknown literal type: ","messagePattern":"error decoding value, unknown literal type: ","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/baml_go/serde/decode.go","lineNumber":515,"sourceCode":"\t\tliteralType := literalType.LiteralType\n\t\tswitch literalType.Literal.(type) {\n\t\tcase *cffi.CFFIFieldTypeLiteral_BoolLiteral:\n\t\t\tliteralValue := literalType.Literal.(*cffi.CFFIFieldTypeLiteral_BoolLiteral).BoolLiteral.Value\n\t\t\tif literalValue {\n\t\t\t\treturn \"bool_true\"\n\t\t\t} else {\n\t\t\t\treturn \"bool_false\"\n\t\t\t}\n\t\tcase *cffi.CFFIFieldTypeLiteral_IntLiteral:\n\t\t\tliteralValue := literalType.Literal.(*cffi.CFFIFieldTypeLiteral_IntLiteral).IntLiteral.Value\n\t\t\treturn \"int_literal:\" + strconv.FormatInt(literalValue, 10)\n\t\tcase *cffi.CFFIFieldTypeLiteral_StringLiteral:\n\t\t\tliteralValue := literalType.Literal.(*cffi.CFFIFieldTypeLiteral_StringLiteral).StringLiteral.Value\n\t\t\t// replace all non-alphanumeric characters with an underscore\n\t\t\tsafeLiteralValue := strings.ReplaceAll(literalValue, \"[^a-zA-Z0-9]\", \"_\")\n\t\t\treturn \"string_\" + safeLiteralValue\n\t\tdefault:\n\t\t\tpanic(\"error decoding value, unknown literal type: \" + fmt.Sprintf(\"%+v\", literalType.Literal))\n\t\t}\n\t}\n\tif _, ok := fieldType.Type.(*cffi.CFFIFieldTypeHolder_ClassType); ok {\n\t\treturn \"class\"\n\t}\n\tif enumType, ok := fieldType.Type.(*cffi.CFFIFieldTypeHolder_EnumType); ok {\n\t\tenumType := enumType.EnumType\n\t\tenumName := enumType.Name\n\t\treturn enumName\n\t}\n\tif _, ok := fieldType.Type.(*cffi.CFFIFieldTypeHolder_UnionVariantType); ok {\n\t\treturn \"union\"\n\t}\n\tif _, ok := fieldType.Type.(*cffi.CFFIFieldTypeHolder_OptionalType); ok {\n\t\treturn \"optional\"\n\t}\n\tif _, ok := fieldType.Type.(*cffi.CFFIFieldTypeHolder_CheckedType); ok {\n\t\treturn \"checked\"","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/serde/decode.go#L497-L533","documentation":"Inside typeToString, a LiteralType holder is serialized by mapping its literal value (bool/int/string) to a key. If the literal variant is none of BoolLiteral, IntLiteral, or StringLiteral (e.g. a float literal added in a newer engine), the switch hits default and panics. The Go runtime does not recognize the literal kind sent by the engine.","triggerScenarios":"Decoding a type that is a literal (e.g. output type `1 | 2` or `\"a\" | \"b\"` or a float literal like `1.5`) where the literal's CFFI variant is not supported by the compiled Go runtime — notably float literals from newer engine versions with an older Go client.","commonSituations":"Using float literals in BAML output unions with a Go client that predates their support; generated Go code and native engine built from different versions.","solutions":["Upgrade the Go baml runtime package to a version whose typeToString handles the literal variant (go get -u github.com/boundaryml/baml/...)","Avoid the unsupported literal form in the .baml output type (e.g. replace a float literal union with a constrained float) and regenerate","Keep baml-cli and the native library at the same version as the Go runtime to prevent unknown variants","Check the panic dump of literalType.Literal to identify which variant is missing and open/track the corresponding baml issue"],"exampleFix":"// before (baml): float literal union\nfunction PickTemp() float {\n  output {{ 1.5 | 2.5 }}\n}\n\n// after: use supported literal kinds or plain type, validate at runtime\nfunction PickTemp() float {\n  output \"@include one of 1.5 or 2.5\"\n}\n// or upgrade the Go client so float literals are supported, then regenerate","handlingStrategy":"validation","validationCode":"// Restrict output literal kinds to what the Go runtime supports (bool/int/string)\n// lint-style check over baml_src output unions:\nvar supportedLiteralKinds = regexp.MustCompile(`^(-?\\d+|\"[^\"]*\"|true|false)$`)\nfunc validateLiteralOutput(outType string) error {\n\tif !supportedLiteralKinds.MatchString(strings.TrimSpace(outType)) {\n\t\treturn fmt.Errorf(\"unsupported literal kind %q — upgrade baml go runtime or change output type\", outType)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use bool/int/string literal unions in output types unless the Go runtime is upgraded","Upgrade Go runtime and CLI in lockstep before adopting new literal kinds","Cover each output type with a decode smoke test in CI"],"tags":["go","ffi","deserialization","literal-type","baml"],"backgroundTag":"unsupported-enum-value","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"}