run-llama/llama_index · error · ValueError

Unexpected keyword arguments: {kwargs}

Error message

Unexpected keyword arguments: {kwargs}

What it means

ChatSummaryMemoryBuffer.from_defaults mirrors ChatMemoryBuffer.from_defaults: any keyword argument not in its explicit signature lands in **kwargs and, if present, triggers ValueError listing the unexpected names. This prevents silently ignoring misspelled or version-mismatched options.

Source

Thrown at llama-index-core/llama_index/core/memory/chat_summary_memory_buffer.py:101

    @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,
        summarize_prompt: Optional[str] = None,
        count_initial_tokens: bool = False,
        **kwargs: Any,
    ) -> "ChatSummaryMemoryBuffer":
        """
        Create a chat memory buffer from an LLM
        and an initial list of chat history messages.
        """
        if kwargs:
            raise ValueError(f"Unexpected keyword arguments: {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

        chat_store = chat_store or SimpleChatStore()

        if chat_history is not None:
            chat_store.set_messages(chat_store_key, chat_history)

        summarize_prompt = summarize_prompt or SUMMARIZE_PROMPT
        return cls(
            llm=llm,
            token_limit=token_limit,
            # TODO: Check if we can get the tokenizer from the llm
            tokenizer_fn=tokenizer_fn or get_tokenizer(),

View on GitHub (pinned to afd0fef371)

Solutions

  1. Inspect the echoed kwargs in the message and correct/remove them.
  2. Confirm the accepted signature via inspect.signature(ChatSummaryMemoryBuffer.from_defaults).
  3. Construct the class directly for options only exposed on the constructor (while still providing token_limit).

Example fix

# before
memory = ChatSummaryMemoryBuffer.from_defaults(llm=llm, memory_token_limit=2000)
# after
memory = ChatSummaryMemoryBuffer.from_defaults(llm=llm, token_limit=2000)
Defensive patterns

Strategy: validation

Validate before calling

import inspect

ALLOWED = set(inspect.signature(ChatSummaryMemoryBuffer.from_defaults).parameters)

def filter_summary_memory_kwargs(kwargs: dict) -> dict:
    return {k: v for k, v in kwargs.items() if k in ALLOWED and k != "kwargs"}

Type guard

def are_valid_summary_from_defaults_kwargs(kwargs: dict) -> bool:
    ALLOWED = {"chat_history", "llm", "chat_store", "chat_store_key", "token_limit",
               "tokenizer_fn", "summarize_prompt", "count_initial_tokens"}
    return set(kwargs) <= ALLOWED

Try / catch

try:
    memory = ChatSummaryMemoryBuffer.from_defaults(llm=llm, **kwargs)
except ValueError as e:
    if "Unexpected keyword arguments" in str(e):
        bad = set(kwargs) - {"chat_history", "llm", "chat_store", "chat_store_key", "token_limit", "tokenizer_fn", "summarize_prompt", "count_initial_tokens"}
        raise ValueError(f"Remove/fix: {bad}") from e
    raise

Prevention

When it happens

Trigger: Calling ChatSummaryMemoryBuffer.from_defaults(...) with a typo (e.g. tokenizer_fn misspelled), or with parameters valid on ChatMemoryBuffer/constructor but not on this class's from_defaults.

Common situations: Copy-pasting memory setup code between ChatMemoryBuffer and ChatSummaryMemoryBuffer; renamed parameters across llama-index versions; IDE autocompleting the wrong name.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/c63166e34c6793a4. Report an issue: GitHub.