{"record":{"id":"57cd45ee2283e08f","repo":"microsoft/semantic-kernel","slug":"invalid-role-role","errorCode":null,"errorMessage":"Invalid role: {role}","messagePattern":"Invalid role: (.+?)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.Amazon/Bedrock/Core/BedrockClientUtilities.cs","lineNumber":51,"sourceCode":"        }\n        // Any other status code is considered unset\n        return ActivityStatusCode.Unset;\n    }\n\n    /// <summary>\n    /// Map Conversation role (value) to author role to build message content for semantic kernel output.\n    /// </summary>\n    /// <param name=\"role\">The ConversationRole in string form to convert to AuthorRole</param>\n    /// <returns>The corresponding AuthorRole.</returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\">Thrown if invalid role</exception>\n    internal static AuthorRole MapConversationRoleToAuthorRole(string role)\n    {\n        return role.ToUpperInvariant() switch\n        {\n            \"USER\" => AuthorRole.User,\n            \"ASSISTANT\" => AuthorRole.Assistant,\n            \"SYSTEM\" => AuthorRole.System,\n            _ => throw new ArgumentOutOfRangeException(nameof(role), $\"Invalid role: {role}\")\n        };\n    }\n\n    internal static void BedrockServiceClientRequestHandler(object sender, RequestEventArgs e)\n    {\n        if (e is not WebServiceRequestEventArgs args || !args.Headers.TryGetValue(\"User-Agent\", out string? value) || value.Contains(HttpHeaderConstant.Values.UserAgent))\n        {\n            return;\n        }\n        args.Headers[\"User-Agent\"] = $\"{value} {HttpHeaderConstant.Values.UserAgent}\";\n        args.Headers[HttpHeaderConstant.Names.SemanticKernelVersion] = HttpHeaderConstant.Values.GetAssemblyVersion(typeof(BedrockClientUtilities));\n    }\n}\n","sourceCodeStart":33,"sourceCodeEnd":65,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.Amazon/Bedrock/Core/BedrockClientUtilities.cs#L33-L65","documentation":"BedrockClientUtilities.MapConversationRoleToAuthorRole converts a Bedrock ConversationRole string into a Semantic Kernel AuthorRole. It recognizes only USER, ASSISTANT, and SYSTEM (compared case-insensitively). Any other role string causes an ArgumentOutOfRangeException. This is an internal helper used while translating a Bedrock Converse response back into SK chat content.","triggerScenarios":"A Bedrock Converse API response returns a Message whose Role is something other than user/assistant/system (e.g. a newly introduced role, or an unexpected/tool role). The connector then calls MapConversationRoleToAuthorRole on that role string and throws.","commonSituations":"AWS adds a new ConversationRole value the installed connector version does not yet know. A custom/patched model response returns a non-standard role. Using an outdated Connectors.Amazon package against newer Bedrock response shapes.","solutions":["Upgrade the Microsoft.SemanticKernel.Connectors.Amazon package to a version that recognizes the role AWS is returning.","If the role comes from content you control, normalize the ConversationRole to user/assistant/system before it reaches the connector.","Wrap the high-level chat completion call (kernel.InvokePromptAsync / IChatCompletionService) in try/catch and surface the raw role for diagnosis."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var response = await bedrockChatCompletion.GetChatMessageContentAsync(chatHistory, settings, cancellationToken);\n}\ncatch (ArgumentOutOfRangeException ex) when (ex.Message.Contains(\"Invalid role\"))\n{\n    // The Bedrock response contained a role the connector does not recognize.\n    // Upgrade Connectors.Amazon, or inspect the raw Converse response for the new role.\n    logger.LogError(ex, \"Unrecognized Bedrock role in response. Upgrade the connector.\");\n    throw;\n}","preventionTips":["Keep Microsoft.SemanticKernel.Connectors.Amazon up to date so new AWS role values are mapped.","Do not inject non-standard role strings into Bedrock responses via custom serialization.","Log the raw role value when this fires so you can confirm whether AWS introduced a new role."],"tags":["csharp","dotnet","semantic-kernel","bedrock","aws","role-mapping"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}