BoundaryML/baml · error

unexpected type for selected: %T

Error message

unexpected type for selected: %T

What it means

llmCall.Selected() expects the native runtime to return a Go bool for the "selected" method. When the FFI layer deserializes the result into some other Go type, the wrapper rejects it with "unexpected type for selected: %T". This indicates a contract mismatch between the native runtime and the Go binding.

Solutions

  1. Check the runtime version matches the generated BAML Go client
  2. Verify the LLM call actually ran through a selection-capable path before calling Selected()
  3. Log result type via %T if you control the wrapper; report a binding bug if the native layer is correct

Example fix

// before
ok, err := call.Selected()
// after
if err != nil {
    if strings.Contains(err.Error(), "unexpected type") {
        // runtime returned non-bool; treat as not-selected and log
        log.Printf("selection unavailable: %v", err)
        return false, nil
    }
    return false, err
}
Defensive patterns

Strategy: type-guard

Type guard

// Go: verify via errors before trusting the bool
ok, err := call.Selected()
if err != nil {
    if strings.Contains(err.Error(), "unexpected type") {
        // runtime returned non-bool; treat as unknown
        return false
    }
    return false
}

Try / catch

// Go
if err != nil {
    log.Printf("selected type mismatch: %v", err)
    return false, nil
}

Prevention

When it happens

Trigger: Calling Selected() when the runtime returns nil or a non-bool (e.g. a wrapped object, string, or nil from a missing/changed "selected" method) instead of a Go bool.

Common situations: Version skew: generated client built against an older runtime where "selected" returned a different shape; a nil/None result from the native side when selection data was never produced (e.g. streaming or a non-selector model).

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

Appendix: source

Thrown at engine/language_client_go/pkg/rawobjects_llm_call.go:122

	}

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

	return usage, nil
}

func (l *llmCall) Selected() (bool, error) {
	result, err := raw_objects.CallMethod(l, "selected", nil)
	if err != nil {
		return false, fmt.Errorf("failed to get selected: %w", err)
	}

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

	return selected, nil
}

func (l *llmCall) Timing() (Timing, error) {
	result, err := raw_objects.CallMethod(l, "timing", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get timing: %w", err)
	}

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

	return timing, nil
}

View on GitHub (pinned to bd85ce9dee)