run-llama/llama_index · error · ValueError
Unexpected kwargs: {kwargs}
Error message
Unexpected kwargs: {kwargs} What it means
ChatMemoryBuffer.from_defaults has a fixed keyword signature and collects anything else into **kwargs; if kwargs is non-empty it raises ValueError listing them. This is a fail-fast guard against typos and renamed parameters silently being ignored (which would produce a misconfigured memory without any signal).
Source
Thrown at llama-index-core/llama_index/core/memory/chat_memory_buffer.py:65
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,
tokenizer_fn: Optional[Callable[[str], List]] = None,
**kwargs: Any,
) -> "ChatMemoryBuffer":
"""Create a chat memory buffer from an LLM."""
if kwargs:
raise ValueError(f"Unexpected kwargs: {kwargs}")
if llm is not None:
context_window = llm.metadata.context_window
token_limit = token_limit or int(context_window * DEFAULT_TOKEN_LIMIT_RATIO)
elif token_limit is None:
token_limit = DEFAULT_TOKEN_LIMIT
if chat_history is not None:
chat_store = chat_store or SimpleChatStore()
chat_store.set_messages(chat_store_key, chat_history)
return cls(
token_limit=token_limit,
tokenizer_fn=tokenizer_fn or get_tokenizer(),
chat_store=chat_store or SimpleChatStore(),
chat_store_key=chat_store_key,
)
View on GitHub (pinned to afd0fef371)
Solutions
- Read the error message — it echoes the exact unexpected keys; fix or remove them.
- Check the signature: inspect.signature(ChatMemoryBuffer.from_defaults) and use only accepted kwargs.
- If the option genuinely exists on the class, construct ChatMemoryBuffer(...) directly with it after setting token_limit.
Example fix
# before memory = ChatMemoryBuffer.from_defaults(token_limt=1000) # typo -> ValueError # after memory = ChatMemoryBuffer.from_defaults(token_limit=1000)
Defensive patterns
Strategy: validation
Validate before calling
import inspect
ALLOWED = set(inspect.signature(ChatMemoryBuffer.from_defaults).parameters)
def filter_memory_kwargs(kwargs: dict) -> dict:
return {k: v for k, v in kwargs.items() if k in ALLOWED} Type guard
def are_valid_from_defaults_kwargs(kwargs: dict) -> bool:
ALLOWED = {"chat_history", "llm", "chat_store", "chat_store_key", "token_limit", "tokenizer_fn"}
return set(kwargs) <= ALLOWED Try / catch
try:
memory = ChatMemoryBuffer.from_defaults(**kwargs)
except ValueError as e:
if "Unexpected kwargs" in str(e):
kwargs.pop("token_limt", None) # fix known typo
memory = ChatMemoryBuffer.from_defaults(**kwargs)
else:
raise Prevention
- Let the IDE type the call against the real signature instead of free-typing kwargs.
- Diff from_defaults signatures when upgrading llama-index versions.
- Keep memory construction in one helper so typos surface in one place.
When it happens
Trigger: Calling ChatMemoryBuffer.from_defaults(token_limt=1000) (typo), or passing parameters that belong to the class constructor but not to from_defaults (e.g. passing an argument removed/renamed in this version).
Common situations: Typos in keyword names; upgrading llama-index versions where a from_defaults parameter was renamed or removed; copy-pasting constructor kwargs into from_defaults.
Related errors
- Unexpected keyword arguments: {kwargs}
- Token limit must be set and greater than 0.
- Initial token count exceeds token limit
- Token limit for full-text messages must be set and greater t
- Max iterations of {max_iterations} reached! Either something
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/860dbba28e8e0cd6.
Report an issue: GitHub.