BoundaryML/baml · error

unexpected type for class property type: %T

Error message

unexpected type for class property type: %T

What it means

ClassPropertyBuilder.Type() asks the runtime for the property's type via the `type_` method and asserts the result implements the Type interface. If the FFI call yields any other Go type, this error is returned. It means the runtime did not return a proper type-definition object, typically because of a bindings/runtime mismatch or a degraded FFI result.

Source

Thrown at engine/language_client_go/pkg/rawobjects_class_property_builder.go:44

// Type sets the type for the property
func (cpb *classPropertyBuilder) SetType(fieldType Type) error {
	args := map[string]interface{}{
		"field_type": fieldType,
	}
	_, err := raw_objects.CallMethod(cpb, "set_type", args)
	return err
}

func (cpb *classPropertyBuilder) Type() (Type, error) {
	result, err := raw_objects.CallMethod(cpb, "type_", nil)
	if err != nil {
		return nil, err
	}

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

	return typ, nil
}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Align the Go module version with the installed BAML runtime and reinstall both.
  2. Check that the property's declared field type (the Type passed to AddProperty) came from the same runtime instance, not a foreign object.
  3. Recreate the class builder/property pipeline and retry to rule out corrupt runtime state.
  4. File a BAML issue including the %T value from the message if it persists.

Example fix

// before
typ, err := propBuilder.Type()
// after
typ, err := propBuilder.Type()
if err != nil {
    return nil, fmt.Errorf("could not resolve property type (runtime mismatch?): %w", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate the property builder is non-nil and from the same session
// if propBuilder == nil { return errors.New("propBuilder required") }

Type guard

func isType(result any) bool {
    _, ok := result.(Type)
    return ok
}

Try / catch

typ, err := propBuilder.Type()
if err != nil {
    if strings.Contains(err.Error(), "unexpected type for class property type") {
        return nil, fmt.Errorf("Type() FFI contract violation: %w", err)
    }
    return nil, err
}

Prevention

When it happens

Trigger: Calling ClassPropertyBuilder.Type() when CallMethod returns something other than a Type — e.g. nil, a raw pointer that failed type resolution, or a value decoded with an unexpected object type.

Common situations: Introspecting dynamic classes with mismatched Go client and native runtime versions; the property was added with a field type the runtime could not re-materialize; corrupted or stale shared runtime artifacts.

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