run-llama/llama_index · error · ValueError
Token limit for full-text messages must be set and greater t
Error message
Token limit for full-text messages must be set and greater than 0.
What it means
ChatSummaryMemoryBuffer (which summarizes old messages instead of dropping them) uses the same pydantic validation pattern as ChatMemoryBuffer: token_limit must be present and >= 1, otherwise ValueError. The limit governs when full-text messages get summarized into a compressed summary.
Source
Thrown at llama-index-core/llama_index/core/memory/chat_summary_memory_buffer.py:72
chat_store: SerializeAsAny[BaseChatStore] = Field(default_factory=SimpleChatStore)
chat_store_key: str = Field(default=DEFAULT_CHAT_STORE_KEY)
_token_count: int = PrivateAttr(default=0)
@field_serializer("chat_store")
def serialize_courses_in_order(self, chat_store: BaseChatStore) -> dict:
res = chat_store.model_dump()
res.update({"class_name": chat_store.class_name()})
return res
@model_validator(mode="before")
@classmethod
def validate_memory(cls, values: dict) -> dict:
"""Validate the memory."""
# Validate token limits
token_limit = values.get("token_limit", -1)
if token_limit < 1:
raise ValueError(
"Token limit for full-text messages must be set and greater than 0."
)
# Validate tokenizer -- this avoids errors when loading from json/dict
tokenizer_fn = values.get("tokenizer_fn")
if tokenizer_fn is None:
values["tokenizer_fn"] = get_tokenizer()
return values
@classmethod
def from_defaults(
cls,
chat_history: Optional[List[ChatMessage]] = None,
llm: Optional[LLM] = None,
chat_store: Optional[BaseChatStore] = None,
chat_store_key: str = DEFAULT_CHAT_STORE_KEY,
token_limit: Optional[int] = None,
View on GitHub (pinned to afd0fef371)
Solutions
- Use ChatSummaryMemoryBuffer.from_defaults(llm=llm, ...) which derives the limit from the LLM context window.
- Pass token_limit explicitly as a positive integer.
- Verify persisted dicts include token_limit before reloading.
Example fix
# before memory = ChatSummaryMemoryBuffer(llm=llm) # ValueError: no token_limit # after memory = ChatSummaryMemoryBuffer.from_defaults(llm=llm) # or memory = ChatSummaryMemoryBuffer(llm=llm, token_limit=3000)
Defensive patterns
Strategy: validation
Validate before calling
def is_valid_summary_memory_config(data: dict) -> bool:
tl = data.get("token_limit", -1)
return isinstance(tl, int) and tl >= 1 and data.get("llm") is not None
assert is_valid_summary_memory_config(config), "token_limit >= 1 and llm are required" Type guard
def has_valid_token_limit(memory_dict: dict) -> bool:
tl = memory_dict.get("token_limit", -1)
return isinstance(tl, int) and tl >= 1 Try / catch
try:
memory = ChatSummaryMemoryBuffer(llm=llm)
except ValueError as e:
if "Token limit for full-text" in str(e):
memory = ChatSummaryMemoryBuffer(llm=llm, token_limit=3000)
else:
raise Prevention
- Use from_defaults(llm=...) for ChatSummaryMemoryBuffer to auto-derive the limit.
- Include token_limit whenever persisting summary memory config.
- Remember this buffer also needs an llm for summarization.
When it happens
Trigger: Constructing ChatSummaryMemoryBuffer(...) directly without token_limit, with 0/negative, or deserializing a dict lacking the key — note it also requires an llm for summarization.
Common situations: Switching from ChatMemoryBuffer and assuming defaults exist on the raw constructor; loading persisted memory JSON that omitted token_limit; passing None explicitly.
Related errors
- Token limit must be set and greater than 0.
- Unknown retriever mode: {retriever_mode}
- Unknown retriever mode: {retriever_mode}
- Cannot initialize from a vector store that does not store te
- llm must start with str 'local' or of type LLM or BaseLangua
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/f176bdebf39d36cf.
Report an issue: GitHub.