BoundaryML/baml · error

unexpected type for int type: %T

Error message

unexpected type for int type: %T

What it means

typeBuilder.Int() calls the FFI method "int" and asserts the returned any implements the baml Type interface. A non-Type result (unwrapped raw pointer, nil, or wrong wrapper kind) triggers this error. It is a CFFI decoder contract failure, not an invalid argument from the caller.

Solutions

  1. Inspect %T in the error to identify the unwrapped object kind.
  2. Upgrade the baml Go module to match your native BAML runtime version.
  3. Regenerate/refresh cffi wrapper code if you maintain custom builds.
  4. File an upstream issue with the printed %T if versions are already aligned.

Example fix

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

// after: log the underlying type to aid diagnosis
typ, err := tb.Int()
if err != nil {
    return fmt.Errorf("tb.Int (update baml bindings if this persists): %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.Int()
if err != nil {
    log.Printf("Int() decode failure (check binding/runtime sync): %v", err)
    return fmt.Errorf("int type build failed: %w", err)
}

Prevention

When it happens

Trigger: Calling TypeBuilder.Int() when the underlying "int" method returns an object the Go bindings cannot wrap as a Type.

Common situations: Binding/native runtime version drift; stale generated wrapper registry; TypeBuilder instance created by a different runtime than the decoder expects.

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/6b77a5238f6cbb68. Report an issue: GitHub.

Appendix: source

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

	}

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

	return typ, nil
}

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

	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
}

View on GitHub (pinned to bd85ce9dee)