From b8f3eb9d7f4c135dc7e72f6fefa809649df933bf Mon Sep 17 00:00:00 2001 From: Patrick Gray Date: Thu, 26 Jun 2025 12:18:52 +0000 Subject: [PATCH] tools - stop filter $defs --- src/strands/tools/decorator.py | 2 +- src/strands/tools/registry.py | 4 ++++ src/strands/tools/tools.py | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/strands/tools/decorator.py b/src/strands/tools/decorator.py index 3d579c3a0..33aa3dd6d 100644 --- a/src/strands/tools/decorator.py +++ b/src/strands/tools/decorator.py @@ -195,7 +195,7 @@ def _clean_pydantic_schema(self, schema: Dict[str, Any]) -> None: schema: The Pydantic-generated JSON schema to clean up (modified in place). """ # Remove Pydantic metadata - keys_to_remove = ["title", "$defs", "additionalProperties"] + keys_to_remove = ["title", "additionalProperties"] for key in keys_to_remove: if key in schema: del schema[key] diff --git a/src/strands/tools/registry.py b/src/strands/tools/registry.py index acaf6e368..5e335ff2b 100644 --- a/src/strands/tools/registry.py +++ b/src/strands/tools/registry.py @@ -538,6 +538,10 @@ def validate_tool_spec(self, tool_spec: ToolSpec) -> None: } continue + # It is expected that type and description are already included in referenced $def. + if "$ref" in prop_def: + continue + if "type" not in prop_def: prop_def["type"] = "string" if "description" not in prop_def: diff --git a/src/strands/tools/tools.py b/src/strands/tools/tools.py index 8dde1d09e..9047ad57b 100644 --- a/src/strands/tools/tools.py +++ b/src/strands/tools/tools.py @@ -81,6 +81,11 @@ def _normalize_property(prop_name: str, prop_def: Any) -> Dict[str, Any]: # Copy existing property, ensuring defaults normalized_prop = prop_def.copy() + + # It is expected that type and description are already included in referenced $def. + if "$ref" in normalized_prop: + return normalized_prop + normalized_prop.setdefault("type", "string") normalized_prop.setdefault("description", f"Property {prop_name}") return normalized_prop