It seems that the schema generated by pydantic for models with datetime fields is not compatible with the schema validation with the new structured output:
python client example: (v1.40.6):
class JournalPublication(BaseModel):
publisher: str = Field(description="The publisher of the journal")
title: str = Field(description="The title of the article")
publication_date: datetime = Field(description="The date the article was published")
def test_response_format():
client = OpenAI()
try:
client.beta.chat.completions.parse(
model="gpt-4o-2024-08-06",
temperature=0,
messages=[
{"role": "user", "content": "When did Albert Einstein publish his discovery of Special Relativity?"}
],
response_format=JournalPublication
)
except BadRequestError as e:
schema = json.dumps(JournalPublication.model_json_schema(), indent=2)
logger.error("Unsupported JSON schema generated=%s", schema)
pytest.fail(f"Failed to parse response format: {e.message}")
Failed to parse response format: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'JournalPublication': In context=('properties', 'publication_date'), 'format' is not permitted", 'type': 'invalid_request_error', 'param': 'response_format', 'code': None}}
Generated Schema:
{
"properties": {
"publisher": {
"description": "The publisher of the journal",
"title": "Publisher",
"type": "string"
},
"title": {
"description": "The title of the article",
"title": "Title",
"type": "string"
},
"publication_date": {
"description": "The date the article was published",
"format": "date-time",
"title": "Publication Date",
"type": "string"
}
},
"required": [
"publisher",
"title",
"publication_date"
],
"title": "JournalPublication",
"type": "object"
}