{"record":{"id":"091903db63a46d6d","repo":"microsoft/autogen","slug":"the-content-has-more-than-one-choice-please-try-a","errorCode":null,"errorMessage":"The content has more than one choice. Please try another input.","messagePattern":"The content has more than one choice\\. Please try another input\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs","lineNumber":164,"sourceCode":"        {\n            IMessage<ChatCompletion> m => PostProcessChatCompletions(m),\n            _ when strictMode is false => message,\n            _ => throw new InvalidOperationException($\"Invalid return message type {message.GetType().Name}\"),\n        };\n    }\n\n    private IMessage PostProcessChatCompletions(IMessage<ChatCompletion> message)\n    {\n        // throw exception if prompt filter results is not null\n        if (message.Content.FinishReason == ChatFinishReason.ContentFilter)\n        {\n            throw new InvalidOperationException(\"The content is filtered because its potential risk. Please try another input.\");\n        }\n\n        // throw exception is there is more than on choice\n        if (message.Content.Content.Count > 1)\n        {\n            throw new InvalidOperationException(\"The content has more than one choice. Please try another input.\");\n        }\n\n        return PostProcessChatResponseMessage(message.Content, message.From);\n    }\n\n    private IMessage PostProcessChatResponseMessage(ChatCompletion chatCompletion, string? from)\n    {\n        // throw exception if prompt filter results is not null\n        if (chatCompletion.FinishReason == ChatFinishReason.ContentFilter)\n        {\n            throw new InvalidOperationException(\"The content is filtered because its potential risk. Please try another input.\");\n        }\n\n        // throw exception is there is more than on choice\n        if (chatCompletion.Content.Count > 1)\n        {\n            throw new InvalidOperationException(\"The content has more than one choice. Please try another input.\");\n        }","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs#L146-L182","documentation":"Thrown by AutoGen.OpenAI's OpenAIChatRequestMessageConnector when post-processing a chat completion whose Content collection contains more than one entry. The connector maps a single completion choice into exactly one AutoGen IMessage, so a multi-part/multi-choice response cannot be represented. It is a guard against model or request configurations that produce multiple content parts.","triggerScenarios":"Calling an OpenAI agent whose ChatOptions.ChoiceCount (n) is set greater than 1, or a model/endpoint that returns a ChatCompletion with multiple items in Content. Raised inside PostProcessChatCompletions when message.Content.Content.Count > 1.","commonSituations":"Developer copies ChatOptions from a sample that sets ChoiceCount = 3 for A/B testing; using a custom endpoint/proxy that always returns multiple choices; upgrading to an SDK version where Content became a collection of parts and refactoring sent several parts.","solutions":["Set ChatOptions.ChoiceCount = 1 (or omit it) on the agent's reply options so the service returns a single choice.","Remove the OpenAIChatRequestMessageConnector middleware if you truly need raw multi-choice completions and process ChatCompletion yourself.","If multiple content parts come from a vision model, ensure the response contains one text part; inspect message.Content.Content in a debug hook to see what the service actually returned.","Catch InvalidOperationException around the agent call and retry with simplified input as a last resort."],"exampleFix":"// before\nvar chatOptions = new ChatOptions { ChoiceCount = 3 };\nawait agent.SendAsync(chatMessages, chatOptions);\n\n// after\nvar chatOptions = new ChatOptions { ChoiceCount = 1 };\nawait agent.SendAsync(chatMessages, chatOptions);","handlingStrategy":"validation","validationCode":"// Before invoking the agent, pin single-choice output\nif (chatOptions.ChoiceCount is > 1)\n{\n    throw new ArgumentOutOfRangeException(nameof(chatOptions), \"AutoGen.OpenAI message connector requires ChoiceCount == 1.\");\n}","typeGuard":null,"tryCatchPattern":"try { var reply = await agent.SendAsync(msgs, chatOptions); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"more than one choice\"))\n{\n    logger.LogError(ex, \"Multi-choice completion returned; set ChoiceCount=1\");\n    throw;\n}","preventionTips":["Default ChatOptions.ChoiceCount to 1 in agent factory code and assert it before every call.","Wrap ChatOptions creation in one helper so multi-choice configs cannot leak into AutoGen agents.","Add an integration test that round-trips one completion through the connector in CI."],"tags":["openai","chat-completions","autogen","csharp","configuration"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}