Skip to content

Invalid schema for response_format 'ManagerSelectionResponse' #3049

@legendgokul

Description

@legendgokul

HI,

Current Setup : i have created multiple agents in AIFoundry with gpt4.1 model, each agent will have list of MCP apis attached to them under actions section

Error Info :
Error 1 :

Coordinator: {"selected_participant":"Agent1","instruction":"<instruction>","finish":false,"final_message":null}executor broke JSON is invalid: Expecting value: line 1 column 1 (char 0)

Error 2 : Coordinator/ manager agent JSON is getting duplicated as shown below

Coordinator: {"selected_participant":"<agentname>","instruction":"<instruction>","finish":false,"final_message":null}{"selected_participant":"<agentname>","instruction":"<instruction>","finish":false,"final_message":null}executor broke 1 validation error for ManagerSelectionResponse
  Invalid JSON: trailing characters at line 1 column 208 [type=json_invalid, input_value='{"selected_participant":...e,"final_message":null}', input_type=str]
   For further information visit https://errors.pydantic.dev/2.12/v/json_invalid

After which i came across below 2 link and i have tried what ever is suggest in those but the issue still exists.

  1. Python: agent_framework.exceptions.ServiceResponseException: <class 'agent_framework_azure_ai._client.AzureAIClient'> service failed to complete the prompt: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'ManagerSelectionResponse'.... #2681
  2. Python: fix: GroupChat ManagerSelectionResponse JSON Schema for OpenAI Structured Outpu… #2750

I have tried to provide strict agent instructions to not generate improper json and also tried providing additional_chat_options as shown below :

response_schema = {
            "title": "ManagerSelectionResponse",
            "type": "object",
            "description": "Response from manager agent with speaker selection decision.",
            "properties": {
                "selected_participant": {
                    "anyOf": [{"type": "string"}, {"type": "null"}],
                    "default": None,
                    "title": "Selected Participant",
                    "description": "Name of participant to speak next (None = finish conversation)",
                },
                "instruction": {
                    "anyOf": [{"type": "string"}, {"type": "null"}],
                    "default": None,
                    "title": "Instruction",
                    "description": "Optional instruction to provide to the selected participant",
                },
                "finish": {
                    "type": "boolean",
                    "default": False,
                    "title": "Finish",
                    "description": "Whether the conversation should be completed",
                },
                "final_message": {
                    "anyOf": [{"type": "string"}, {"type": "null"}],
                    "default": None,
                    "title": "Final Message",
                    "description": "Optional text content for final message",
                },
            },
            # OpenAI strict mode requires all properties to be in required array
            "required": ["selected_participant", "instruction", "finish", "final_message"],
            "additionalProperties": False,
        }

        managerAgent = ChatAgent(            
                chat_client= AzureAIAgentClient(
                    credential=credential,
                    project_endpoint = os.getenv("AZURE_PROJECT_ENDPOINT"),
                    model_deployment_name = os.getenv("AZURE_MODEL_DEPLOYMENT"),         
                    agent_id="<agent_id>"
                ),    
                name="Coordinator" ,
                additional_chat_options={
                "response_format": {
                    "type": "json_schema",
                    "json_schema": {
                        "name": response_schema["title"],
                        "strict": True,
                        "schema": response_schema,
                    },
                },
            }                     
        )

        
        workflow = (
                GroupChatBuilder()
                .set_manager(managerAgent, display_name="Orchestrator")
                .participants([<agent list>])  
                .build()
            )

I also noticed in above issue links they have utilized AzureOpenAIChatClient but in my project i have used AzureAIAgentClient.

Note :

  1. All the agents which are configured inside the workflow return basic string as output not JSON.
  2. i am doing async for event in workflow.run_stream(user_message): to obtain agent streaming output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions