MemPalace/mempalace · error · ValueError

{field_name} exceeds maximum length of {MAX_NAME_LENGTH} cha

Error message

{field_name} exceeds maximum length of {MAX_NAME_LENGTH} characters

What it means

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).

Source

Thrown at mempalace/config.py:84

    ``-home-user-proj`` yields ``home_user_proj`` rather than a leading-
    underscore slug that ``sanitize_name`` (and thus the MCP write tools)
    would reject.
    """
    return name.lower().replace(" ", "_").replace("-", "_").strip("_")


def sanitize_name(value: str, field_name: str = "name") -> str:
    """Validate and sanitize a wing/room/entity name.

    Raises ValueError if the name is invalid.
    """
    if not isinstance(value, str) or not value.strip():
        raise ValueError(f"{field_name} must be a non-empty string")

    value = value.strip()

    if len(value) > MAX_NAME_LENGTH:
        raise ValueError(f"{field_name} exceeds maximum length of {MAX_NAME_LENGTH} characters")

    # Block path traversal
    if ".." in value or "/" in value or "\\" in value:
        raise ValueError(f"{field_name} contains invalid path characters")

    # Block null bytes
    if "\x00" in value:
        raise ValueError(f"{field_name} contains null bytes")

    # Enforce safe character set
    if not _SAFE_NAME_RE.match(value):
        raise ValueError(f"{field_name} contains invalid characters")

    return value


def sanitize_kg_value(value: str, field_name: str = "value") -> str:
    """Validate a knowledge-graph entity name (subject or object).

View on GitHub (pinned to 06cb6987f0)

Solutions

  1. Shorten the name to a concise identifier under the limit and put the long description in content/metadata instead
  2. In calling code, enforce the limit before the call: len(name.strip()) <= MAX_NAME_LENGTH
  3. Import MAX_NAME_LENGTH from mempalace.config to validate against the exact bound your version enforces

Example fix

# before
create_wing("Notes from the very long meeting on 2026-08-14 about ...")

# after
create_wing("meeting_2026_08_14")
Defensive patterns

Strategy: validation

Validate before calling

from mempalace.config import MAX_NAME_LENGTH

name = name.strip()
if len(name) > MAX_NAME_LENGTH:
    name = name[:MAX_NAME_LENGTH]  # or reject / slugify, per your policy

Type guard

def name_within_limit(value: str) -> bool:
    return isinstance(value, str) and 0 < len(value.strip()) <= MAX_NAME_LENGTH

Try / catch

try:
    safe = sanitize_name(name)
except ValueError as exc:
    if "maximum length" in str(exc):
        safe = sanitize_name(name[:MAX_NAME_LENGTH])
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of MemPalace/mempalace@06cb6987f0 (2026-08-15). Data as JSON: /api/errors/6d98555a66dea56f. Report an issue: GitHub.