diff --git a/python/semantic_kernel/prompt_template/utils/handlebars_system_helpers.py b/python/semantic_kernel/prompt_template/utils/handlebars_system_helpers.py index ea60447f2cb9..6919b8c1a297 100644 --- a/python/semantic_kernel/prompt_template/utils/handlebars_system_helpers.py +++ b/python/semantic_kernel/prompt_template/utils/handlebars_system_helpers.py @@ -74,13 +74,16 @@ def _array(this, *args, **kwargs): def _range(this, *args, **kwargs): - args = list(args) - for index, arg in enumerate(args): - if not isinstance(arg, int): + converted = [] + for arg in args: + if isinstance(arg, int): + converted.append(arg) + else: try: - args[index] = int(arg) - except ValueError: - args.pop(index) + converted.append(int(arg)) + except (ValueError, TypeError): + continue + args = converted if len(args) == 1: return list(range(args[0])) if len(args) == 2: diff --git a/python/tests/unit/prompt_template/test_handlebars_prompt_template.py b/python/tests/unit/prompt_template/test_handlebars_prompt_template.py index 6efea53f50c7..2b120d438d78 100644 --- a/python/tests/unit/prompt_template/test_handlebars_prompt_template.py +++ b/python/tests/unit/prompt_template/test_handlebars_prompt_template.py @@ -140,6 +140,7 @@ async def test_it_renders_kernel_functions_arg_from_arguments(kernel: Kernel, de ("range", "0 5 2", "[0, 2, 4]"), ("range", "0 5 1 1", "[]"), ("range", "'a' 5", "[0, 1, 2, 3, 4]"), + ("range", "'a' 'b' 5", "[0, 1, 2, 3, 4]"), ("concat", "'test1' 'test2' 'test3'", "test1test2test3"), ("or", "true false", "true"), ("add", "1 2", "3.0"),