{"record":{"id":"fd6c457ae4e171e3","repo":"BoundaryML/baml","slug":"unexpected-type-for-headers-t","errorCode":null,"errorMessage":"unexpected type for headers: %T","messagePattern":"unexpected type for headers: %T","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_http_request.go","lineNumber":77,"sourceCode":"\t}\n\n\tmethod, ok := result.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type for method: %T\", result)\n\t}\n\n\treturn method, nil\n}\n\nfunc (h *httpRequest) Headers() (map[string]string, error) {\n\tresult, err := raw_objects.CallMethod(h, \"headers\", nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get headers: %w\", err)\n\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}","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_http_request.go#L59-L95","documentation":"httpRequest.Headers() expects the runtime 'headers' method to yield a Go map[string]string. 'unexpected type for headers: %T' means the bridge returned a different type — commonly map[string][]string (multi-value headers) or nil.","triggerScenarios":"The runtime stores headers as multi-value maps, objects with non-string values (numbers/arrays), or returns nil when no headers exist.","commonSituations":"Runtime representing headers as map[string]interface{}; headers containing repeated keys or non-string values (Content-Length numbers); cross-version representation changes.","solutions":["Check %T in the message; if it is map[string][]string, adapt at the boundary before this API or convert","Fix the runtime to flatten header values to strings","Treat nil headers as an empty map on the caller side","Align client and runtime versions"],"exampleFix":"// before\nheaders, err := req.Headers()\nif err != nil { return err }\n// after\nif h, ok := rawHeaders.(map[string][]string); ok {\n    flat := map[string]string{}\n    for k, vs := range h { if len(vs) > 0 { flat[k] = vs[0] } }\n    headers = flat\n}","handlingStrategy":"type-guard","validationCode":"hs, err := req.Headers()\nif err == nil && hs == nil { hs = map[string]string{} }","typeGuard":"func asStringMap(v any) (map[string]string, bool) {\n    switch t := v.(type) {\n    case map[string]string:\n        return t, true\n    case map[string][]string:\n        m := map[string]string{}\n        for k, vs := range t { if len(vs) > 0 { m[k] = vs[0] } }\n        return m, true\n    }\n    return nil, false\n}","tryCatchPattern":"hs, err := req.Headers()\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type\") {\n        return fmt.Errorf(\"header representation changed: %w\", err)\n    }\n    return err\n}","preventionTips":["Normalize runtime headers to map[string]string before exposing them","Test with multi-value and non-string header values","Keep header representation stable across versions"],"tags":["go","type-mismatch","http-headers"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}