BoundaryML/baml · error

unexpected type for float type: %T

Error message

unexpected type for float type: %T

What it means

typeBuilder.Float() calls the FFI method "float" and asserts the result implements the baml Type interface. If the bridge returns any other value (unwrapped pointer, nil, wrong wrapper), this error is thrown. It means the native side built the float type but the Go bindings could not decode it into a Type.

Solutions

  1. Read %T in the error message to see what the decoder actually produced.
  2. Align the baml Go dependency version with the native BAML runtime.
  3. Regenerate cffi bindings if you build BAML from source.
  4. Report upstream with the printed type if versions already match.

Example fix

// before
floatTyp, err := tb.Float()
if err != nil {
    return err
}

// after
doubleTyp, err := tb.Float()
if err != nil {
    return fmt.Errorf("float type build failed (check baml binding/runtime versions): %w", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

if tb == nil {
    return errors.New("type builder is nil")
}

Type guard

func isBamlType(v any) bool { _, ok := v.(baml.Type); return ok }

Try / catch

typ, err := tb.Float()
if err != nil {
    if strings.Contains(err.Error(), "unexpected type for float type") {
        return fmt.Errorf("float type decode failed - verify baml binding/runtime versions: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling TypeBuilder.Float() when the underlying "float" method returns a non-Type object from the bridge.

Common situations: Mismatched baml Go module and native runtime versions; wrapper registry lacking the mapping for the returned object type; custom builds with stale generated code.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at engine/language_client_go/pkg/rawobjects_type_builder.go:61

	}

	typ, ok := result.(Type)
	if !ok {
		return nil, fmt.Errorf("unexpected type for int type: %T", result)
	}

	return typ, nil
}

func (tb *typeBuilder) Float() (Type, error) {
	result, err := raw_objects.CallMethod(tb, "float", nil)
	if err != nil {
		return nil, err
	}

	typ, ok := result.(Type)
	if !ok {
		return nil, fmt.Errorf("unexpected type for float type: %T", result)
	}

	return typ, nil
}

func (tb *typeBuilder) Bool() (Type, error) {
	result, err := raw_objects.CallMethod(tb, "bool", nil)
	if err != nil {
		return nil, err
	}

	typ, ok := result.(Type)
	if !ok {
		return nil, fmt.Errorf("unexpected type for bool type: %T", result)
	}

	return typ, nil
}

View on GitHub (pinned to bd85ce9dee)