BoundaryML/baml · error

unexpected type for body: %T

Error message

unexpected type for body: %T

What it means

Thrown by httpResponse.Body() when the FFI call succeeded but the decoded result does not implement the HTTPBody interface. The %T verb names the concrete Go type that arrived. It indicates the body object was decoded into a type the Go bindings do not recognize as an HTTPBody, usually from version drift between the BAML core and the Go bindings.

Solutions

  1. Upgrade the Go bindings and BAML core to matching versions
  2. Check the %T in the error and look for the missing case in the pkg/cffi body decoder
  3. Fall back to reading raw body bytes via other available accessors if the typed body is unusable
  4. File a BAML issue with the %T value if versions already match

Example fix

body, err := resp.Body()
if err != nil {
    log.Printf("typed body unavailable: %v", err)
    return err
}
Defensive patterns

Strategy: type-guard

Validate before calling

if resp == nil { return errors.New("nil HTTPResponse") }

Type guard

func safeTypedBody(resp baml.HTTPResponse) (baml.HTTPBody, bool) {
    b, err := resp.Body()
    return b, err == nil
}

Try / catch

body, err := resp.Body()
if err != nil {
    if strings.Contains(err.Error(), "unexpected type") {
        return fmt.Errorf("body decode drift (check version match): %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling HTTPResponse.Body() when the core returns a body object decoded as a generic RawObject or an unrecognized body variant rather than an httpBody implementation.

Common situations: Mixed engine/binding versions; event-log bodies produced by a newer BAML release; unhandled body encoding added on the core side without a matching Go decoder.

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

Appendix: source

Thrown at engine/language_client_go/pkg/rawobjects_http_response.go:77

	}

	headers, ok := result.(map[string]string)
	if !ok {
		return nil, fmt.Errorf("unexpected type for headers: %T", result)
	}

	return headers, nil
}

func (h *httpResponse) Body() (HTTPBody, error) {
	result, err := raw_objects.CallMethod(h, "body", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get body: %w", err)
	}

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

	return body, nil
}

View on GitHub (pinned to bd85ce9dee)