BoundaryML/baml · error

error decoding value, unknown literal type:

Error message

error decoding value, unknown literal type: 

What it means

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.

Source

Thrown at engine/language_client_go/baml_go/serde/decode.go:515

		literalType := literalType.LiteralType
		switch literalType.Literal.(type) {
		case *cffi.CFFIFieldTypeLiteral_BoolLiteral:
			literalValue := literalType.Literal.(*cffi.CFFIFieldTypeLiteral_BoolLiteral).BoolLiteral.Value
			if literalValue {
				return "bool_true"
			} else {
				return "bool_false"
			}
		case *cffi.CFFIFieldTypeLiteral_IntLiteral:
			literalValue := literalType.Literal.(*cffi.CFFIFieldTypeLiteral_IntLiteral).IntLiteral.Value
			return "int_literal:" + strconv.FormatInt(literalValue, 10)
		case *cffi.CFFIFieldTypeLiteral_StringLiteral:
			literalValue := literalType.Literal.(*cffi.CFFIFieldTypeLiteral_StringLiteral).StringLiteral.Value
			// replace all non-alphanumeric characters with an underscore
			safeLiteralValue := strings.ReplaceAll(literalValue, "[^a-zA-Z0-9]", "_")
			return "string_" + safeLiteralValue
		default:
			panic("error decoding value, unknown literal type: " + fmt.Sprintf("%+v", literalType.Literal))
		}
	}
	if _, ok := fieldType.Type.(*cffi.CFFIFieldTypeHolder_ClassType); ok {
		return "class"
	}
	if enumType, ok := fieldType.Type.(*cffi.CFFIFieldTypeHolder_EnumType); ok {
		enumType := enumType.EnumType
		enumName := enumType.Name
		return enumName
	}
	if _, ok := fieldType.Type.(*cffi.CFFIFieldTypeHolder_UnionVariantType); ok {
		return "union"
	}
	if _, ok := fieldType.Type.(*cffi.CFFIFieldTypeHolder_OptionalType); ok {
		return "optional"
	}
	if _, ok := fieldType.Type.(*cffi.CFFIFieldTypeHolder_CheckedType); ok {
		return "checked"

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Upgrade the Go baml runtime package to a version whose typeToString handles the literal variant (go get -u github.com/boundaryml/baml/...)
  2. Avoid the unsupported literal form in the .baml output type (e.g. replace a float literal union with a constrained float) and regenerate
  3. Keep baml-cli and the native library at the same version as the Go runtime to prevent unknown variants
  4. Check the panic dump of literalType.Literal to identify which variant is missing and open/track the corresponding baml issue

Example fix

// before (baml): float literal union
function PickTemp() float {
  output {{ 1.5 | 2.5 }}
}

// after: use supported literal kinds or plain type, validate at runtime
function PickTemp() float {
  output "@include one of 1.5 or 2.5"
}
// or upgrade the Go client so float literals are supported, then regenerate
Defensive patterns

Strategy: validation

Validate before calling

// Restrict output literal kinds to what the Go runtime supports (bool/int/string)
// lint-style check over baml_src output unions:
var supportedLiteralKinds = regexp.MustCompile(`^(-?\d+|"[^"]*"|true|false)$`)
func validateLiteralOutput(outType string) error {
	if !supportedLiteralKinds.MatchString(strings.TrimSpace(outType)) {
		return fmt.Errorf("unsupported literal kind %q — upgrade baml go runtime or change output type", outType)
	}
	return nil
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/e05750672f39d6c9. Report an issue: GitHub.