python-poetry/poetry · error · ValueError
Invalid layout
Error message
Invalid layout
What it means
Raised by poetry.layouts.layout() at src/poetry/layouts/__init__.py:11-12 when the requested layout name is not a key in _LAYOUTS, which only contains 'src' and 'standard'. ValueError. Used by `poetry new --name=...` and similar scaffolding commands.
Source
Thrown at src/poetry/layouts/__init__.py:12
from __future__ import annotations
from poetry.layouts.layout import Layout
from poetry.layouts.src import SrcLayout
_LAYOUTS = {"src": SrcLayout, "standard": Layout}
def layout(name: str) -> type[Layout]:
if name not in _LAYOUTS:
raise ValueError("Invalid layout")
return _LAYOUTS[name]
View on GitHub (pinned to 92b74dcfe3)
Solutions
- Use one of the supported names: 'src' or 'standard'.
- For a src-style project pass `poetry new --src mypkg`.
- If you need a custom layout, register it by extending the _LAYOUTS dict in your own code path before calling layout().
Example fix
# before $ poetry new --layout=masonry mypkg ValueError: Invalid layout # after $ poetry new --src mypkg # uses 'src' layout
Defensive patterns
Strategy: validation
Validate before calling
SUPPORTED_LAYOUTS = {'src', 'standard'}
def validate_layout(name: str) -> None:
if name not in SUPPORTED_LAYOUTS:
raise ValueError(f'Invalid layout {name!r}; choose from {sorted(SUPPORTED_LAYOUTS)}.') Type guard
def is_known_layout(name: str) -> bool:
return name in {'src', 'standard'} Try / catch
try:
layout_cls = layout(name)
except ValueError as e:
if 'Invalid layout' in str(e):
layout_cls = layout('standard') # safe fallback for scaffolding
raise Prevention
- Only request 'src' or 'standard' for `poetry new`.
- Pin your scaffolding choices in project templates.
When it happens
Trigger: Calling layout('masonry') or any name other than 'src'/'standard'. Reached via `poetry new --layout=X myproj` or `poetry new --src` (which selects 'src').
Common situations: Typo in the --layout flag, or assuming a custom layout is registered when it is not. Developers extending Poetry sometimes expect plugin layouts to be auto-registered.
Related errors
- Missing [url] in source {name!r}.
- Setting {self.argument('key')} does not exist
- You can only pass one value.
- "{value}" is an invalid value for {key}
- Group(s) not found: {', '.join(message_parts)}
AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04).
Data as JSON: /data/errors/d4297c1add866fb2.json.
Report an issue: GitHub.