BoundaryML/baml · error

failed to get selected

Error message

failed to get selected: %w

What it means

BAML's Go binding wraps a Rust/CFFI runtime. llmCall.Selected() calls raw_objects.CallMethod(l, "selected", nil) across the FFI boundary; if the native layer fails to answer the "selected" method call, the Go wrapper wraps the underlying error with "failed to get selected". This is a transport/bridge failure, not a normal application error.

Solutions

  1. Print the wrapped cause with errors.Unwrap or %v to see the underlying FFI error and fix that first
  2. Re-fetch the llmCall from a fresh BAML function invocation instead of reusing a stale handle
  3. Ensure the BAML runtime is initialized and not shut down before calling Selected()
  4. Align the generated Go client and the native baml library versions

Example fix

// before
selected, err := call.Selected()
// after
selected, err := call.Selected()
if err != nil {
    log.Printf("selected lookup failed: %v", err) // inspect wrapped cause
    return false
}
Defensive patterns

Strategy: try-catch

Try / catch

// Go
selected, err := call.Selected()
if err != nil {
    log.Printf("failed to get selected: %v", err)
    return false
}

Prevention

When it happens

Trigger: Calling Selected() on an LLMCall object whose underlying native pointer has been invalidated, freed, or whose runtime returned an error for the "selected" method (e.g. after runtime shutdown or an internal Rust-side panic surfaced as an error).

Common situations: Using an llmCall retrieved from a completed/cancelled function call after the runtime was torn down; version mismatch between generated BAML client code and the native baml runtime library; accessing the call concurrently while the runtime resets state.

Related errors


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

Appendix: source

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

		return nil, fmt.Errorf("failed to get usage: %w", err)
	}

	if result == nil {
		return nil, nil
	}

	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 {

View on GitHub (pinned to bd85ce9dee)