diff --git a/homeassistant/components/openai_conversation/entity.py b/homeassistant/components/openai_conversation/entity.py index 9c1e77be7d3..64439c8a9c1 100644 --- a/homeassistant/components/openai_conversation/entity.py +++ b/homeassistant/components/openai_conversation/entity.py @@ -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 diff --git a/tests/components/openai_conversation/test_entity.py b/tests/components/openai_conversation/test_entity.py index 58187bd63e9..c24cb5b3d79 100644 --- a/tests/components/openai_conversation/test_entity.py +++ b/tests/components/openai_conversation/test_entity.py @@ -63,6 +63,8 @@ async def test_format_structured_output() -> None: "item_value", ], "type": "object", + "additionalProperties": False, + "strict": True, }, "type": "array", },