BoundaryML/baml · error
unexpected type for http response: %T
Error message
unexpected type for http response: %T
What it means
LLMCall.HttpResponse() asserts the runtime result implements HTTPResponse; this error fires when the deserialized FFI value has a different type (%T reveals it). It means the runtime returned an unexpected payload shape for the http_response attribute — a Go-binding/runtime contract mismatch. A nil result is handled earlier and returns (nil, nil), so this only fires on a present-but-wrong-typed value.
Source
Thrown at engine/language_client_go/pkg/rawobjects_llm_call.go:90
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)
}
return response, nil
}
func (l *llmCall) Usage() (Usage, error) {
result, err := raw_objects.CallMethod(l, "usage", nil)
if err != nil {
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)View on GitHub (pinned to bd85ce9dee)
Solutions
- Upgrade and regenerate BAML bindings so both sides agree on the response object type.
- Inspect the %T value to see what was actually returned and report persistent mismatches.
- Handle the error gracefully in tracing/logging code paths.
- Ensure you never swapped request/response objects when storing call metadata.
Example fix
// before
resp, err := call.HttpResponse()
if err != nil { return err }
// after
resp, err := call.HttpResponse()
if err != nil {
log.Printf("http response type mismatch: %v", err)
resp = nil
} Defensive patterns
Strategy: type-guard
Type guard
func isHTTPResponse(v interface{}) (baml.HTTPResponse, bool) {
resp, ok := v.(baml.HTTPResponse)
return resp, ok
} Try / catch
resp, err := call.HttpResponse()
if err != nil {
log.Printf("http response type mismatch: %v", err)
return nil
} Prevention
- Synchronize Go binding and native runtime versions.
- Capture %T on mismatch for debugging.
- Handle nil response separately from type errors.
- Never swap stored request/response references.
When it happens
Trigger: raw_objects.CallMethod(l, "http_response", nil) returns a non-nil value failing the response.(HTTPResponse) assertion at rawobjects_llm_call.go:88-91 — e.g. an HTTPRequest object or a raw CFFI wrapper.
Common situations: Version skew between Go bindings and native runtime changing how http_response is typed; a runtime bug returning a request object where a response was expected; objects created by a different runtime instance.
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
- unexpected type for client name: %T
- unexpected type for provider: %T
- unexpected type for http request: %T
- unexpected type for usage: %T
- unexpected type for class property builders: %T
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/188cc8d604ae7f0c.
Report an issue: GitHub.