{"record":{"id":"29f152730751bc9f","repo":"FoundationAgents/MetaGPT","slug":"cannot-find-the-answer-phrase-response","errorCode":null,"errorMessage":"Cannot find the answer phrase \"{response}\"","messagePattern":"Cannot find the answer phrase \"(.+?)\"","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/utils/a11y_tree.py","lineNumber":174,"sourceCode":"    except Exception as e:\n        raise ValueError(\"Element not found\") from e\n\n\nasync def get_element_center(node_info):\n    x, y, width, height = node_info[\"x\"], node_info[\"y\"], node_info[\"width\"], node_info[\"height\"]\n    center_x = x + width / 2\n    center_y = y + height / 2\n    return center_x, center_y\n\n\ndef extract_step(response: str, action_splitter: str = \"```\") -> str:\n    # find the first occurence of action\n    pattern = rf\"{action_splitter}((.|\\n)*?){action_splitter}\"\n    match = re.search(pattern, response)\n    if match:\n        return match.group(1).strip()\n    else:\n        raise ValueError(f'Cannot find the answer phrase \"{response}\"')\n\n\nasync def get_bounding_rect(cdp_session, backend_node_id: str):\n    try:\n        remote_object = await cdp_session.send(\"DOM.resolveNode\", {\"backendNodeId\": int(backend_node_id)})\n        remote_object_id = remote_object[\"object\"][\"objectId\"]\n        response = await cdp_session.send(\n            \"Runtime.callFunctionOn\",\n            {\n                \"objectId\": remote_object_id,\n                \"functionDeclaration\": \"\"\"\n                    function() {\n                        if (this.nodeType == 3) {\n                            var range = document.createRange();\n                            range.selectNode(this);\n                            var rect = range.getBoundingClientRect().toJSON();\n                            range.detach();\n                            return rect;","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/utils/a11y_tree.py#L156-L192","documentation":"extract_step in metagpt/utils/a11y_tree.py pulls the action out of an LLM response by searching for the first pair of action_splitter fences (default '```'). If the response contains no fenced block, the regex finds nothing and this ValueError fires with the full response embedded in the message.","triggerScenarios":"extract_step('click [12]') — action sent without ``` fences; response truncated by token limits before the closing fence; model wrapping the action in single backticks or quotes; custom action_splitter that never appears in the response.","commonSituations":"LLM omits the markdown fence, answers in prose ('I would click...'), or gets cut off mid-action by max_tokens. Also occurs when the caller passes a raw action string directly instead of a full model response.","solutions":["Ensure the LLM response contains the action between triple-backtick fences, e.g. '```click [12]```'.","If the response was truncated, increase max_tokens or reduce prompt size so the fenced block completes.","Make the prompt explicitly require the fence delimiters around the action.","If you already have a bare action string, skip extract_step and pass it straight to execute_action."],"exampleFix":"# before\nstep = extract_step('click [12]')  # raises: no ``` block\n\n# after\nstep = extract_step('```click [12]```')  # -> 'click [12]'","handlingStrategy":"validation","validationCode":"def has_action_block(response: str, splitter: str = \"```\") -> bool:\n    return splitter in response","typeGuard":null,"tryCatchPattern":"try:\n    step = extract_step(response)\nexcept ValueError:\n    # response malformed/truncated: re-ask the model, possibly with raised max_tokens","preventionTips":["Require fence delimiters around actions in the prompt.","Check for an unclosed fence to detect truncation before parsing.","Set max_tokens generously enough for the full fenced action."],"tags":["metagpt","llm-output","parsing","markdown","truncation"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}