From 780f424642ee3d06819ef35a42b7a55a24ee6cb8 Mon Sep 17 00:00:00 2001 From: Edson Date: Fri, 17 Jul 2026 01:01:00 -0400 Subject: [PATCH] [python] Tolerate Java tool params without a description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit create_model_from_java_tool_schema_str read properties[name]["description"] directly, but Java's SchemaUtils.generateSchema only emits a "description" key when a @ToolParam has a non-empty description (ToolParam.description() defaults to ""). A description-less param — which the project's own tools produce, e.g. @ToolParam(name = "a") — therefore crashed the Python schema converter with KeyError: 'description'. Read it with .get() so the existing 'if description is None' fallback fabricates the default "Parameter: " description instead of crashing. Add a regression test covering a property with no description key. Closes #913 --- python/flink_agents/api/tools/tests/test_utils.py | 10 ++++++++++ python/flink_agents/api/tools/utils.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/python/flink_agents/api/tools/tests/test_utils.py b/python/flink_agents/api/tools/tests/test_utils.py index b1d01f094..a98ef9211 100644 --- a/python/flink_agents/api/tools/tests/test_utils.py +++ b/python/flink_agents/api/tools/tests/test_utils.py @@ -174,6 +174,16 @@ def test_model_from_java_schema_fields_are_required() -> None: assert field.is_required() +def test_model_from_java_schema_without_description() -> None: + # Java only emits a "description" key for a @ToolParam with a non-empty + # description (ToolParam.description() defaults to ""), so a param without + # one must be tolerated and fall back to a generated description. + schema_str = json.dumps({"properties": {"a": {"type": "number"}}}) + field = create_model_from_java_tool_schema_str("J", schema_str).model_fields["a"] + assert field.annotation is float + assert field.description == "Parameter: a" + + # ---- create_java_tool_schema_str_from_model ---------------------------------- diff --git a/python/flink_agents/api/tools/utils.py b/python/flink_agents/api/tools/utils.py index 79063950d..d3cf647bd 100644 --- a/python/flink_agents/api/tools/utils.py +++ b/python/flink_agents/api/tools/utils.py @@ -193,7 +193,7 @@ def create_model_from_java_tool_schema_str( fields = {} for param_name in properties: - description = properties[param_name]["description"] + description = properties[param_name].get("description") if description is None: description = f"Parameter: {param_name}" type = TYPE_MAPPING.get(properties[param_name]["type"])