FoundationAgents/MetaGPT · error · ValueError
Cannot find the answer phrase "{response}"
Error message
Cannot find the answer phrase "{response}" What it means
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.
Source
Thrown at metagpt/utils/a11y_tree.py:174
except Exception as e:
raise ValueError("Element not found") from e
async def get_element_center(node_info):
x, y, width, height = node_info["x"], node_info["y"], node_info["width"], node_info["height"]
center_x = x + width / 2
center_y = y + height / 2
return center_x, center_y
def extract_step(response: str, action_splitter: str = "```") -> str:
# find the first occurence of action
pattern = rf"{action_splitter}((.|\n)*?){action_splitter}"
match = re.search(pattern, response)
if match:
return match.group(1).strip()
else:
raise ValueError(f'Cannot find the answer phrase "{response}"')
async def get_bounding_rect(cdp_session, backend_node_id: str):
try:
remote_object = await cdp_session.send("DOM.resolveNode", {"backendNodeId": int(backend_node_id)})
remote_object_id = remote_object["object"]["objectId"]
response = await cdp_session.send(
"Runtime.callFunctionOn",
{
"objectId": remote_object_id,
"functionDeclaration": """
function() {
if (this.nodeType == 3) {
var range = document.createRange();
range.selectNode(this);
var rect = range.getBoundingClientRect().toJSON();
range.detach();
return rect;View on GitHub (pinned to 11cdf466d0)
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.
Example fix
# before
step = extract_step('click [12]') # raises: no ``` block
# after
step = extract_step('```click [12]```') # -> 'click [12]' Defensive patterns
Strategy: validation
Validate before calling
def has_action_block(response: str, splitter: str = "```") -> bool:
return splitter in response Try / catch
try:
step = extract_step(response)
except ValueError:
# response malformed/truncated: re-ask the model, possibly with raised max_tokens Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not find content between [{tag}] and [/{tag}]
- Invalid python code
- Error while extracting and parsing the {data_type}: {e}
- Expecting property name enclosed in double quotes
- Expecting ':' delimiter
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/29f152730751bc9f.
Report an issue: GitHub.