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"])