python-poetry/poetry · error · PoetryConsoleError
Invalid template string in 'virtualenvs.prompt' setting: {e}
Error message
Invalid template string in 'virtualenvs.prompt' setting: {e} What it means
Raised as PoetryConsoleError in EnvManager.create_venv when formatting the virtualenvs.prompt config value raises a ValueError - i.e. the template string is structurally malformed for str.format, most commonly unbalanced curly braces.
Source
Thrown at src/poetry/utils/env/env_manager.py:459
venv = venv_path
else:
name = self.generate_env_name(name, str(cwd))
name = f"{name}-py{python.minor_version.to_string()}"
venv = venv_path / name
if venv_prompt is not None:
try:
venv_prompt = venv_prompt.format(
project_name=self._poetry.package.name or "virtualenv",
python_version=python.minor_version.to_string(),
)
except KeyError as e:
raise PoetryConsoleError(
f"Invalid template variable '{e.args[0]}' in 'virtualenvs.prompt' setting.\n"
f"Valid variables are: {{project_name}}, {{python_version}}"
) from e
except ValueError as e:
raise PoetryConsoleError(
f"Invalid template string in 'virtualenvs.prompt' setting: {e}"
) from e
if not venv.is_dir():
if create_venv is False:
self._io.write_error_line(
"<fg=black;bg=yellow>"
"Skipping virtualenv creation, "
"as specified in config file."
"</>"
)
return self.get_system_env()
if venv.is_file():
self._io.write_error_line(
f"<warning>{venv} is not a virtual environment but a file. Removing it.</warning>"
)View on GitHub (pinned to 92b74dcfe3)
Solutions
- Balance the braces or escape literal ones: use {{ for a literal '{' and }} for '}'.
- Reconfigure with a well-formed template: 'poetry config virtualenvs.prompt "({project_name})"'.
- Reset to default: 'poetry config --unset virtualenvs.prompt'.
- Validate the string with Python first: '"...".format(project_name="x", python_version="3.11")'.
Example fix
// before
poetry config virtualenvs.prompt "{project_name"
# ValueError: unmatched brace -> PoetryConsoleError
// after
poetry config virtualenvs.prompt "{project_name}-py{python_version}" Defensive patterns
Strategy: validation
Validate before calling
def prompt_template_parses(tpl: str) -> bool:
try:
tpl.format(project_name="x", python_version="3.11")
return True
except (KeyError, ValueError):
return False
# before setting config:
assert prompt_template_parses(new_prompt), "malformed template string" Type guard
from poetry.console.exceptions import PoetryConsoleError
def is_invalid_prompt_string(e: Exception) -> bool:
return isinstance(e, PoetryConsoleError) and "Invalid template string" in str(e) Try / catch
from poetry.console.exceptions import PoetryConsoleError
try:
manager.create_venv()
except PoetryConsoleError as e:
if "Invalid template string" in str(e):
run_cli(["poetry", "config", "--unset", "virtualenvs.prompt"])
manager.create_venv()
else:
raise Prevention
- Balance all braces in the prompt template; escape literals as {{ }}.
- Test the template with Python's str.format before configuring it.
- Keep the template simple: '{project_name}-py{python_version}' covers most needs.
- Reset with 'poetry config --unset virtualenvs.prompt' if unsure.
When it happens
Trigger: Configuring 'virtualenvs.prompt' with a string containing an odd number of braces, e.g. "{project_name" (missing close) or a lone '}' - anything str.format rejects with ValueError. Caught at env_manager.py:458-461.
Common situations: User wants a literal brace in the prompt but forgets to escape it as {{ or }}; truncation/copy-paste drops a brace; a config file edit leaves an unterminated placeholder.
Related errors
- Invalid template variable '{e.args[0]}' in 'virtualenvs.prom
- Key {'.'.join(keys)} not in config
- Key {'.'.join(keys)} not in config
- You must pass exactly 1 value
- Invalid build config setting '{value}'. It must be a valid J
AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04).
Data as JSON: /data/errors/03ba3ecfbde5820f.json.
Report an issue: GitHub.