Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions openhands-sdk/openhands/sdk/tool/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ def _process_schema_node(
# Handle anyOf (often used for optional fields with None)
if "anyOf" in node:
non_null_types = [
t
for t in node["anyOf"]
if not isinstance(t, dict) or t.get("type") != "null"
t for t in node["anyOf"] if isinstance(t, dict) and t.get("type") != "null"
]
if non_null_types:
# Process the first non-null type
Expand Down
22 changes: 22 additions & 0 deletions tests/sdk/tool/test_mcp_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,25 @@ def test_boolean_schema_nodes_are_normalized(node, expected):

assert result == expected
json.dumps(result)


def test_anyof_with_false_does_not_clobber_concrete_type():
"""A ``false`` member in ``anyOf`` must not become the representative type.

JSON Schema ``false`` means "reject everything." When it appears as one
branch of an ``anyOf`` alongside a concrete type (common in schemas emitted
by TypeScript/MCP servers), the processor must pick the concrete type, not
``false``. Previously the filter ``not isinstance(t, dict)`` treated
``False`` as a non-null type, so ``_process_schema_node(False)`` returned
``{"not": {}}`` — making the parameter impossible for the LLM to satisfy.
"""
schema = {
"type": "object",
"properties": {
"value": {
"anyOf": [False, {"type": "string"}],
},
},
}
result = _process_schema_node(schema, {})
assert result["properties"]["value"] == {"type": "string"}
Loading