{"record":{"id":"ce84de86a47f16d4","repo":"BoundaryML/baml","slug":"unexpected-type-for-text-t-rawobjects-sse-response","errorCode":null,"errorMessage":"unexpected type for text: %T","messagePattern":"unexpected type for text: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_sse_response.go","lineNumber":35,"sourceCode":"}\n\nfunc (s *sseResponse) ObjectType() cffi.BamlObjectType {\n\treturn cffi.BamlObjectType_OBJECT_SSE_RESPONSE\n}\n\nfunc (s *sseResponse) pointer() int64 {\n\treturn s.RawObject.Pointer()\n}\n\nfunc (s *sseResponse) Text() (string, error) {\n\tresult, err := raw_objects.CallMethod(s, \"text\", nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get text: %w\", err)\n\t}\n\n\ttext, ok := result.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type for text: %T\", result)\n\t}\n\n\treturn text, nil\n}\n\nfunc (s *sseResponse) JSON() (any, error) {\n\tresult, err := raw_objects.CallMethod(s, \"json\", nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get JSON: %w\", err)\n\t}\n\n\treturn result, nil\n}\n","sourceCodeStart":17,"sourceCodeEnd":49,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_sse_response.go#L17-L49","documentation":"sseResponse.Text() calls the underlying FFI object's \"text\" method via raw_objects.CallMethod and asserts the returned any is a Go string. When the cross-language bridge returns a value that is not a string, the assertion fails and this error is thrown. It indicates the raw object backing the SSEResponse did not yield text of the expected type, usually due to a version mismatch between the Go bindings and the native BAML runtime or an internal bridge bug.","triggerScenarios":"Calling Text() on an SSEResponse whose underlying \"text\" FFI method returns a non-string value (e.g. nil, []byte, or a wrapped object) instead of a Go string.","commonSituations":"Using a baml_go Go binding version that does not match the installed native BAML runtime; the FFI decoder returns a differently-typed payload (e.g. []byte instead of string); a streaming SSE event carries non-text payload that the bridge mis-decodes.","solutions":["Check that the baml Go module version exactly matches your BAML CLI/native runtime version (go.mod vs `baml version`) and upgrade both together.","Print the offending type with errors like `unexpected type for text: %T` to identify what the bridge actually returned, then file/inspect the raw_objects.CallMethod decoder for that type.","If the SSE payload may be non-text, prefer JSON() over Text() and decode yourself.","Update the baml dependency (`go get -u github.com/boundaryml/baml/...`) to pick up FFI type-decoding fixes."],"exampleFix":"// before\ntext, err := sseResp.Text()\nif err != nil {\n    return err\n}\n\n// after: fall back to JSON when text decoding fails\ntext, err := sseResp.Text()\nif err != nil {\n    var anyResp any\n    anyResp, err = sseResp.JSON()\n    if err != nil {\n        return err\n    }\n    _ = anyResp\n}","handlingStrategy":"try-catch","validationCode":"if sseResp == nil {\n    return errors.New(\"sse response is nil\")\n}","typeGuard":"func isString(v any) bool { _, ok := v.(string); return ok }","tryCatchPattern":"text, err := sseResp.Text()\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for text\") {\n        log.Printf(\"non-string SSE payload, falling back to JSON: %v\", err)\n        return sseResp.JSON()\n    }\n    return fmt.Errorf(\"sse text: %w\", err)\n}","preventionTips":["Pin the baml Go module version to the exact native BAML runtime version you deploy.","Prefer JSON() when the SSE payload type is uncertain.","Check `baml version` against go.mod after every upgrade."],"tags":["go","ffi","type-mismatch","sse"],"backgroundTag":"unexpected-response-shape","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"}