Skip to content

Python: BadRequestError: missing required parameter 'response_format.json_schema.name' when using Pydantic model in response_format for Structured Output #1842

@samueljohnsiby

Description

@samueljohnsiby

Using response_format Pydantic Model with AzureOpenAIAssistantsClient.create_agent raises:

openai.BadRequestError: code=400, message="missing required parameter: 'response_format.json_schema.name'"

Pydantic version : 2.12

Code:

from pydantic import BaseModel, Field
from azure.ai.openai import AzureOpenAIAssistantsClient
from azure.identity import DefaultAzureCredential

cred = DefaultAzureCredential()
deployment = "my-deployment"

client = AzureOpenAIAssistantsClient(credential=cred, deployment_name=deployment)

class RouterOutput(BaseModel):
    next: str = Field(..., description="which agent to route to")
    instruction: str = Field(..., description="what instruction to give")

agent = client.create_agent(
    name="router",
    description="Routes tasks to agents",
    instructions="Route to correct agent based on message intent",
    tools=[],
    response_format=RouterOutput,
    chat_message_store_factory=None,
)

response = agent.run("high metrics alert in vm")
print(response.text)

The call fails with the 400 error above.

Metadata

Metadata

Labels

model clientsIssues related to the model client implementationspython

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions