HKUDS/DeepTutor · error · OpValidationError
edit: text length must be 1..{_MAX_TEXT_LEN} (got {len(op.ne
Error message
edit: text length must be 1..{_MAX_TEXT_LEN} (got {len(op.new_text)}) What it means
OpValidationError raised in _validate when an EditOp's new_text is empty or longer than _MAX_TEXT_LEN. Replacement text for an existing entry is bounded by the same limit as AddOp text so entries stay within the memory document's size budget; invalid replacement text is rejected before the edit is applied (apply is all-or-nothing).
Source
Thrown at deeptutor/services/memory/ops.py:91
if isinstance(op, AddOp):
if not op.text or len(op.text) > _MAX_TEXT_LEN:
raise OpValidationError(
f"add: text length must be 1..{_MAX_TEXT_LEN} (got {len(op.text)})"
)
if not op.section or len(op.section) > _MAX_SECTION_LEN:
raise OpValidationError(f"add: invalid section {op.section!r}")
if not op.refs:
raise OpValidationError("add: refs must be non-empty")
for ref in op.refs:
if not is_valid_ref(ref):
raise OpValidationError(f"add: malformed ref {ref!r}")
elif isinstance(op, EditOp):
if not is_entry_id(op.target_id):
raise OpValidationError(f"edit: malformed target_id {op.target_id!r}")
if doc.find(op.target_id) is None:
raise OpValidationError(f"edit: target_id {op.target_id} not found")
if not op.new_text or len(op.new_text) > _MAX_TEXT_LEN:
raise OpValidationError(
f"edit: text length must be 1..{_MAX_TEXT_LEN} (got {len(op.new_text)})"
)
if not op.new_refs:
raise OpValidationError("edit: refs must be non-empty")
for ref in op.new_refs:
if not is_valid_ref(ref):
raise OpValidationError(f"edit: malformed ref {ref!r}")
if op.target_id in deletes:
raise OpValidationError(
f"batch conflict: edit and delete on same id {op.target_id}"
)
edits.add(op.target_id)
elif isinstance(op, DeleteOp):
if not is_entry_id(op.target_id):
raise OpValidationError(f"delete: malformed target_id {op.target_id!r}")
if doc.find(op.target_id) is None:
raise OpValidationError(f"delete: target_id {op.target_id} not found")
if op.reason not in _DELETE_REASONS:View on GitHub (pinned to 3e82f13042)
Solutions
- Clamp/reject: require 1.._MAX_TEXT_LEN (import the constant from ops.py) before building the EditOp
- To remove content use the dedicated DeleteOp rather than an empty-text edit
- Summarize or split oversized replacement text; surface a clear error to the LLM/caller so it retries shorter
Example fix
# before
op = EditOp(target_id=eid, new_text=rewritten, new_refs=[ref])
# after
from deeptutor.services.memory.ops import _MAX_TEXT_LEN
rewritten = rewritten.strip()
if not rewritten or len(rewritten) > _MAX_TEXT_LEN:
raise ValueError("replacement text out of range")
op = EditOp(target_id=eid, new_text=rewritten, new_refs=[ref]) Defensive patterns
Strategy: validation
Validate before calling
from deeptutor.services.memory.ops import _MAX_TEXT_LEN
new_text = new_text.strip() if new_text else ""
if not (1 <= len(new_text) <= _MAX_TEXT_LEN):
raise ValueError("replacement text out of range") Type guard
def is_valid_edit_text(text: str) -> bool:
return bool(text) and len(text) <= _MAX_TEXT_LEN Try / catch
try:
ops.apply(doc, [op])
except OpValidationError as e:
if e.args[0].startswith("edit: text length"):
op = replace(op, new_text=op.new_text[:_MAX_TEXT_LEN])
ops.apply(doc, [op])
else:
raise Prevention
- Clamp LLM rewrites to _MAX_TEXT_LEN before building EditOp
- Use DeleteOp for removals, never empty-string edits
- Import limits from ops.py so constants stay in sync
When it happens
Trigger: EditOp(..., new_text='' or new_text longer than _MAX_TEXT_LEN) passed to ops.apply — typically an LLM rewriting an entry into an oversized blob, or code passing None/empty string as 'no change' semantics that the API does not support.
Common situations: LLM-generated replacements without clamping; 'clear this entry' implemented as empty text instead of a delete op; diffs or concatenations accidentally producing huge strings; tests probing boundaries.
Related errors
- add: text length must be 1..{_MAX_TEXT_LEN} (got {len(op.tex
- add: invalid section {op.section!r}
- add: refs must be non-empty
- add: malformed ref {ref!r}
- edit: malformed target_id {op.target_id!r}
AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27).
Data as JSON: /api/errors/7762141defacbacd.
Report an issue: GitHub.