{"record":{"id":"554081284ddb0ff9","repo":"BoundaryML/baml","slug":"unexpected-type-for-body-t","errorCode":null,"errorMessage":"unexpected type for body: %T","messagePattern":"unexpected type for body: %T","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_http_request.go","lineNumber":91,"sourceCode":"\t}\n\n\theaders, ok := result.(map[string]string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for headers: %T\", result)\n\t}\n\n\treturn headers, nil\n}\n\nfunc (h *httpRequest) Body() (HTTPBody, error) {\n\tresult, err := raw_objects.CallMethod(h, \"body\", nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get body: %w\", err)\n\t}\n\n\tbody, ok := result.(HTTPBody)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for body: %T\", result)\n\t}\n\n\treturn body, nil\n}\n","sourceCodeStart":73,"sourceCodeEnd":96,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_http_request.go#L73-L96","documentation":"Thrown by HTTPRequest.Body() in BAML's Go client when the raw object returned by the FFI CallMethod(\"body\") call cannot be asserted to the HTTPBody interface. It means the body payload decoded from the Rust core arrived as an unexpected Go type (%T names the actual type), indicating a version mismatch or corrupted/unsupported body encoding between the BAML core and the Go bindings.","triggerScenarios":"Calling baml HTTPRequest.Body() on a request object obtained from event logs or LLMCall.HttpRequest() when the underlying CFFI-decoded result is not registered as an HTTPBody implementation — e.g. the body was decoded as a generic RawObject or nil-typed wrapper instead of an httpBody.","commonSituations":"Mixed BAML Go-binding versions where the Go module is older/newer than the installed baml core library; reading event-log objects after a core upgrade changed body encoding; body objects whose type tag isn't recognized by the decoder.","solutions":["Upgrade the Go bindings (engine/language_client_go) and the BAML core library to matching versions with 'go get -u github.com/boundaryml/baml/...'","Print %T from the error message and check which concrete type arrived; inspect pkg/cffi decoders for a missing case","Regenerate/refresh the baml generated client for your project so the core and bindings agree on object types","If persistent, report the %T value to the BAML maintainers since it indicates an unhandled decoder path"],"exampleFix":"// before: blindly using the body\nbody, err := req.Body() // errors with unexpected type\n\n// after: guard and surface the actual type\nbody, err := req.Body()\nif err != nil {\n    log.Printf(\"body unavailable: %v\", err) // %T reveals the real type\n    return err\n}","handlingStrategy":"type-guard","validationCode":"if req == nil { return errors.New(\"nil HTTPRequest\") }","typeGuard":"func safeBody(req baml.HTTPRequest) (baml.HTTPBody, error) {\n    b, err := req.Body()\n    if err != nil {\n        return nil, fmt.Errorf(\"body guard: %w\", err)\n    }\n    return b, nil\n}","tryCatchPattern":"body, err := req.Body()\nif err != nil {\n    var te *baml.UnexpectedTypeError // if exposed\n    if errors.As(err, &te) { log.Printf(\"decoded type: see %T in message\", err) }\n    return fmt.Errorf(\"http body decode failed: %w\", err)\n}","preventionTips":["Keep the Go bindings and BAML engine on the same release","Never cache raw HTTPRequest handles across runtime lifetimes","Treat event-log body reads as optional and always check err before use"],"tags":["go","type-assertion","ffi","baml"],"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"}