{"id":"594da91abb77a4fc","repo":"python-poetry/poetry","slug":"invalid-package-definition","errorCode":null,"errorMessage":"Invalid package definition.","messagePattern":"Invalid package definition\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/poetry/console/commands/init.py","lineNumber":520,"sourceCode":"\n        author = combine_unicode(author or default)\n\n        if author in [\"n\", \"no\"]:\n            return None\n\n        m = AUTHOR_REGEX.match(author)\n        if not m:\n            raise ValueError(\n                \"Invalid author string. Must be in the format: \"\n                \"John Smith <john@example.com>\"\n            )\n\n        return author\n\n    @staticmethod\n    def _validate_package(package: str | None) -> str | None:\n        if package and len(package.split()) > 2:\n            raise ValueError(\"Invalid package definition.\")\n\n        return package\n\n    @staticmethod\n    def _validate_version_constraint(constraint: str | None) -> str | None:\n        from poetry.core.constraints.version import parse_constraint\n\n        constraint = (constraint or \"\").strip()\n        if not constraint:\n            return None\n\n        try:\n            parse_constraint(constraint)\n        except ValueError as e:\n            raise ValueError(f\"Invalid version constraint: {constraint}\") from e\n\n        return constraint\n","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/console/commands/init.py#L502-L538","documentation":"ValueError from `_validate_package` (init.py:518-520) when the package requirement string splits into more than two whitespace tokens. A valid requirement is either `name` (1 token) or `name version` (2 tokens); three or more is treated as malformed.","triggerScenarios":"Entering `requests >= 2.28` (with a space between operator and version, yielding 3 tokens); pasting `requests extras security`.","commonSituations":"PEP 508 syntax (`requests[security]>=2.28`) being split on whitespace; users expecting to add extras in this prompt.","solutions":["Provide just the package name and let init resolve the version, or use `name version` with no internal spaces.","Keep operator and version together: `requests>=2.28` rather than `requests >= 2.28`.","Add extras later via `poetry add 'requests[security]'`."],"exampleFix":"# before\nrequests >= 2.28\n# after\nrequests>=2.28","handlingStrategy":"validation","validationCode":"req = \"requests>=2.28\"\nif len(req.split()) > 2:\n    raise SystemExit(\"use 'name' or 'name version' with no internal spaces\")","typeGuard":"def is_valid_package_string(value: str | None) -> bool:\n    return not value or len(value.split()) <= 2","tryCatchPattern":null,"preventionTips":["Keep operator and version adjacent (`>=2.28`, not `>= 2.28`).","Use PEP 508 form `name[extra]` without spaces.","Defer extras to `poetry add`."],"tags":["init","dependencies","validation"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}