4-o function calling doesn't work by return : Structured output is not allowed.

Yicli 5 Reputation points
2024-10-10T06:42:38.3+00:00

I trie to follow the structure out of 4-o https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/structured-outputs?tabs=python-secure

And I meet this error {'message': 'Structured output is not allowed.', 'type': 'invalid_request_error', 'param': None, 'code': None} even when I use the example code.

from pydantic import BaseModel
import openai
from openai import AzureOpenAI

client = AzureOpenAI(
  azure_endpoint=GPT4o_DEPLOYMENT_ENDPOINT,
  api_key=GPT4o_API_KEY,
  api_version="2024-08-01-preview"
)


class CalendarEvent(BaseModel):
    name: str
    date: str
    participants: list[str]

completion = client.beta.chat.completions.parse(
    model="gpt-4o-noah", # replace with the model deployment name of your gpt-4o 2024-08-06 deployment
    messages=[
        {"role": "system", "content": "Extract the event information."},
        {"role": "user", "content": "Alice and Bob are going to a science fair on Friday."},
    ],
    response_format=CalendarEvent,
)

event = completion.choices[0].message.parsed

print(event)
print(completion.model_dump_json(indent=2))

openai.BadRequestError: Error code: 400 - {'error': {'message': 'Structured output is not allowed.', 'type': 'invalid_request_error', 'param': None, 'code': None}}

What's wrong and how can I fix it?

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,258 questions
{count} vote

1 answer

Sort by: Most helpful
  1. AshokPeddakotla-MSFT 34,861 Reputation points
    2024-10-10T09:20:18.5833333+00:00

    Yicli I'm glad that your issue is resolved and thank you for posting your solution so that others experiencing the same thing can easily reference this!

    Since the Microsoft Q&A community has a policy that the question author cannot accept their own answer, they can only accept answers by others, I'll repost your solution in case you'd like to Accept the answer.

    Error Message:

    I trie to follow the structure out of 4-o https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/structured-outputs?tabs=python-secure

    And I meet this error {'message': 'Structured output is not allowed.', 'type': 'invalid_request_error', 'param': None, 'code': None} even when I use the example code.

    Solution:

    I just deploy a new model as the old. And it works again.

    I think I can simply use the new one

    If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.