{"record":{"id":"6b7b89387d36337f","repo":"microsoft/semantic-kernel","slug":"invalid-role-authorrole","errorCode":null,"errorMessage":"Invalid role: {authorRole}","messagePattern":"Invalid role: (.+?)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/Bedrock/BedrockAgent.cs","lineNumber":596,"sourceCode":"        {\n            Role = this.MapBedrockAgentUser(chatMessageContent.Role),\n            Content = [new() { Text = chatMessageContent.Content }]\n        };\n    }\n\n    private Amazon.BedrockAgentRuntime.ConversationRole MapBedrockAgentUser(AuthorRole authorRole)\n    {\n        if (authorRole == AuthorRole.User)\n        {\n            return Amazon.BedrockAgentRuntime.ConversationRole.User;\n        }\n\n        if (authorRole == AuthorRole.Assistant)\n        {\n            return Amazon.BedrockAgentRuntime.ConversationRole.Assistant;\n        }\n\n        throw new ArgumentOutOfRangeException($\"Invalid role: {authorRole}\");\n    }\n\n    #endregion\n}\n","sourceCodeStart":578,"sourceCodeEnd":601,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/Bedrock/BedrockAgent.cs#L578-L601","documentation":"Thrown by MapBedrockAgentUser when an AuthorRole is neither User nor Assistant. Bedrock's ConversationRole only models User and Assistant, so any other role (System, Tool, Function, custom) cannot be mapped and ArgumentOutOfRangeException is thrown.","triggerScenarios":"Message history passed to the Bedrock channel contains a message with Role == AuthorRole.System (or Tool/Function/Custom). MapBedrockAgentUser is invoked for each history message and rejects unsupported roles.","commonSituations":"Caller forwarded a generic chat history (which commonly starts with a System message) into a Bedrock agent without filtering; tool-call result messages included; multi-provider code reused System prompts verbatim.","solutions":["Filter the message history to only User and Assistant roles before passing to the Bedrock agent.","Fold any system instructions into the Bedrock agent's instruction/session configuration instead of a System chat message.","Remove or convert Tool/Function role messages to User/Assistant before mapping."],"exampleFix":"// before\nvar history = new List<ChatMessageContent>\n{\n    new(AuthorRole.System, \"You are helpful.\"), // -> throws 178\n    new(AuthorRole.User, \"hi\"),\n};\n\n// after\nvar history = new List<ChatMessageContent>\n{\n    // system prompt configured on the Bedrock agent instead\n    new(AuthorRole.User, \"hi\"),\n};","handlingStrategy":"type-guard","validationCode":"var unsupported = history.Where(m => m.Role != AuthorRole.User && m.Role != AuthorRole.Assistant).ToList();\nif (unsupported.Count > 0)\n    throw new ArgumentOutOfRangeException($\"Bedrock only supports User/Assistant roles; found: {string.Join(\", \", unsupported.Select(m => m.Role))}\");","typeGuard":"static bool HistoryIsBedrockCompatible(IEnumerable<ChatMessageContent> h) =>\n    h.All(m => m.Role == AuthorRole.User || m.Role == AuthorRole.Assistant);","tryCatchPattern":"try { var role = MapBedrockAgentUser(role); }\ncatch (ArgumentOutOfRangeException) { /* drop or convert the unsupported-role message */ }","preventionTips":["Filter chat history to User/Assistant before passing to Bedrock.","Move system instructions into the Bedrock agent's instruction config, not a System message.","Convert or remove Tool/Function role messages for Bedrock channels."],"tags":["validation","bedrock","agent","role","precondition"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}