@devries-cameron20 / composio-1 / commits / eb00a096d
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: use .get() for schema type/title access in pydantic_model_from_param_schema

Schemas for nested objects may use anyOf/allOf/oneOf/$ref instead of a top-level 'type' key. Direct dict access prop_info['type'] and prop_info['title'] would raise KeyError in those cases (e.g. Dropbox SEARCH_FILE_OR_FOLDER with an 'options' parameter). Changes: - prop_info['type'] -> prop_info.get('type') - prop_info['title'] -> prop_info.get('title', prop_name) - FALLBACK_VALUES[prop_type] -> FALLBACK_VALUES.get(prop_type) - When prop_type is None, delegate to json_schema_to_pydantic_type() which already handles all combiner schemas correctly Fixes #2459

Maxwell Calkin committed Mar 8, 2026 at 00:50 UTC eb00a096dc192280c4cedf525e570e045136c5ea
1 file changed +12 -5
python/composio/utils/shared.py
+12 -5
@@ -292,7 +292,6 @@ def pydantic_model_from_param_schema(param_schema: t.Dict) -> t.Type:
292 :param param_schema: Schema with 'title', 'properties', and optionally 'required' keys.
293 :return: A Pydantic model class for the defined schema.
294
295 - :raises KeyError: Missing 'type' in property definitions.
295 :raised ValueError: Invalid 'type' for property or recursive model creation.
296
297 Note: Requires global `schema_type_python_type_dict` for type mapping and
@@ -320,14 +319,22 @@ def pydantic_model_from_param_schema(param_schema: t.Dict) -> t.Type:
319 return t.List
320
321 for prop_name, prop_info in param_schema.get("properties", {}).items():
323 - prop_type = prop_info["type"]
324 - prop_title = prop_info["title"].replace(" ", "")
325 - prop_default = prop_info.get("default", FALLBACK_VALUES[prop_type])
322 + prop_type = prop_info.get("type")
323 + prop_title = prop_info.get("title", prop_name).replace(" ", "")
324 + prop_default = prop_info.get("default", FALLBACK_VALUES.get(prop_type))
325 if (
327 - prop_type in PYDANTIC_TYPE_TO_PYTHON_TYPE
326 + prop_type is not None
327 + and prop_type in PYDANTIC_TYPE_TO_PYTHON_TYPE
328 and prop_type not in CONTAINER_TYPE
329 ):
330 signature_prop_type = PYDANTIC_TYPE_TO_PYTHON_TYPE[prop_type]
331 + elif prop_type is None:
332 + # Schema uses anyOf/allOf/oneOf/$ref instead of a top-level "type" key.
333 + # Delegate to json_schema_to_pydantic_type which handles all combiners.
334 + signature_prop_type = t.cast(
335 + t.Type,
336 + json_schema_to_pydantic_type(json_schema=prop_info),
337 + )
338 else:
339 signature_prop_type = pydantic_model_from_param_schema(prop_info)
340