TencentCloud/TencentDB-Agent-Memory · error · ParamError
session_id must be a non-empty string
Error message
session_id must be a non-empty string
What it means
In delete_conversation, an explicitly provided session_id parameter must be a non-empty, non-whitespace string. Passing None is allowed (it is simply ignored), but an empty string, whitespace-only string, or non-string value raises ParamError.
Source
Thrown at sdk/memory-core/python/tencentdb_agent_memory/v3/client.py:312
session_id: Optional[str] = None,
) -> Dict[str, Any]:
"""``POST /v3/conversation/delete`` — 批量删除 L0。
``message_ids``(≤5000)与 ``session_ids``(≤100)至少给一个,可同时给。
注意作用域:这里**不会**回退到构造时的 ``session_id``。删除是破坏性
操作,若像读接口那样自动带上默认 session,只想按 message_ids 删几条
的调用方会意外把整个会话删掉。要删会话必须显式传 ``session_ids``。
``session_id``(单数)已废弃,保留仅为兼容旧调用方,会合并进
``session_ids``。
"""
normalized_messages = _normalize_delete_ids("message_ids", message_ids, 5000)
normalized_sessions = _normalize_delete_ids("session_ids", session_ids, 100)
if session_id is not None:
if not isinstance(session_id, str) or not session_id.strip():
raise ParamError("session_id must be a non-empty string")
merged = list(normalized_sessions or [])
if session_id.strip() not in merged:
merged.append(session_id.strip())
normalized_sessions = merged
if not normalized_messages and not normalized_sessions:
raise ParamError(
"delete_conversation requires message_ids or session_ids "
"(the constructor session_id is intentionally NOT used for deletes)"
)
return self._stub.post(
f"{_V3}/conversation/delete",
_strip_none({
**self._iso.base_body(),
"message_ids": normalized_messages,
"session_ids": normalized_sessions,
}),View on GitHub (pinned to 3efcd317b8)
Solutions
- Pass a stripped non-empty session_id string, or omit the parameter (None) entirely
- Normalize before calling: session_id = (raw or '').strip() or None
- Coerce non-strings explicitly: session_id = str(session_id) when it is guaranteed non-empty
- Ensure optional fields serialize to None, not '', when absent
Example fix
// before client.delete_conversation(session_id=session_id or "") # '' raises // after sid = session_id.strip() if isinstance(session_id, str) else None client.delete_conversation(session_id=sid or None)
Defensive patterns
Strategy: type-guard
Validate before calling
def clean_session_id(v):
if v is None:
return None
if isinstance(v, str) and v.strip():
return v.strip()
raise ValueError("session_id must be a non-empty string or None") Type guard
def is_valid_session_id(v) -> bool:
return v is None or (isinstance(v, str) and bool(v.strip())) Try / catch
try:
client.delete_conversation(session_id=sid)
except ParamError as e:
if "non-empty string" in str(e):
sid = None # fall back to session_ids-based delete
client.delete_conversation(session_ids=[...]) Prevention
- Normalize optional string params to None instead of '' when absent
- Never pass str(None) or unset template placeholders as session ids
- Strip session ids at the API boundary of your own service
- Use a dedicated SessionId type/wrapper to avoid raw strings
When it happens
Trigger: Calling delete_conversation(session_id="") or session_id=" "; passing a non-string (int, UUID object) as session_id; forwarding an optional variable that is an empty string rather than None.
Common situations: Config or request payloads where the session id defaulted to empty string instead of None; a upstream caller converting None to '' via str(None) or default substitutions.
Related errors
- {field} must contain only non-empty strings
- delete_atomic requires a non-empty ids list
- clear_chat_memory requires a non-empty memory_ids list
- {field} accepts at most {max_items} items, got {len(deduped)
- v3 MemoryClient requires non-empty {', '.join(missing)} at c
AI-assisted analysis of TencentCloud/TencentDB-Agent-Memory@3efcd317b8 (2026-09-01).
Data as JSON: /api/errors/be1e2b131b4e2dbc.
Report an issue: GitHub.