Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(python): handle title-less top-level schemas (#3325)
MatinGathanid5a37efb8560
diff --git a/python/composio/utils/shared.py b/python/composio/utils/shared.pyindex 9fc194383..15b1e2237 100644--- a/python/composio/utils/shared.py+++ b/python/composio/utils/shared.py@@ -446,6 +446,8 @@ def json_schema_to_model(:return: Pydantic `BaseModel` type"""model_name = json_schema.get("title")+ if model_name is None:+ model_name = "GeneratedModel"field_definitions = {}for name, prop in json_schema.get("properties", {}).items():updated_name, pydantic_type, pydantic_field = json_schema_to_pydantic_field(diff --git a/python/tests/test_schema_parser.py b/python/tests/test_schema_parser.pyindex f751d0d6f..2046b674b 100644--- a/python/tests/test_schema_parser.py+++ b/python/tests/test_schema_parser.py@@ -8,7 +8,7 @@ particularly focusing on the required field propagation bug that was fixed.import typing as timport pytest-from pydantic import BaseModel+from pydantic import BaseModel, ValidationErrorfrom pydantic.fields import PydanticUndefinedfrom composio.utils.shared import (@@ -323,6 +323,35 @@ class TestJsonSchemaToModel:instance = model_class(tags=["tag1", "tag2"])assert instance.tags == ["tag1", "tag2"]+ @pytest.mark.parametrize(+ ("title", "expected_model_name"),+ [+ ({}, "GeneratedModel"),+ ({"title": None}, "GeneratedModel"),+ ({"title": ""}, ""),+ ],+ )+ def test_title_uses_expected_model_name(self, title, expected_model_name):+ """Missing or null titles must not reach Pydantic's model factory."""+ json_schema = {+ **title,+ "type": "object",+ "properties": {+ "name": {"type": "string"},+ "value": {"type": "integer"},+ },+ "required": ["name"],+ }++ model_class = json_schema_to_model(json_schema)+ assert model_class.__name__ == expected_model_name+ instance = model_class(name="test", value=42)+ assert instance.name == "test"+ assert instance.value == 42++ with pytest.raises(ValidationError):+ model_class()+class TestPydanticModelFromParamSchema:"""Test cases for pydantic_model_from_param_schema function."""