{"record":{"id":"4edb01ab1327193a","repo":"MemPalace/mempalace","slug":"content-exceeds-maximum-length-of-max-length-cha","errorCode":null,"errorMessage":"content exceeds maximum length of {max_length} characters","messagePattern":"content exceeds maximum length of (.+?) characters","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mempalace/config.py","lineNumber":215,"sourceCode":"\n\ndef sanitize_iso_date(value, field_name: str = \"date\"):\n    \"\"\"Backward-compatible wrapper for ISO temporal validation.\n\n    Historically this accepted only full dates. It now also accepts canonical\n    UTC datetimes, but the old name is kept so existing imports continue to\n    work.\n    \"\"\"\n\n    return sanitize_iso_temporal(value, field_name)\n\n\ndef sanitize_content(value: str, max_length: int = 100_000) -> str:\n    \"\"\"Validate drawer/diary content length.\"\"\"\n    if not isinstance(value, str) or not value.strip():\n        raise ValueError(\"content must be a non-empty string\")\n    if len(value) > max_length:\n        raise ValueError(f\"content exceeds maximum length of {max_length} characters\")\n    if \"\\x00\" in value:\n        raise ValueError(\"content contains null bytes\")\n    return strip_lone_surrogates(value)\n\n\nDEFAULT_PALACE_PATH = os.path.expanduser(\"~/.mempalace/palace\")\nDEFAULT_COLLECTION_NAME = \"mempalace_drawers\"\nDEFAULT_BACKEND = \"chroma\"\nDEFAULT_MILVUS_CONSISTENCY_LEVEL = \"Strong\"\n_MILVUS_CONSISTENCY_LEVELS = {\n    \"strong\": \"Strong\",\n    \"session\": \"Session\",\n    \"bounded\": \"Bounded\",\n    \"eventually\": \"Eventually\",\n}\n\n# How many timestamped palace backups to retain before the oldest are\n# pruned. Applies to the accumulating backups written by ``mempalace","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/config.py#L197-L233","documentation":"Raised by sanitize_content() when drawer/diary content exceeds max_length characters (default 100,000). Verbatim storage means content is never silently truncated — an over-long payload would bloat a single drawer beyond its intended granularity, so it is rejected and the caller is expected to chunk it first.","triggerScenarios":"Calling a drawer/diary write API with a document longer than the limit — e.g. saving a whole day's transcript, a large log file, or concatenated sessions as one content string (default limit 100k chars).","commonSituations":"Bulk-importing large files without chunking; hooks accumulating an entire long session; users pasting a whole book chapter; custom callers raising the limit elsewhere but hitting the default.","solutions":["Chunk the content into multiple drawers below the limit (split on paragraph/session boundaries to keep chunks coherent)","Check size before the call: len(content) <= 100_000 (or the max_length you pass)","Pass a larger max_length explicitly only if your use case truly needs one huge drawer"],"exampleFix":"# before\nsave_drawer(wing, room, huge_text)   # >100k chars\n\n# after\nfor i in range(0, len(huge_text), 90_000):\n    save_drawer(wing, room, huge_text[i:i+90_000])","handlingStrategy":"validation","validationCode":"MAX = 100_000  # keep in sync with the default, or your explicit max_length\nCHUNK = 90_000\nchunks = [content[i:i + CHUNK] for i in range(0, len(content), CHUNK)] or [\"\"]\n# write each chunk as its own drawer","typeGuard":"def content_within_limit(content: str, max_length: int = 100_000) -> bool:\n    return isinstance(content, str) and 0 < len(content) <= max_length","tryCatchPattern":"try:\n    safe = sanitize_content(content)\nexcept ValueError as exc:\n    if \"maximum length\" in str(exc):\n        for chunk in split_paragraph_boundaries(content, 90_000):\n            save_drawer(wing, room, chunk)\n    else:\n        raise","preventionTips":["Chunk large inputs on natural boundaries (paragraphs, sessions) before writing","Check len(content) before the call in import pipelines","Never rely on the library to truncate — verbatim storage means it never will"],"tags":["validation","content","length-limit","chunking","mempalace"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}