{"id":"bfedecbf661f92e3","repo":"python-poetry/poetry","slug":"invalid-template-variable-e-args-0-in-virtua","errorCode":null,"errorMessage":"Invalid template variable '{e.args[0]}' in 'virtualenvs.prompt' setting.\nValid variables are: {{project_name}}, {{python_version}}","messagePattern":"Invalid template variable '(.+?)' in 'virtualenvs\\.prompt' setting\\.\nValid variables are: (.+?)\\}, (.+?)\\}","errorType":"console","errorClass":"PoetryConsoleError","httpStatus":null,"severity":"error","filePath":"src/poetry/utils/env/env_manager.py","lineNumber":454,"sourceCode":"            )\n\n            python = Python.get_compatible_python(poetry=self._poetry, io=self._io)\n\n        if in_project_venv:\n            venv = venv_path\n        else:\n            name = self.generate_env_name(name, str(cwd))\n            name = f\"{name}-py{python.minor_version.to_string()}\"\n            venv = venv_path / name\n\n        if venv_prompt is not None:\n            try:\n                venv_prompt = venv_prompt.format(\n                    project_name=self._poetry.package.name or \"virtualenv\",\n                    python_version=python.minor_version.to_string(),\n                )\n            except KeyError as e:\n                raise PoetryConsoleError(\n                    f\"Invalid template variable '{e.args[0]}' in 'virtualenvs.prompt' setting.\\n\"\n                    f\"Valid variables are: {{project_name}}, {{python_version}}\"\n                ) from e\n            except ValueError as e:\n                raise PoetryConsoleError(\n                    f\"Invalid template string in 'virtualenvs.prompt' setting: {e}\"\n                ) from e\n\n        if not venv.is_dir():\n            if create_venv is False:\n                self._io.write_error_line(\n                    \"<fg=black;bg=yellow>\"\n                    \"Skipping virtualenv creation, \"\n                    \"as specified in config file.\"\n                    \"</>\"\n                )\n\n                return self.get_system_env()","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/utils/env/env_manager.py#L436-L472","documentation":"Raised as PoetryConsoleError in EnvManager.create_venv when formatting the virtualenvs.prompt config value raises a KeyError - i.e. the template string references a placeholder other than the two supported ones ({project_name} and {python_version}). Only those two variables are provided to str.format.","triggerScenarios":"Configuring 'virtualenvs.prompt' with a template like \"{name}-env\" or \"{py_version}\" (unsupported placeholder) via 'poetry config virtualenvs.prompt \"{name}\"', then triggering venv creation. KeyError caught at env_manager.py:448-457.","commonSituations":"User invents a placeholder name; copy-pastes a prompt template from another tool (e.g. starship) that uses different tokens; uses snake_case variants like {pythonVersion}.","solutions":["Use only the supported placeholders: {project_name} and {python_version}.","Reconfigure: 'poetry config virtualenvs.prompt \"{project_name}-py{python_version}\"'.","Reset to default: 'poetry config --unset virtualenvs.prompt'.","Check for stray braces that should be literal - escape them as {{ }}."],"exampleFix":"// before\npoetry config virtualenvs.prompt \"{name}-{py}\"\n# create_venv -> KeyError -> PoetryConsoleError\n\n// after\npoetry config virtualenvs.prompt \"{project_name}-{python_version}\"","handlingStrategy":"validation","validationCode":"import re\n\nALLOWED = {\"project_name\", \"python_version\"}\n\ndef prompt_template_ok(tpl: str) -> bool:\n    for m in re.finditer(r\"\\{([a-zA-Z_][a-zA-Z0-9_]*)\\}\", tpl):\n        if m.group(1) not in ALLOWED:\n            return False\n    return True\n\n# before setting config:\nassert prompt_template_ok(new_prompt), \"unsupported placeholder\"","typeGuard":"from poetry.console.exceptions import PoetryConsoleError\n\ndef is_invalid_prompt_variable(e: Exception) -> bool:\n    return isinstance(e, PoetryConsoleError) and \"Invalid template variable\" in str(e)","tryCatchPattern":"from poetry.console.exceptions import PoetryConsoleError\n\ntry:\n    manager.create_venv()\nexcept PoetryConsoleError as e:\n    if \"Invalid template variable\" in str(e):\n        # reset the misconfigured prompt and retry\n        run_cli([\"poetry\", \"config\", \"--unset\", \"virtualenvs.prompt\"])\n        manager.create_venv()\n    else:\n        raise","preventionTips":["Use only {project_name} and {python_version} in virtualenvs.prompt.","Validate the template with str.format(project_name='x', python_version='3.11') before saving.","Reset a misconfigured prompt with 'poetry config --unset virtualenvs.prompt'.","Escape literal braces as {{ and }}."],"tags":["config","virtualenvs-prompt","template","formatting"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}