@devries-cameron20 / composio Mirror · read-only / commits / cb84856a1
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.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 18:30 UTC

fix(openai-agents): preserve array item schemas (#3819)

## Summary Prevent the Python OpenAI Agents provider from rewriting valid JSON Schema array item definitions. - Stop adding `"type": "string"` when an `items` schema has no direct `type`. - Preserve item schemas using `anyOf`, `oneOf`, `$ref`, object constraints, or `{}`. - Continue removing `examples`, `pattern`, and `default` as before. - Add regression coverage for each affected schema shape. ## Problem The provider previously added `"type": "string"` to every array `items` object without a direct type declaration. That changes the meaning of valid JSON Schemas. For example: ```json { "anyOf": [ { "type": "object" }, { "type": "null" } ] } became: { "type": "string", "anyOf": [ { "type": "object" }, { "type": "null" } ] } Because both constraints apply, valid object and null values become impossible. This could expose misleading tool schemas to OpenAI Agents or cause correct tool arguments to be rejected. ## Testing - OpenAI Agents provider tests — 6 passed - OpenAI Agents type-inference tests — 5 passed - Mypy passed - Ruff lint and formatting passed - Schema-preservation smoke test passed Co-authored-by: GautamSharma99 <gautamsharme99067@gmail.com> Co-authored-by: Alberto Schiabel <jkomyno@users.noreply.github.com>

Gautam Sharma committed Jul 15, 2026 at 19:37 UTC cb84856a166864b70facc5848584f09c81da9831
2 files changed +67 -11
python/providers/openai_agents/composio_openai_agents/provider.py
+6 -11
@@ -13,11 +13,15 @@ from composio.utils.pydantic import parse_pydantic_error
13 from composio.utils.shared import normalize_tool_arguments
14
15
16 -# Recursively remove 'examples' keys from the schema properties
16 +# Recursively remove unsupported annotation/validation keys from schema properties.
17 def _remove_examples_from_schema(schema_obj: t.Dict[str, t.Any]) -> None:
18 """
19 Remove 'examples', 'pattern', and 'default' keys from all properties in the
20 - schema, including nested ones. Also ensure that any 'items' object has a 'type' key.
20 + schema, including nested ones.
21 +
22 + Array item schemas are otherwise preserved verbatim. JSON Schema permits
23 + ``items`` to use combiners, references, object keywords, or an empty schema
24 + without declaring a direct ``type``.
25 """
26 # Handle properties directly
27 if "properties" in schema_obj and isinstance(schema_obj["properties"], dict):
@@ -31,12 +35,6 @@ def _remove_examples_from_schema(schema_obj: t.Dict[str, t.Any]) -> None:
35 if "default" in prop_value:
36 del prop_value["default"]
37
34 - # Ensure 'items' has a 'type' key
35 - if "items" in prop_value and isinstance(prop_value["items"], dict):
36 - if "type" not in prop_value["items"]:
37 - # Default to string type for items if not specified
38 - prop_value["items"]["type"] = "string"
39 -
38 # Recursively process nested properties
39 _remove_examples_from_schema(prop_value)
40
@@ -48,9 +46,6 @@ def _remove_examples_from_schema(schema_obj: t.Dict[str, t.Any]) -> None:
46 del schema_obj["items"]["pattern"]
47 if "default" in schema_obj["items"]:
48 del schema_obj["items"]["default"]
51 - # Ensure items has a type
52 - if "type" not in schema_obj["items"]:
53 - schema_obj["items"]["type"] = "string"
49 _remove_examples_from_schema(schema_obj["items"])
50
51 # Handle any other nested object properties
python/providers/openai_agents/tests/test_provider.py
+61
@@ -3,6 +3,8 @@
3 import copy
4 from unittest.mock import MagicMock
5
6 +import pytest
7 +
8 from composio_openai_agents.provider import OpenAIAgentsProvider
9
10
@@ -49,3 +51,62 @@ def test_wrap_tool_does_not_mutate_input_parameters():
51 "required": ["owner"],
52 "additionalProperties": False,
53 }
54 +
55 +
56 +@pytest.mark.parametrize(
57 + "items_schema",
58 + [
59 + {
60 + "anyOf": [
61 + {
62 + "type": "object",
63 + "properties": {"id": {"type": "string"}},
64 + "required": ["id"],
65 + },
66 + {"type": "null"},
67 + ]
68 + },
69 + {
70 + "oneOf": [
71 + {"type": "integer"},
72 + {"type": "object", "additionalProperties": True},
73 + ]
74 + },
75 + {"$ref": "#/$defs/Entry"},
76 + {
77 + "properties": {"name": {"type": "string"}},
78 + "required": ["name"],
79 + },
80 + {},
81 + ],
82 + ids=["nullable-any-of", "one-of", "ref", "object-keywords", "empty-schema"],
83 +)
84 +def test_wrap_tool_preserves_array_item_schemas(items_schema):
85 + """Valid item schemas must not be intersected with an invented string type."""
86 + tool = MagicMock(
87 + slug="PROCESS_RECORDS",
88 + description="Process records",
89 + input_parameters={
90 + "type": "object",
91 + "$defs": {
92 + "Entry": {
93 + "type": "object",
94 + "properties": {"id": {"type": "string"}},
95 + }
96 + },
97 + "properties": {
98 + "records": {
99 + "type": "array",
100 + "items": copy.deepcopy(items_schema),
101 + }
102 + },
103 + "required": ["records"],
104 + },
105 + )
106 +
107 + wrapped_tool = OpenAIAgentsProvider().wrap_tool(tool, lambda **kwargs: {})
108 +
109 + assert (
110 + wrapped_tool.params_json_schema["properties"]["records"]["items"]
111 + == items_schema
112 + )