{"record":{"id":"6d98555a66dea56f","repo":"MemPalace/mempalace","slug":"field-name-exceeds-maximum-length-of-max-name-l","errorCode":null,"errorMessage":"{field_name} exceeds maximum length of {MAX_NAME_LENGTH} characters","messagePattern":"(.+?) exceeds maximum length of (.+?) characters","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mempalace/config.py","lineNumber":84,"sourceCode":"    ``-home-user-proj`` yields ``home_user_proj`` rather than a leading-\n    underscore slug that ``sanitize_name`` (and thus the MCP write tools)\n    would reject.\n    \"\"\"\n    return name.lower().replace(\" \", \"_\").replace(\"-\", \"_\").strip(\"_\")\n\n\ndef sanitize_name(value: str, field_name: str = \"name\") -> str:\n    \"\"\"Validate and sanitize a wing/room/entity name.\n\n    Raises ValueError if the name is invalid.\n    \"\"\"\n    if not isinstance(value, str) or not value.strip():\n        raise ValueError(f\"{field_name} must be a non-empty string\")\n\n    value = value.strip()\n\n    if len(value) > MAX_NAME_LENGTH:\n        raise ValueError(f\"{field_name} exceeds maximum length of {MAX_NAME_LENGTH} characters\")\n\n    # Block path traversal\n    if \"..\" in value or \"/\" in value or \"\\\\\" in value:\n        raise ValueError(f\"{field_name} contains invalid path characters\")\n\n    # Block null bytes\n    if \"\\x00\" in value:\n        raise ValueError(f\"{field_name} contains null bytes\")\n\n    # Enforce safe character set\n    if not _SAFE_NAME_RE.match(value):\n        raise ValueError(f\"{field_name} contains invalid characters\")\n\n    return value\n\n\ndef sanitize_kg_value(value: str, field_name: str = \"value\") -> str:\n    \"\"\"Validate a knowledge-graph entity name (subject or object).","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/config.py#L66-L102","documentation":"Raised by sanitize_name() when a wing/room/entity name exceeds MAX_NAME_LENGTH characters. Names back filesystem paths and collection identifiers whose length is bounded, so over-long names are rejected before any storage is touched. The limit constant is defined in mempalace/config.py (MAX_NAME_LENGTH).","triggerScenarios":"Passing a name longer than MAX_NAME_LENGTH (after whitespace stripping) to any API or CLI that calls sanitize_name — e.g. a full sentence, a base64 blob, or an LLM-generated descriptive title used as a wing name.","commonSituations":"LLM tool calls using a whole document title or summary as the entity name; pasting a path-like descriptive string; programmatic generation of names from user input without truncation.","solutions":["Shorten the name to a concise identifier under the limit and put the long description in content/metadata instead","In calling code, enforce the limit before the call: len(name.strip()) <= MAX_NAME_LENGTH","Import MAX_NAME_LENGTH from mempalace.config to validate against the exact bound your version enforces"],"exampleFix":"# before\ncreate_wing(\"Notes from the very long meeting on 2026-08-14 about ...\")\n\n# after\ncreate_wing(\"meeting_2026_08_14\")","handlingStrategy":"validation","validationCode":"from mempalace.config import MAX_NAME_LENGTH\n\nname = name.strip()\nif len(name) > MAX_NAME_LENGTH:\n    name = name[:MAX_NAME_LENGTH]  # or reject / slugify, per your policy","typeGuard":"def name_within_limit(value: str) -> bool:\n    return isinstance(value, str) and 0 < len(value.strip()) <= MAX_NAME_LENGTH","tryCatchPattern":"try:\n    safe = sanitize_name(name)\nexcept ValueError as exc:\n    if \"maximum length\" in str(exc):\n        safe = sanitize_name(name[:MAX_NAME_LENGTH])\n    else:\n        raise","preventionTips":["Keep names short identifiers; put prose in content/metadata","Import MAX_NAME_LENGTH and enforce it in UI input validation","Watch LLM-generated names — they routinely exceed limits"],"tags":["validation","names","length-limit","mempalace"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}