openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Unable to create json schema assistants in async

Open jmesich opened this issue 1 year ago • 5 comments

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • [X] This is an issue with the Python library

Describe the bug

When I try to create a json schema assistant, I get this error "error": "Error code: 400 - {'error': {'message': \"Missing required parameter: 'response_format.json_schema.schema'. You provided 'schema_', did you mean to provide 'schema'?\", 'type': 'invalid_request_error', 'param': 'response_format.json_schema.schema', 'code': 'missing_required_parameter'}}"

When I go into the response_format_json_schema.py file and update JSONSchema.schema_ to JSONSchema.schema, the problem disappears.

To Reproduce

Call openai.AsyncOpenAI().beta.assistants.create with a response_format parameter

Code snippets

await openai.AsyncOpenAI().beta.assistants.create(
            model=assistant.model,
            description=assistant.description,
            instructions=assistant.instructions,
            name=assistant.name,
            response_format=assistant.response_format,
            temperature=assistant.temperature,
            tool_resources=assistant.tool_resources,
            tools=assistant.tools,
            top_p=assistant.top_p,
)

OS

MacOS Sonoma 14.6.1

Python version

Python v3.12.2

Library version

openai v1.54.4

Pydantic Version

2.9.2

jmesich avatar Nov 15 '24 19:11 jmesich

To address this issue, you can modify the library's source code to ensure that schema_ is correctly serialized as schema in the API request. This involves updating the serialization logic within the response_format_json_schema.py file. By changing the attribute from schema_ to schema, the API will recognize the parameter, resolving the error.

Dhruv-net avatar Nov 23 '24 19:11 Dhruv-net

Hi @Dhruv-net, thank you for your response but I have already mentioned that fix in my description above and I do not wish to fork the repo for my deployments!

jmesich avatar Nov 25 '24 14:11 jmesich

Thanks for the report, are you using pydantic v1?

RobertCraigie avatar Jan 17 '25 11:01 RobertCraigie

Hi Robert! Thanks for your question, I'm using pydantic version 2.9.2. Ill add it to the ticket for visibility as well.

jmesich avatar Jan 22 '25 13:01 jmesich

Would you be able to provide a minimally reproducible example snippet? Unfortunately I can't reproduce this.

RobertCraigie avatar Feb 17 '25 11:02 RobertCraigie

I encountered the same error and fixed it by importing another library with the same name.

  • Before: from openai.types import ResponseFormatJSONSchema
  • After: from openai.types.shared_params import ResponseFormatJSONSchema

Hope this will help you.

BusungKim avatar Apr 25 '25 01:04 BusungKim

Closing as I can't reproduce. Please re-open if you have more context.

RobertCraigie avatar Jul 10 '25 10:07 RobertCraigie