{"record":{"id":"fd7f978e47c568b7","repo":"iflytek/astron-agent","slug":"codeenum-variable-parse-error","errorCode":"CodeEnum.VARIABLE_PARSE_ERROR","errorMessage":"Variable name: {key_name} parsing failed, reason: {str(e)}","messagePattern":"Variable name: (.+?) parsing failed, reason: (.+?)","errorType":"error_code","errorClass":"CustomException","httpStatus":null,"severity":"error","filePath":"core/workflow/engine/nodes/util/prompt.py","lineNumber":102,"sourceCode":"            try:\n                last_part = (\n                    variable_pool.get_variable(\n                        node_id=node_id, key_name=arr_name, span=span\n                    )\n                    if index == 0\n                    else last_part.get(arr_name)\n                )\n            except Exception:\n                # User's key_name is incorrect and not found in variable pool\n                return key_name\n            last_part = (\n                parse_nested_array(last_part, cur_part_key_name)\n                if \"[\" in cur_part_key_name\n                else last_part\n            )\n        return last_part\n    except Exception as e:\n        raise CustomException(\n            err_code=CodeEnum.VARIABLE_PARSE_ERROR,\n            err_msg=f\"Variable name: {key_name} parsing failed, reason: {str(e)}\",\n        ) from e\n\n\ndef prompt_template_replace(\n    input_identifier: list,\n    _prompt_template: str,\n    node_id: str,\n    variable_pool: VariablePool,\n    span_context: Span,\n) -> str:\n    \"\"\"\n    Replace variables in prompt template with their actual values.\n\n    This function processes a prompt template by finding all variables,\n    resolving their values from the variable pool, and replacing them\n    in the template string.","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/engine/nodes/util/prompt.py#L84-L120","documentation":"process_prompt parses variable references embedded in prompt strings (including nested array indexing like foo[0].bar). If any exception occurs while parsing the variable name syntax, it wraps the failure in a CustomException with CodeEnum.VARIABLE_PARSE_ERROR, preserving the original reason.","triggerScenarios":"Calling any of the callers (get_variable_from_vp, get_full_prompt, prompt_template_replace, etc.) with a malformed variable path in a prompt/variable-pool reference, e.g. 'a[', 'a[b]x.', or illegal bracket nesting.","commonSituations":"Hand-edited prompt templates with broken {{var}} references; variables containing characters the parser does not expect; copied templates from another workflow with unsupported syntax.","solutions":["Fix the variable name syntax in the prompt template so it parses (balanced brackets, valid path segments)","Log the inner exception reason (included in the message) to locate the offending token","Validate variable references before rendering, e.g. with a regex or dry-run of the parser","Escape or remove unsupported characters from variable names"],"exampleFix":"# before\nprompt = \"Hello {{user.name[}}\"\n# after\nprompt = \"Hello {{user.name[0]}}\"","handlingStrategy":"try-catch","validationCode":"import re\nVAR_RE = re.compile(r'^[A-Za-z_][\\w\\-]*(\\[[^\\[\\]]+\\])*(\\.[A-Za-z_][\\w\\-]*(\\[[^\\[\\]]+\\])*)*$')\nassert VAR_RE.match(key_name), f\"malformed variable name: {key_name}\"","typeGuard":null,"tryCatchPattern":"try:\n    prompt = process_prompt(template, variable_pool, span)\nexcept CustomException as e:\n    if e.err_code == CodeEnum.VARIABLE_PARSE_ERROR:\n        logger.error(f\"bad variable reference: {e.err_msg}\")\n        prompt = template  # or fail fast per requirements","preventionTips":["Use the workflow editor's variable picker rather than typing placeholders","Lint templates for balanced brackets before save","Validate variable paths with a dry parse at node configuration time","Keep variable names to simple identifier characters"],"tags":["parsing","variables","prompt-template"],"backgroundTag":"invalid-argument-format","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}