From 19e86a197a7cc3b2cdad3e9a019f269c365712f2 Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Wed, 23 Apr 2025 01:56:43 +0800 Subject: [PATCH] fix phone number format issue (#2217) --- .../skyvern/check-phone-number-format.j2 | 21 +++++++++++++------ skyvern/utils/prompt_engine.py | 6 ++++-- skyvern/webeye/actions/handler.py | 16 +++++++------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/skyvern/forge/prompts/skyvern/check-phone-number-format.j2 b/skyvern/forge/prompts/skyvern/check-phone-number-format.j2 index c4f3c0b9..ecc6319e 100644 --- a/skyvern/forge/prompts/skyvern/check-phone-number-format.j2 +++ b/skyvern/forge/prompts/skyvern/check-phone-number-format.j2 @@ -1,4 +1,6 @@ -You need to help checking if the current phone number format is matching the required format according to the user goal, user details and HTML elements. +You need to help checking two goals: +1. Based on the context/intention, check whether the current value is used to input as a phone number +2. If the current value is a phone number, check whether the format of the phone number matches the required format based on the user's goals, user details, and HTML elements. There are several checkpoints to verify the format of the phone number: - Whether the phone number should add hyphen. @@ -9,15 +11,22 @@ MAKE SURE YOU OUTPUT VALID JSON. No text before or after JSON, no trailing comma Reply in JSON format with the following keys: { -"phone_number_format": str, // Think step by step. The format of the phone number required on the page according to HTML elements. +"page_info": str, // Think step by step. Describe all the useful information in the page related to the user goal. +"is_phone_number_input": bool, // Think step by step. True if the current value is used to input as a phone number. "thought": str, // Think step by step. Describe your thought about how you come up with the phone_number_format. Use information you see on the site to explain. -"is_current_format_correct": bool, // True if the current phone number format is matching the required format. -"recommended_phone_number": str, // If is_current_format_correct is True, return null. Otherwise, return the recommended phone number with the correct format. +"phone_number_format": str, // Think step by step. The format of the phone number required on the page according to HTML elements. Null if is_phone_number_input is False. +"is_current_format_correct": bool, // True if the current phone number format is matching the required format. Null if is_phone_number_input is False. +"recommended_phone_number": str, // If is_current_format_correct is True or is_phone_number_input is False, return null. Otherwise, return the recommended phone number with the correct format. } -Current phone number: +Context/Intention ``` -{{ current_phone_number }} +{{ context }} +``` + +Current value: +``` +{{ current_value }} ``` User goal: diff --git a/skyvern/utils/prompt_engine.py b/skyvern/utils/prompt_engine.py index 5723777e..b2c68459 100644 --- a/skyvern/utils/prompt_engine.py +++ b/skyvern/utils/prompt_engine.py @@ -12,9 +12,11 @@ LOG = structlog.get_logger() class CheckPhoneNumberFormatResponse(BaseModel): - phone_number_format: str + page_info: str + is_phone_number_input: bool thought: str - is_current_format_correct: bool + phone_number_format: str | None + is_current_format_correct: bool | None recommended_phone_number: str | None diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.py index d7c6e2de..c6838630 100644 --- a/skyvern/webeye/actions/handler.py +++ b/skyvern/webeye/actions/handler.py @@ -242,7 +242,7 @@ def clean_and_remove_element_tree_factory( async def check_phone_number_format( - phone_number: str, + value: str, action: actions.InputTextAction, skyvern_element: SkyvernElement, scraped_page: ScrapedPage, @@ -260,7 +260,8 @@ async def check_phone_number_format( html = new_scraped_page.build_element_tree(html_need_skyvern_attrs=False) prompt = prompt_engine.load_prompt( template="check-phone-number-format", - current_phone_number=phone_number, + context=action.intention, + current_value=value, navigation_goal=task.navigation_goal, navigation_payload_str=json.dumps(task.navigation_payload), elements=html, @@ -273,10 +274,11 @@ async def check_phone_number_format( check_phone_number_format_response = CheckPhoneNumberFormatResponse.model_validate(json_response) if ( - check_phone_number_format_response.is_current_format_correct + not check_phone_number_format_response.is_phone_number_input + or check_phone_number_format_response.is_current_format_correct or not check_phone_number_format_response.recommended_phone_number ): - return phone_number + return value LOG.info( "The current phone number format is incorrect, using the recommended phone number", @@ -826,11 +828,11 @@ async def handle_input_text_action( # force to move focus back to the element await skyvern_element.get_locator().focus(timeout=timeout) - # check the phone number format - if await skyvern_element.get_attr("type") == "tel": + # check the phone number format when type=tel and the text is not a secret value + if await skyvern_element.get_attr("type") == "tel" and text == action.text: try: text = await check_phone_number_format( - phone_number=text, + value=text, action=action, skyvern_element=skyvern_element, scraped_page=scraped_page,