BoundaryML/baml · error

unexpected type for class property builders: %T

Error message

unexpected type for class property builders: %T

What it means

BAML's Go client wraps dynamic class-builder objects that live behind an FFI boundary. When ListProperties() calls the remote `list_properties` method, it expects the runtime to hand back a []raw_objects.RawPointer; if the shared runtime returns any other Go type, this error is thrown instead of silently continuing. It signals a version or state mismatch between the Go bindings and the native BAML runtime, i.e. the FFI layer broke its documented return contract.

Source

Thrown at engine/language_client_go/pkg/rawobjects_class_builder.go:51

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

	return typ, nil
}

// ListProperties returns all properties in the class
func (cb *classBuilder) ListProperties() ([]ClassPropertyBuilder, error) {
	result, err := raw_objects.CallMethod(cb, "list_properties", nil)
	if err != nil {
		return nil, err
	}

	rawObjects, ok := result.([]raw_objects.RawPointer)
	if !ok {
		return nil, fmt.Errorf("unexpected type for class property builders: %T", result)
	}

	rawObjectsCast := make([]ClassPropertyBuilder, len(rawObjects))
	for i, rawObject := range rawObjects {
		rawObjectsCast[i] = rawObject.(ClassPropertyBuilder)
	}

	return rawObjectsCast, nil
}

// AddProperty adds a new property to the class
func (cb *classBuilder) AddProperty(name string, fieldType Type) (ClassPropertyBuilder, error) {
	args := map[string]interface{}{
		"name":       name,
		"field_type": fieldType,
	}
	result, err := raw_objects.CallMethod(cb, "add_property", args)
	if err != nil {

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Verify the baml Go module version matches the installed BAML CLI/runtime version and upgrade both together (`go get -u github.com/boundaryml/baml/...` + `baml version`).
  2. Check runtime logs for an earlier panic or error in the `list_properties` method that would have made CallMethod return a non-pointer result.
  3. Rebuild/reinstall the BAML runtime artifacts so the FFI bindings are in sync, then retry.
  4. If it persists, file a bug with the %T value printed in the error message so maintainers can see which type leaked through the FFI layer.

Example fix

// before
rawObjects, ok := result.([]raw_objects.RawPointer)
if !ok {
    return nil, fmt.Errorf("unexpected type for class property builders: %T", result)
}
// after
callers cannot patch this directly; guard the call site:
props, err := classBuilder.ListProperties()
if err != nil {
    return nil, fmt.Errorf("ListProperties unavailable (runtime/bindings mismatch): %w", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Go has no pre-call check; verify version parity instead:
// baml.Version() == expectedRuntimeVersion (checked at startup)

Type guard

func isClassPropertyBuilderList(result any) bool {
    _, ok := result.([]raw_objects.RawPointer)
    return ok
}

Try / catch

props, err := classBuilder.ListProperties()
if err != nil {
    if strings.Contains(err.Error(), "unexpected type for class property builders") {
        // treat as runtime/bindings mismatch: fail fast with diagnostics
        return nil, fmt.Errorf("FFI contract violation in ListProperties: %w", err)
    }
    return nil, err
}

Prevention

When it happens

Trigger: Calling ClassBuilder.ListProperties() when the underlying CallMethod returns something other than []raw_objects.RawPointer — typically a nil result, a single raw pointer, or a deserialized map after a partial runtime failure.

Common situations: Mixing a Go client built against one BAML version with a native runtime library of another; a runtime crash mid-call that yields a default/empty result; using a class builder object that was never fully initialized on the runtime side.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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