additionalProperties error when unpacking list of one pydantic object in Union

I kept getting additionalProperties error when using pydantic SDK object for response format: openai.BadRequestError: Error code: 400 - {‘error’: {‘message’: “Invalid schema for response_format ‘PlanDecision’: In context=(‘properties’, ‘Action_input’), ‘additionalProperties’ is required to be supplied and to be false.”, ‘type’: ‘invalid_request_error’, ‘param’: ‘response_format’, ‘code’: None}}.
Also this error only happened when trying to unpack a list of pydantic object inside an Union: Union[tuple(list)]. When the list has more than one elements I don’t get this error, only when the list has one element only do i get this error.
Anyone get the same problem? Any possible solution? I’m using python 3.10.12 and latest openai version.

1 Like

Hi @bachtruoq and welcome to the community!

Could you provide your Pydantic model so we can have a look? openai-python package automatically sets additionalProperties to false when you supply your Pydantic schema (e.g. see here), so it would be interesting to see where/why this happens.

I have actualy solved the problem using Optional[Union[tuple(list)]]

2 Likes