{"record":{"id":"f93c157a9132a344","repo":"microsoft/autogen","slug":"expand-scenario-expects-an-str-or-list-for-templa","errorCode":null,"errorMessage":"expand_scenario expects an str or list for 'template'","messagePattern":"expand_scenario expects an str or list for 'template'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/agbench/src/agbench/run_cmd.py","lineNumber":215,"sourceCode":"        substitutions = {\"scenario.py\": cast(Dict[str, str], substitutions)}\n\n    copy_operations: List[Tuple[str, str]] = []\n\n    # Handle file (str), folder (str), or mapping (List) templates\n    if isinstance(template, str):\n        template_path = os.path.join(scenario_dir, template)\n        if os.path.isdir(template_path):\n            copy_operations.append((template, \"\"))\n        else:\n            copy_operations.append((template, \"scenario.py\"))\n    elif isinstance(template, list):\n        for elm in template:\n            if isinstance(elm, list):\n                copy_operations.append((elm[0], elm[1]))\n            else:\n                copy_operations.append((elm, \"\"))\n    else:\n        raise ValueError(\"expand_scenario expects an str or list for 'template'\")\n\n    # The global includes folder is always copied\n    shutil.copytree(\n        BASE_TEMPLATE_PATH,\n        output_dir,\n        ignore=shutil.ignore_patterns(\"*.example\"),\n        dirs_exist_ok=False,\n    )\n\n    # Expand other folders\n    for items in copy_operations:\n        src_path = pathlib.Path(os.path.join(scenario_dir, items[0])).absolute()\n        dest_path = pathlib.Path(os.path.join(output_dir, items[1])).absolute()\n\n        if os.path.isdir(src_path):\n            shutil.copytree(src_path, dest_path, dirs_exist_ok=True)\n        else:\n            if os.path.isdir(dest_path):","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/agbench/src/agbench/run_cmd.py#L197-L233","documentation":"Raised in agbench's scenario expansion when the 'template' field of a scenario is neither a string nor a list. The expander handles str (a file or directory path within the scenario dir) and list (of [source, dest] pairs or plain strings); any other JSON type (number, object, bool, null-as-non-None) is rejected with ValueError.","triggerScenarios":"A .jsonl scenario line whose \"template\" field is, e.g., a JSON object {\"path\": ...} or a number, or a template element list whose items are nested structures not of the form [str, str].","commonSituations":"Hand-editing scenario JSONL and using an object form from different tooling docs, YAML->JSON conversion producing unexpected types, or schema drift between scenario format versions.","solutions":["Set \"template\" to a string path relative to the scenario dir, e.g. \"coding\" or \"scenario.py\".","Or use a list form: [\"dir_or_file\", ...] or [[\"src\", \"dest\"], ...].","Validate the scenario JSON against the expected schema before running (jsonschema or a quick isinstance check)."],"exampleFix":"// before\n{\"name\": \"bench\", \"template\": {\"path\": \"scenario.py\"}}\n\n// after\n{\"name\": \"bench\", \"template\": \"scenario.py\"}","handlingStrategy":"validation","validationCode":"import json\ntemplate = scenario.get(\"template\")\nif not isinstance(template, (str, list)):\n    raise ValueError(f\"scenario '{scenario.get('name')}': 'template' must be str or list, got {type(template).__name__}\")","typeGuard":"def is_valid_template(t) -> bool:\n    if isinstance(t, str):\n        return True\n    if isinstance(t, list):\n        return all(isinstance(x, str) or (isinstance(x, list) and len(x) == 2 and all(isinstance(i, str) for i in x)) for x in t)\n    return False","tryCatchPattern":"try:\n    expand_scenario(...)\nexcept ValueError as e:\n    if \"expects an str or list\" in str(e):\n        fix_scenario_template_and_rerun()\n    else:\n        raise","preventionTips":["Lint every scenario JSONL line against the template schema before batch runs.","Keep scenario examples in-repo and diff new scenarios against them."],"tags":["json","schema","scenario","validation","agbench"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}