From 8deb1d938cd7259f908cd23c6781f68289bf0df2 Mon Sep 17 00:00:00 2001 From: Yashwant Bezawada Date: Fri, 7 Nov 2025 20:45:13 -0600 Subject: [PATCH] Fix Pydantic extra='allow' handling in strict JSON schema generation The to_strict_json_schema function was not properly handling Pydantic models with extra='allow'. It only set additionalProperties to false if the key didn't exist, but Pydantic models with extra='allow' generate schemas with additionalProperties=true. This causes the OpenAI API to reject the schema since structured outputs require additionalProperties to always be false. Changed the condition to always set additionalProperties=false for all object types, regardless of whether the key already exists in the schema. Fixes #2740 --- src/openai/lib/_pydantic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openai/lib/_pydantic.py b/src/openai/lib/_pydantic.py index 3cfe224cb1..2614184f24 100644 --- a/src/openai/lib/_pydantic.py +++ b/src/openai/lib/_pydantic.py @@ -47,7 +47,7 @@ def _ensure_strict_json_schema( _ensure_strict_json_schema(definition_schema, path=(*path, "definitions", definition_name), root=root) typ = json_schema.get("type") - if typ == "object" and "additionalProperties" not in json_schema: + if typ == "object": json_schema["additionalProperties"] = False # object types