shareAI-lab/learn-claude-code · error · ValueError
Memory description and body cannot be empty
Error message
Memory description and body cannot be empty
What it means
Raised by write_memory_file() in s09_memory/code.py:155 when either the description or the body argument is empty after stripping whitespace. Both fields are required because the description feeds the memory index (rebuilt immediately after the write) and the body is the actual record content; a record with no body would be a dead file in the store. One combined check covers both fields, so the message does not say which one is missing.
Source
Thrown at s09_memory/code.py:155
if _normalized_memory_text(str(memory.get("body", ""))) == normalized_body:
return False
return True
def memory_document(name: str, mem_type: str, description: str, body: str) -> str:
metadata = yaml.safe_dump(
{"name": name, "description": description, "type": mem_type},
sort_keys=False,
allow_unicode=True,
).strip()
return f"---\n{metadata}\n---\n\n{body.strip()}\n"
def write_memory_file(name: str, mem_type: str, description: str, body: str) -> Path:
if not name.strip():
raise ValueError("Memory name cannot be empty")
if mem_type not in MEMORY_TYPES:
raise ValueError(f"Unknown memory type: {mem_type}")
if not description.strip() or not body.strip():
raise ValueError("Memory description and body cannot be empty")
MEMORY_DIR.mkdir(parents=True, exist_ok=True)
path = memory_path(f"{memory_slug(name)}.md")
path.write_text(memory_document(name, mem_type, description, body))
rebuild_memory_index()
return path
def rebuild_memory_index() -> None:
MEMORY_DIR.mkdir(parents=True, exist_ok=True)
lines = []
for path in sorted(MEMORY_DIR.glob("*.md")):
if path.name == MEMORY_INDEX.name:
continue
try:
path = memory_path(path.name)
except ValueError:
continue
metadata, body = parse_frontmatter(path.read_text())View on GitHub (pinned to 985456f4ad)
Solutions
- Inspect both arguments with strip() before the call and reject or repair whichever is blank.
- When generating records from model output, run validate_memory_record() first — it rejects empty description/body — or log and skip the record instead of writing it.
- If a body is genuinely short (e.g. a one-word preference), still provide a full sentence so strip() cannot empty it.
Example fix
# before
write_memory_file(name, mem_type, record.get('description', ''), record.get('body', ''))
# after
description = (record.get('description') or '').strip()
body = (record.get('body') or '').strip()
if description and body:
write_memory_file(name, mem_type, description, body)
else:
print(f'skipped record {name!r}: empty description or body') Defensive patterns
Strategy: validation
Validate before calling
def record_is_writable(name, mem_type, description, body) -> bool:
return all(isinstance(v, str) and v.strip()
for v in (name, description, body)) Type guard
def has_full_record(rec: dict) -> bool:
return all(isinstance(rec.get(k), str) and rec[k].strip()
for k in ('name', 'description', 'body')) Try / catch
try:
write_memory_file(name, mem_type, description, body)
except ValueError:
log.info('skipping incomplete memory record %r', name)
continue Prevention
- Strip and check both description and body at the call site; the error does not say which is blank.
- Never write records straight from LLM output without validate_memory_record().
- Skip-and-log incomplete records during capture rather than aborting the batch.
When it happens
Trigger: Calling write_memory_file with description='' or body=' '; passing a description but a body that is None (AttributeError aside, whitespace-only strings are the direct trigger); building records from LLM output where the body key exists but contains only whitespace or formatting characters.
Common situations: Summarization pipelines whose output got truncated to empty; template-based record writers that render an empty template when a variable is missing; tests that stub out content generation with blank strings.
Related errors
- Memory name cannot be empty
- The memory index is not a memory record
- Unknown memory type: {mem_type}
- Task subject cannot be empty
- Bash command cannot be empty
AI-assisted analysis of shareAI-lab/learn-claude-code@985456f4ad (2026-08-14).
Data as JSON: /api/errors/37d010ae46089f0b.
Report an issue: GitHub.