BoundaryML/baml · error

unexpected type for http request: %T

Error message

unexpected type for http request: %T

What it means

LLMCall.HttpRequest() type-asserts the runtime result to the HTTPRequest interface; this error fires when the deserialized FFI value is not a HTTPRequest (%T shows the actual type). It means the runtime returned an unexpected payload shape for the http_request attribute — a binding/runtime contract mismatch.

Source

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

	}

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

	return provider, nil
}

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

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

	return request, nil
}

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

	if result == nil {
		return nil, nil
	}

	response, ok := result.(HTTPResponse)
	if !ok {
		return nil, fmt.Errorf("unexpected type for http response: %T", result)

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Upgrade the Go bindings and BAML runtime to matching versions and regenerate.
  2. Check the %T in the message to identify the wrong type returned, and report if it persists.
  3. Guard logging/diagnostics code so a type mismatch degrades gracefully.
  4. Ensure the object you are querying is genuinely an LLM call, not another BAML object type.

Example fix

// before
req, err := call.HttpRequest()
if err != nil { return err }

// after
req, err := call.HttpRequest()
if err != nil {
    log.Printf("http request type mismatch: %v", err)
    return nil // degrade instead of failing the pipeline
}
Defensive patterns

Strategy: type-guard

Type guard

func isHTTPRequest(v interface{}) (baml.HTTPRequest, bool) {
    req, ok := v.(baml.HTTPRequest)
    return req, ok
}

Try / catch

req, err := call.HttpRequest()
if err != nil {
    log.Printf("http request type mismatch: %v", err)
    return nil
}

Prevention

When it happens

Trigger: raw_objects.CallMethod(l, "http_request", nil) returns a value failing the request.(HTTPRequest) assertion at rawobjects_llm_call.go:70-73 — e.g. a raw wrapper struct, nil, or wrong object type (such as an HTTPResponse).

Common situations: Version skew between the Go bindings and the native runtime encoding http_request differently; a runtime regression returning a mismatched object type; mixing call objects across runtime instances.

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