@devries-cameron20 / composio-1 / commits / d5a37efb8
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(python): handle title-less top-level schemas (#3325)

## Summary Fixes `json_schema_to_model` when a top-level JSON schema omits `title` or sets it to `null`. This is the remaining direct-helper path; anonymous nested objects from #2435 are already handled by `schema_converter.py`. - falls back to `GeneratedModel` only when the title is `None`, preserving intentionally empty string titles - adds regression coverage for missing, `null`, and empty titles, model construction, and required-field validation ## Validation - `ruff format --check python/composio/utils/shared.py python/tests/test_schema_parser.py` - `ruff check python/composio/utils/shared.py python/tests/test_schema_parser.py` - `PYTHONPATH="$PWD/python" /Users/jkomyno/work/composio/composio2/.venv/bin/pytest -q python/tests/test_schema_parser.py` This is a follow-up to #2435; it intentionally does not close that already-resolved issue. Co-authored-by: jkomyno <alberto@composio.dev> Co-authored-by: Alberto Schiabel <jkomyno@users.noreply.github.com>

MatinGathani committed Jul 13, 2026 at 15:31 UTC d5a37efb856083db377be9781d2e83eac7bedbbf
2 files changed +32 -1
python/composio/utils/shared.py
+2
@@ -446,6 +446,8 @@ def json_schema_to_model(
446 :return: Pydantic `BaseModel` type
447 """
448 model_name = json_schema.get("title")
449 + if model_name is None:
450 + model_name = "GeneratedModel"
451 field_definitions = {}
452 for name, prop in json_schema.get("properties", {}).items():
453 updated_name, pydantic_type, pydantic_field = json_schema_to_pydantic_field(
python/tests/test_schema_parser.py
+30 -1
@@ -8,7 +8,7 @@ particularly focusing on the required field propagation bug that was fixed.
8 import typing as t
9
10 import pytest
11 -from pydantic import BaseModel
11 +from pydantic import BaseModel, ValidationError
12 from pydantic.fields import PydanticUndefined
13
14 from composio.utils.shared import (
@@ -323,6 +323,35 @@ class TestJsonSchemaToModel:
323 instance = model_class(tags=["tag1", "tag2"])
324 assert instance.tags == ["tag1", "tag2"]
325
326 + @pytest.mark.parametrize(
327 + ("title", "expected_model_name"),
328 + [
329 + ({}, "GeneratedModel"),
330 + ({"title": None}, "GeneratedModel"),
331 + ({"title": ""}, ""),
332 + ],
333 + )
334 + def test_title_uses_expected_model_name(self, title, expected_model_name):
335 + """Missing or null titles must not reach Pydantic's model factory."""
336 + json_schema = {
337 + **title,
338 + "type": "object",
339 + "properties": {
340 + "name": {"type": "string"},
341 + "value": {"type": "integer"},
342 + },
343 + "required": ["name"],
344 + }
345 +
346 + model_class = json_schema_to_model(json_schema)
347 + assert model_class.__name__ == expected_model_name
348 + instance = model_class(name="test", value=42)
349 + assert instance.name == "test"
350 + assert instance.value == 42
351 +
352 + with pytest.raises(ValidationError):
353 + model_class()
354 +
355
356 class TestPydanticModelFromParamSchema:
357 """Test cases for pydantic_model_from_param_schema function."""