Fix structured output object selector conversion for OpenAI (#150916)

This commit is contained in:
Paulus Schoutsen
2025-08-19 22:17:30 +02:00
committed by GitHub
parent 8d30d69af5
commit e68df66028
2 changed files with 4 additions and 2 deletions

View File

@@ -92,6 +92,8 @@ MAX_TOOL_ITERATIONS = 10
def _adjust_schema(schema: dict[str, Any]) -> None:
"""Adjust the schema to be compatible with OpenAI API."""
if schema["type"] == "object":
schema.setdefault("strict", True)
schema.setdefault("additionalProperties", False)
if "properties" not in schema:
return
@@ -125,8 +127,6 @@ def _format_structured_output(
_adjust_schema(result)
result["strict"] = True
result["additionalProperties"] = False
return result

View File

@@ -63,6 +63,8 @@ async def test_format_structured_output() -> None:
"item_value",
],
"type": "object",
"additionalProperties": False,
"strict": True,
},
"type": "array",
},