{"record":{"id":"48101f81484808ef","repo":"BoundaryML/baml","slug":"unexpected-type-for-raw-llm-response-t","errorCode":null,"errorMessage":"unexpected type for raw LLM response: %T","messagePattern":"unexpected type for raw LLM response: %T","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_function_log.go","lineNumber":105,"sourceCode":"\t}\n\n\tusage, ok := result.(Usage)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for usage: %T\", result)\n\t}\n\n\treturn usage, nil\n}\n\nfunc (f *functionLog) RawLLMResponse() (string, error) {\n\tresult, err := raw_objects.CallMethod(f, \"raw_llm_response\", nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get raw LLM response: %w\", err)\n\t}\n\n\tresponse, ok := result.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type for raw LLM response: %T\", result)\n\t}\n\n\treturn response, nil\n}\n\nfunc (f *functionLog) CallsCount() (int, error) {\n\tresult, err := raw_objects.CallMethod(f, \"calls_count\", nil)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to get calls count: %w\", err)\n\t}\n\n\tcount, ok := result.(int)\n\tif !ok {\n\t\treturn 0, fmt.Errorf(\"unexpected type for calls count: %T\", result)\n\t}\n\n\treturn count, nil\n}","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_function_log.go#L87-L123","documentation":"RawLLMResponse() retrieves the raw LLM response text for a function log via the language runtime bridge (raw_objects.CallMethod). If the bridge call itself fails it wraps that error; if the bridge returns a value that is not a Go string, it rejects it with 'unexpected type for raw LLM response: %T'. This guards the boundary between the host runtime and Go, where the remote object's return type cannot be statically checked.","triggerScenarios":"Calling FunctionLog.RawLLMResponse() when the underlying raw object's 'raw_response' method returns a non-string (e.g. nil, []byte, or a wrapper pointer) because the runtime method failed or returned a different type than expected.","commonSituations":"Runtime bridge version drift between the Go bindings and the target runtime; the LLM response being unset/None in the runtime so the bridge hands back nil; custom runtimes returning wrapped objects instead of plain strings.","solutions":["Inspect the %T in the error message to identify the actual type returned by the bridge","Verify the runtime objects library (raw_objects) and target runtime versions match the Go binding expectations","Check that the function log actually recorded an LLM response before calling RawLLMResponse","If a known wrapper/byte-slice type is returned, add an explicit conversion before the assertion"],"exampleFix":"// before\nresponse, ok := result.(string)\nif !ok {\n    return \"\", fmt.Errorf(\"unexpected type for raw LLM response: %T\", result)\n}\n// after\nswitch v := result.(type) {\ncase string:\n    return v, nil\ncase []byte:\n    return string(v), nil\ndefault:\n    return \"\", fmt.Errorf(\"unexpected type for raw LLM response: %T\", result)\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func asString(v any) (string, bool) {\n    s, ok := v.(string)\n    return s, ok\n}","tryCatchPattern":"resp, err := flog.RawLLMResponse()\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for raw LLM response\") {\n        // fall back to Calls()/SelectedCall() data or skip this log\n        return nil, fmt.Errorf(\"bridge returned non-string response: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Keep the language runtime and Go bindings on matching versions","Check that a raw LLM response exists before calling RawLLMResponse","Log the %T from the error when it occurs to report binding bugs precisely"],"tags":["go","type-assertion","rpc","llm"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}