{"record":{"id":"c63166e34c6793a4","repo":"run-llama/llama_index","slug":"unexpected-keyword-arguments-kwargs","errorCode":null,"errorMessage":"Unexpected keyword arguments: {kwargs}","messagePattern":"Unexpected keyword arguments: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/memory/chat_summary_memory_buffer.py","lineNumber":101,"sourceCode":"    @classmethod\r\n    def from_defaults(\r\n        cls,\r\n        chat_history: Optional[List[ChatMessage]] = None,\r\n        llm: Optional[LLM] = None,\r\n        chat_store: Optional[BaseChatStore] = None,\r\n        chat_store_key: str = DEFAULT_CHAT_STORE_KEY,\r\n        token_limit: Optional[int] = None,\r\n        tokenizer_fn: Optional[Callable[[str], List]] = None,\r\n        summarize_prompt: Optional[str] = None,\r\n        count_initial_tokens: bool = False,\r\n        **kwargs: Any,\r\n    ) -> \"ChatSummaryMemoryBuffer\":\r\n        \"\"\"\r\n        Create a chat memory buffer from an LLM\r\n        and an initial list of chat history messages.\r\n        \"\"\"\r\n        if kwargs:\r\n            raise ValueError(f\"Unexpected keyword arguments: {kwargs}\")\r\n\r\n        if llm is not None:\r\n            context_window = llm.metadata.context_window\r\n            token_limit = token_limit or int(context_window * DEFAULT_TOKEN_LIMIT_RATIO)\r\n        elif token_limit is None:\r\n            token_limit = DEFAULT_TOKEN_LIMIT\r\n\r\n        chat_store = chat_store or SimpleChatStore()\r\n\r\n        if chat_history is not None:\r\n            chat_store.set_messages(chat_store_key, chat_history)\r\n\r\n        summarize_prompt = summarize_prompt or SUMMARIZE_PROMPT\r\n        return cls(\r\n            llm=llm,\r\n            token_limit=token_limit,\r\n            # TODO: Check if we can get the tokenizer from the llm\r\n            tokenizer_fn=tokenizer_fn or get_tokenizer(),\r","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/memory/chat_summary_memory_buffer.py#L83-L119","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copy-pasting memory setup code between ChatMemoryBuffer and ChatSummaryMemoryBuffer; renamed parameters across llama-index versions; IDE autocompleting the wrong name.","solutions":["Inspect the echoed kwargs in the message and correct/remove them.","Confirm the accepted signature via inspect.signature(ChatSummaryMemoryBuffer.from_defaults).","Construct the class directly for options only exposed on the constructor (while still providing token_limit)."],"exampleFix":"# before\nmemory = ChatSummaryMemoryBuffer.from_defaults(llm=llm, memory_token_limit=2000)\n# after\nmemory = ChatSummaryMemoryBuffer.from_defaults(llm=llm, token_limit=2000)","handlingStrategy":"validation","validationCode":"import inspect\n\nALLOWED = set(inspect.signature(ChatSummaryMemoryBuffer.from_defaults).parameters)\n\ndef filter_summary_memory_kwargs(kwargs: dict) -> dict:\n    return {k: v for k, v in kwargs.items() if k in ALLOWED and k != \"kwargs\"}","typeGuard":"def are_valid_summary_from_defaults_kwargs(kwargs: dict) -> bool:\n    ALLOWED = {\"chat_history\", \"llm\", \"chat_store\", \"chat_store_key\", \"token_limit\",\n               \"tokenizer_fn\", \"summarize_prompt\", \"count_initial_tokens\"}\n    return set(kwargs) <= ALLOWED","tryCatchPattern":"try:\n    memory = ChatSummaryMemoryBuffer.from_defaults(llm=llm, **kwargs)\nexcept ValueError as e:\n    if \"Unexpected keyword arguments\" in str(e):\n        bad = set(kwargs) - {\"chat_history\", \"llm\", \"chat_store\", \"chat_store_key\", \"token_limit\", \"tokenizer_fn\", \"summarize_prompt\", \"count_initial_tokens\"}\n        raise ValueError(f\"Remove/fix: {bad}\") from e\n    raise","preventionTips":["Do not copy kwarg sets between ChatMemoryBuffer and ChatSummaryMemoryBuffer blindly.","Re-check from_defaults signatures after llama-index upgrades.","Centralize memory factory code so signature drift fails fast in tests."],"tags":["llama-index","memory","validation","api-misuse","typo"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}