crewAIInc/crewAI · error · ValueError
Project name '{name}' contains no valid characters for a Pyt
Error message
Project name '{name}' contains no valid characters for a Python module name What it means
Raised by validate_auth_against_agent_card (as A2AClientHTTPError 401) when the client's auth object is the wrong class for what the remote agent's AgentCard security schemes declare. The client-side preflight maps AgentCard security scheme types to allowed ClientAuthScheme classes (_SCHEME_AUTH_MAPPING, _HTTP_SCHEME_MAPPING) and rejects mismatches before any network call.
Source
Thrown at lib/cli/src/crewai_cli/create_crew.py:61
return script_names
def create_folder_structure(
name: str, parent_folder: str | None = None
) -> tuple[Path, str, str]:
import keyword
import re
name = name.rstrip("/")
if not name.strip():
raise ValueError("Project name cannot be empty or contain only whitespace")
folder_name = name.replace(" ", "_").replace("-", "_").lower()
folder_name = re.sub(r"[^a-zA-Z0-9_]", "", folder_name)
if re.match(r"^[^a-zA-Z0-9_-]+", name):
raise ValueError(
f"Project name '{name}' contains no valid characters for a Python module name"
)
if not folder_name:
raise ValueError(
f"Project name '{name}' contains no valid characters for a Python module name"
)
if folder_name[0].isdigit():
raise ValueError(
f"Project name '{name}' would generate folder name '{folder_name}' which cannot start with a digit (invalid Python module name)"
)
if keyword.iskeyword(folder_name):
raise ValueError(
f"Project name '{name}' would generate folder name '{folder_name}' which is a reserved Python keyword"
)
View on GitHub (pinned to 754d7323be)
Solutions
- Fetch the AgentCard and read agent_card.security_schemes to see exactly which scheme(s) the first security requirement names
- Construct the matching client auth class: APIKeySecurityScheme -> APIKeyAuth, OAuth2SecurityScheme -> OAuth2ClientAuth, HTTPAuth 'basic' -> BasicAuth, HTTPAuth 'bearer' -> BearerTokenAuth
- If the card lists alternative schemes (list in security[0]), any one of the allowed classes satisfies the check
- After upgrading the remote agent, re-fetch the AgentCard instead of reusing a cached one, since requirements may have changed
Example fix
# before client = A2AClient(agent_card) await client.invoke(..., auth=BearerTokenAuth(token=tok)) # card requires APIKeyAuth # after client = A2AClient(agent_card) await client.invoke(..., auth=APIKeyAuth(api_key=os.environ['A2A_API_KEY']))
Defensive patterns
Strategy: validation
Validate before calling
from crewai.a2a.auth.utils import validate_auth_against_agent_card validate_auth_against_agent_card(agent_card, auth) # raises A2AClientHTTPError early with a precise message # call this right after fetching the card, before building the full request
Type guard
from crewai.a2a.auth.schemes import (
APIKeyAuth, BearerTokenAuth, BasicAuth, OAuth2ClientAuth, ClientAuthScheme,
)
from crewai.a2a.auth.utils import validate_auth_against_agent_card
def auth_matches_card(auth: ClientAuthScheme, card) -> bool:
try:
validate_auth_against_agent_card(card, auth)
return True
except Exception:
return False Try / catch
from crewai.a2a.auth.errors import A2AClientHTTPError
from crewai.a2a.auth.utils import validate_auth_against_agent_card
try:
validate_auth_against_agent_card(card, auth)
except A2AClientHTTPError as e:
if e.code == 401 and "requires" in str(e):
auth = pick_auth_for_card(card) # construct the class named in the message
else:
raise Prevention
- Always run validate_auth_against_agent_card immediately after fetching the AgentCard to fail before doing request work
- Derive the auth class from the card itself (switch on security_schemes types) instead of hardcoding one
- Re-fetch the AgentCard on every session start; never persist it across deployments
- Write a unit test per supported scheme (apiKey, http/basic, http/bearer, oauth2) asserting your auth factory matches
When it happens
Trigger: Fetching an AgentCard whose security_schemes declare e.g. APIKeySecurityScheme or an HTTPAuthSecurityScheme(scheme='bearer') and then passing auth=BearerTokenAuth(...) (or vice versa) to the A2A client invoke. _raise_auth_mismatch formats this exact message naming the required class(es) and the provided class (utils.py:89-115).
Common situations: Server switched from API-key to OAuth2 between releases; developer copies sample code that uses BearerTokenAuth against an agent that requires APIKeyAuth; multiple security schemes on one card and the developer picks the wrong one to satisfy.
Related errors
- Project name '{name}' would generate folder name '{folder_na
- Error: {e}
- Project name cannot be empty or contain only whitespace
- Invalid or missing authentication credentials
- Error. A valid pyproject.toml file is required. Check that a
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/8c74faa64d485b85.
Report an issue: GitHub.