{"record":{"id":"4762ce60945a94a6","repo":"iflytek/astron-agent","slug":"key-key-does-not-exist","errorCode":null,"errorMessage":"key {key} does not exist","messagePattern":"key (.+?) does not exist","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"core/workflow/engine/entities/variable_pool.py","lineNumber":95,"sourceCode":"    :param first_only: If True, extract only the first element for array object types\n    :return: Extracted value based on key navigation\n    \"\"\"\n    mapping_value: Any = content\n    mapping_schema: dict = cast(dict, schemas)  # Ensure not None\n    key_type: str = mapping_schema.get(\"type\", \"\")\n    key_i = 0\n    for key in key_list:\n        if key_i == 0:\n            key_i += 1\n            continue\n        mapping_schema = cast(dict, mapping_schema)\n        if key_type == \"array\":\n            mapping_schema = cast(dict, mapping_schema.get(\"items\", {}))\n            array_type = mapping_schema.get(\"type\")\n            if array_type == \"object\":\n                mapping_schema = cast(dict, mapping_schema.get(\"properties\", {}))\n                if key not in mapping_schema:\n                    raise Exception(f\"key {key} does not exist\")\n                mapping_schema = cast(dict, mapping_schema[key])\n                key_type = mapping_schema.get(\"type\", \"\")\n\n                mapping_value = cast(list, mapping_value)\n                if first_only:\n                    if mapping_value:\n                        mapping_value = mapping_value[0].get(\n                            key, schema_type_default_value.get(key_type)\n                        )\n                    else:\n                        mapping_value = schema_type_default_value.get(key_type)\n                else:\n                    return [\n                        iteration_array(\n                            value.get(key, schema_type_default_value.get(key_type)),\n                            mapping_schema,\n                            key_list[key_i:],\n                            first_only=first_only,","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/engine/entities/variable_pool.py#L77-L113","documentation":"VariablePool.iteration_array resolves iteration array mappings; when the mapping schema describes an array of objects, it looks up the requested key in the object's properties schema and raises Exception('key {key} does not exist') if absent. This ensures only keys declared in the object item schema can be extracted during iteration, failing fast on schema/reference mismatches.","triggerScenarios":"Requesting iteration_array for an object-typed array variable with a key that is not declared in that array's items.properties mapping schema — e.g. iterating over records and reading a field that was never defined in the variable's schema.","commonSituations":"Renaming an object field in an upstream node (LLM/code output) while iteration nodes still reference the old field name; schema inferred from a first record that lacks the field; hand-edited variable mapping schemas missing the key.","solutions":["Add the missing key to the array variable's items.properties schema in the variable mapping","Update the iteration node to reference an existing field name from the schema","Ensure the upstream node that produces the array declares all fields its consumers read (stabilize output schema)","Validate mapping schemas at build time so key mismatches surface before execution"],"exampleFix":"// before: reading 'userName' but schema only declares 'name'\n{\"items\": {\"type\": \"object\", \"properties\": {\"name\": {\"type\": \"string\"}}}}\n// after: align key or schema\n{\"items\": {\"type\": \"object\", \"properties\": {\"name\": {\"type\": \"string\"}, \"userName\": {\"type\": \"string\"}}}}","handlingStrategy":"validation","validationCode":"def key_in_array_schema(mapping_schema, key):\n    items = mapping_schema.get(\"items\", {})\n    if items.get(\"type\") == \"object\":\n        return key in items.get(\"properties\", {})\n    return True","typeGuard":"def can_extract_key(mapping_schema, key) -> bool:\n    props = mapping_schema.get(\"items\", {}).get(\"properties\", {})\n    return key in props","tryCatchPattern":"try:\n    arr = pool.iteration_array(key=field, mapping_schema=schema, ...)\nexcept Exception as e:\n    if str(e).startswith(\"key \") and \"does not exist\" in str(e):\n        # fix field name or extend items.properties schema, then retry\n        ...\n    raise","preventionTips":["Stabilize upstream node output schemas so consumer fields always exist","Update iteration nodes whenever an object field is renamed","Validate variable mapping schemas at workflow build time"],"tags":["variable-pool","iteration","schema","key"],"backgroundTag":"invalid-identifier","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}