BoundaryML/baml · error
failed to decode object response: %w
Error message
failed to decode object response: %w
What it means
This error wraps decodeObjectResponse failures in NewRawObject. The constructor call succeeded and the protobuf unmarshalled, but the response content could not be decoded into a Go object: it may be an error response from the native side, an object handle that cannot be decoded, or a serde value of unexpected shape.
Source
Thrown at engine/language_client_go/baml_go/raw_objects/utils.go:137
content_bytes := C.GoBytes(unsafe.Pointer(cBuf.ptr), C.int32_t(cBuf.len))
C.WrapFreeBuffer(cBuf) // Free the buffer after use
if cBuf.len == 0 {
return nil, fmt.Errorf("failed to call object constructor")
}
if cBuf.ptr == nil {
return nil, fmt.Errorf("object constructor returned nil pointer")
}
var content_holder cffi.InvocationResponse
err = proto.Unmarshal(content_bytes, &content_holder)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal content bytes: %w", err)
}
parsed, err := decodeObjectResponse(rt, &content_holder)
if err != nil {
return nil, fmt.Errorf("failed to decode object response: %w", err)
}
return parsed, nil
}
func destructor(object RawPointer) error {
result, err := CallMethod(object, "~destructor", nil)
if err != nil {
return fmt.Errorf("failed to call destructor: %w", err)
}
if result != nil {
return fmt.Errorf("destructor returned unexpected result: %v", result)
}
return nil
}
View on GitHub (pinned to bd85ce9dee)
Solutions
- Read the wrapped %w message; it usually contains the actual native-side error text
- Verify all required constructor kwargs (e.g. media url/base64) are valid before calling
- Reinstall matching versions of the BAML native library and Go module
- If the message is 'decodeRawObjectImpl is not set', ensure the baml_go runtime was initialized before use
Defensive patterns
Strategy: validation
Validate before calling
if rt == nil { return fmt.Errorf("runtime required") } // and validate constructor kwargs (url/base64 non-empty) before calling Try / catch
parsed, err := b.NewTypeBuilder(rt)
if err != nil {
if strings.Contains(err.Error(), "failed to decode object response") {
return fmt.Errorf("native constructor rejected call: %w", err)
}
return err
} Prevention
- Validate all constructor arguments before calling
- Ensure the BAML Go runtime is fully initialized
- Match native library and Go module versions
When it happens
Trigger: NewRawObject invoked via NewCollector, NewTypeBuilder, or media constructors when the native constructor returns an InvocationResponse whose payload cannot be decoded (e.g. native-side error string, unknown object type, decodeRawObjectImpl not registered).
Common situations: Constructor rejected the arguments and returned an error payload; Go bindings initialized incorrectly (decode impl missing); object type enum mismatch between native lib and Go bindings.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- nil response
- failed to decode object at index %d: %w
- failed to decode object handle: %w
- Protobuf decode error: {0}
- Map entry missing key
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/ff66989a459e5964.
Report an issue: GitHub.