You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Invalid Schema Error when Using examples Field in Pydantic Model for OpenAI Python Client #2274
Confirm this is an issue with the Python library and not an underlying OpenAI API
This is an issue with the Python library
Describe the bug
When you add the examples field in the Field definition of a Pydantic model (as shown in the code below) while using the OpenAI Python client, it raises a BadRequestError with error code 400. The error message indicates that the examples field is not permitted in the schema for the response_format parameter.
This is the error message:
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400- {'error': {'message': "Invalid schema for response_format 'MathReasoning': In context=('properties', 'final_answer'), 'examples' is not permitted.",'type': 'invalid_request_error','param': 'response_format','code': None}}
Question:
Is this behavior due to a limitation in the OpenAI Python client or API, or is it something that could potentially be patched in the future?
To Reproduce
fromopenaiimportClientfrompydanticimportBaseModel, Fieldfromdotenvimportload_dotenvload_dotenv()
client=Client()
classStep(BaseModel):
explanation: stroutput: strclassMathReasoning(BaseModel):
steps: list[Step]
final_answer: str=Field(
title="Final Answer",
description="The final answer to the math problem",
examples=["x = -3", "x = 2"]
)
completion=client.beta.chat.completions.parse(
model="gpt-4o-2024-08-06",
messages=[
{"role": "system", "content": "You are a helpful math tutor. Guide the user through the solution step by step."},
{"role": "user", "content": "how can I solve 8x + 7 = -23"}
],
response_format=MathReasoning,
)
math_reasoning=completion.choices[0].message# If the model refuses to respond, you will get a refusal messageif (math_reasoning.refusal):
print(math_reasoning.refusal)
else:
print(math_reasoning.parsed)
Thanks for reporting this! There have been several API and SDK updates since this was opened, so we’re closing it for now. If this is still affecting you, please retry with the latest SDK and share a minimal reproduction. We’re happy to reopen and take another look.
Activity
AnneMayor commentedon Apr 5, 2025
I am also curious if this issue should be resolved or not. If this issue should be handled, I would like to open PR for this issue.
Fix Invalid Schema Error by stripping unsupported keywords (e.g., `ex…
marcuswood-oai commentedon Oct 23, 2026
Thanks for reporting this! There have been several API and SDK updates since this was opened, so we’re closing it for now. If this is still affecting you, please retry with the latest SDK and share a minimal reproduction. We’re happy to reopen and take another look.