class TestResponse(BaseModel):
todays_date: Optional[datetime.datetime]
completion = client.beta.chat.completions.parse(
model="gpt-4o-2024-08-06",
messages=[
dict(role="user", content="What is today's date?")
],
response_format=TestResponse
)
yields
openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'TestResponse': In context=('properties', 'todays_date', 'anyOf', '0'), 'format' is not permitted", 'type': 'invalid_request_error', 'param': 'response_format', 'code': None}}
Also fails with just dates
class TestResponse(BaseModel):
todays_date: Optional[datetime.date]
What’s the best way to handle this? If I hack the schema output and remove ‘format’ it works… but that doesn’t seem ideal.
Snake: 3.11
Pydantic: 2.7.2
OpenAI: 1.40.2