iflytek/astron-agent · error · CustomException

CodeEnum.VARIABLE_PARSE_ERROR

CodeEnum.VARIABLE_PARSE_ERROR

Error message

Variable name: {key_name} parsing failed, reason: {str(e)}

What it means

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.

Solutions

  1. Fix the variable name syntax in the prompt template so it parses (balanced brackets, valid path segments)
  2. Log the inner exception reason (included in the message) to locate the offending token
  3. Validate variable references before rendering, e.g. with a regex or dry-run of the parser
  4. Escape or remove unsupported characters from variable names

Example fix

# before
prompt = "Hello {{user.name[}}"
# after
prompt = "Hello {{user.name[0]}}"
Defensive patterns

Strategy: try-catch

Validate before calling

import re
VAR_RE = re.compile(r'^[A-Za-z_][\w\-]*(\[[^\[\]]+\])*(\.[A-Za-z_][\w\-]*(\[[^\[\]]+\])*)*$')
assert VAR_RE.match(key_name), f"malformed variable name: {key_name}"

Try / catch

try:
    prompt = process_prompt(template, variable_pool, span)
except CustomException as e:
    if e.err_code == CodeEnum.VARIABLE_PARSE_ERROR:
        logger.error(f"bad variable reference: {e.err_msg}")
        prompt = template  # or fail fast per requirements

Prevention

When it happens

Trigger: 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.

Common situations: Hand-edited prompt templates with broken {{var}} references; variables containing characters the parser does not expect; copied templates from another workflow with unsupported syntax.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/fd7f978e47c568b7. Report an issue: GitHub.

Appendix: source

Thrown at core/workflow/engine/nodes/util/prompt.py:102

            try:
                last_part = (
                    variable_pool.get_variable(
                        node_id=node_id, key_name=arr_name, span=span
                    )
                    if index == 0
                    else last_part.get(arr_name)
                )
            except Exception:
                # User's key_name is incorrect and not found in variable pool
                return key_name
            last_part = (
                parse_nested_array(last_part, cur_part_key_name)
                if "[" in cur_part_key_name
                else last_part
            )
        return last_part
    except Exception as e:
        raise CustomException(
            err_code=CodeEnum.VARIABLE_PARSE_ERROR,
            err_msg=f"Variable name: {key_name} parsing failed, reason: {str(e)}",
        ) from e


def prompt_template_replace(
    input_identifier: list,
    _prompt_template: str,
    node_id: str,
    variable_pool: VariablePool,
    span_context: Span,
) -> str:
    """
    Replace variables in prompt template with their actual values.

    This function processes a prompt template by finding all variables,
    resolving their values from the variable pool, and replacing them
    in the template string.

View on GitHub (pinned to 5e758547a8)