Skip to content

fix: handle additionalProperties in json_schema_to_pydantic_type#3105

Open
hashwnath wants to merge 2 commits intoComposioHQ:nextfrom
hashwnath:fix/3087-additional-properties-handling
Open

fix: handle additionalProperties in json_schema_to_pydantic_type#3105
hashwnath wants to merge 2 commits intoComposioHQ:nextfrom
hashwnath:fix/3087-additional-properties-handling

Conversation

@hashwnath
Copy link
Copy Markdown

Summary

Fixes #3087

When a JSON schema defines an object with additionalProperties but no explicit properties (e.g. {"type": "object", "additionalProperties": {"type": "string"}}), json_schema_to_pydantic_type() delegates to create_model_from_schema() which generates an empty Pydantic model. This causes Pydantic to silently strip all fields during validation, resulting in empty objects like [{}] instead of the expected data.

This affects any tool in the catalog whose schema uses additionalProperties without explicit properties — including OUTLOOK_CALENDAR_CREATE_EVENT's attendees_info field.

Fix

Before delegating to create_model_from_schema(), check if the object schema has additionalProperties but no properties. In that case, map directly to Dict[str, value_type]:

Schema Before After
{"type": "object", "additionalProperties": {"type": "string"}} Empty model → {} Dict[str, str]
{"type": "object", "additionalProperties": {"type": "integer"}} Empty model → {} Dict[str, int]
{"type": "object", "additionalProperties": true} Empty model → {} Dict[str, Any]
{"type": "object", "properties": {...}} Unchanged Unchanged

Verification

Using the MRE from the issue:

from composio.utils.shared import json_schema_to_model

schema = {
    "type": "object",
    "title": "CreateEventRequest",
    "properties": {
        "attendees_info": {
            "type": "array",
            "items": {
                "type": "object",
                "additionalProperties": {"type": "string"}
            },
            "default": []
        }
    }
}

Model = json_schema_to_model(schema)
result = Model.model_validate({
    "attendees_info": [
        {"name": "John Doe", "type": "required", "email": "john@example.com"}
    ]
})
print(result.model_dump())
# Before: {'attendees_info': [{}]}
# After:  {'attendees_info': [{'name': 'John Doe', 'type': 'required', 'email': 'john@example.com'}]}

@hashwnath hashwnath requested a review from haxzie as a code owner April 2, 2026 07:52
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 2, 2026

@hashwnath is attempting to deploy a commit to the Composio Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

…trict model

When additionalProperties is false and no properties are defined, the
schema means "only empty objects are valid." Previously this returned
bare Dict (too permissive). Now it falls through to create_model_from_schema
which produces a strict Pydantic model that rejects extra fields.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Python SDK silently strips fields from attendees_info objects due to additionalProperties not being handled in json_schema_to_pydantic_type

1 participant