BoundaryML/baml · error
failed to get raw LLM response: %w
Error message
failed to get raw LLM response: %w
What it means
This error wraps any failure from raw_objects.CallMethod when RawLLMResponse() fetches the 'raw_llm_response' attribute of a FunctionLog via the C FFI. It is a pass-through wrapper: the actionable cause (empty FFI response buffer, nil pointer, proto unmarshal failure, or object-response decode failure) lives in the wrapped error. It means the Go client could not retrieve the raw LLM response text from the runtime object.
Source
Thrown at engine/language_client_go/pkg/rawobjects_function_log.go:100
func (f *functionLog) Usage() (Usage, error) {
result, err := raw_objects.CallMethod(f, "usage", nil)
if err != nil {
return nil, fmt.Errorf("failed to get usage: %w", err)
}
usage, ok := result.(Usage)
if !ok {
return nil, fmt.Errorf("unexpected type for usage: %T", result)
}
return usage, nil
}
func (f *functionLog) RawLLMResponse() (string, error) {
result, err := raw_objects.CallMethod(f, "raw_llm_response", nil)
if err != nil {
return "", fmt.Errorf("failed to get raw LLM response: %w", err)
}
response, ok := result.(string)
if !ok {
return "", fmt.Errorf("unexpected type for raw LLM response: %T", result)
}
return response, nil
}
func (f *functionLog) CallsCount() (int, error) {
result, err := raw_objects.CallMethod(f, "calls_count", nil)
if err != nil {
return 0, fmt.Errorf("failed to get calls count: %w", err)
}
count, ok := result.(int)
if !ok {View on GitHub (pinned to bd85ce9dee)
Solutions
- Unwrap the error (errors.Unwrap / %w chain) to see the concrete FFI failure ('failed to call object method function', 'nil pointer', decode failure).
- Read RawLLMResponse() within the lifetime of the owning function call/stream.
- Keep the generated Go client in sync with the BAML runtime (re-run `baml generate`).
- If the wrapped error is an unmarshal/decode failure on a live object, report it upstream with your versions.
Defensive patterns
Strategy: try-catch
Validate before calling
if fnLog == nil {
return errors.New("function log is nil; cannot read RawLLMResponse")
} Type guard
func isCallMethodFailure(err error) bool {
return strings.Contains(err.Error(), "failed to call object method")
} Try / catch
raw, err := fnLog.RawLLMResponse()
if err != nil {
log.Printf("RawLLMResponse unavailable: %v (wrapped: %v)", err, errors.Unwrap(err))
return fmt.Errorf("baml raw LLM response inaccessible: %w", err)
} Prevention
- Unwrap this error to reach the concrete FFI cause.
- Fetch the raw response before the function stream completes.
- Regenerate the client after any BAML runtime upgrade.
- Do not cache functionLog references beyond the request scope.
When it happens
Trigger: Calling RawLLMResponse() on a functionLog whose runtime object was freed or is invalid; the FFI method call returned an empty buffer or nil pointer; the protobuf response failed to unmarshal/decode.
Common situations: Reading raw responses after a stream completed and objects were reclaimed; caching log references in long-running services; Go client vs BAML runtime version mismatch.
Related errors
- failed to get function name: %w
- failed to get log type: %w
- failed to get timing: %w
- failed to get usage: %w
- %s
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/6006f4498465c70a.
Report an issue: GitHub.