{"record":{"id":"860dbba28e8e0cd6","repo":"run-llama/llama_index","slug":"unexpected-kwargs-kwargs","errorCode":null,"errorMessage":"Unexpected kwargs: {kwargs}","messagePattern":"Unexpected kwargs: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/memory/chat_memory_buffer.py","lineNumber":65,"sourceCode":"        if tokenizer_fn is None:\n            values[\"tokenizer_fn\"] = get_tokenizer()\n\n        return values\n\n    @classmethod\n    def from_defaults(\n        cls,\n        chat_history: Optional[List[ChatMessage]] = None,\n        llm: Optional[LLM] = None,\n        chat_store: Optional[BaseChatStore] = None,\n        chat_store_key: str = DEFAULT_CHAT_STORE_KEY,\n        token_limit: Optional[int] = None,\n        tokenizer_fn: Optional[Callable[[str], List]] = None,\n        **kwargs: Any,\n    ) -> \"ChatMemoryBuffer\":\n        \"\"\"Create a chat memory buffer from an LLM.\"\"\"\n        if kwargs:\n            raise ValueError(f\"Unexpected kwargs: {kwargs}\")\n\n        if llm is not None:\n            context_window = llm.metadata.context_window\n            token_limit = token_limit or int(context_window * DEFAULT_TOKEN_LIMIT_RATIO)\n        elif token_limit is None:\n            token_limit = DEFAULT_TOKEN_LIMIT\n\n        if chat_history is not None:\n            chat_store = chat_store or SimpleChatStore()\n            chat_store.set_messages(chat_store_key, chat_history)\n\n        return cls(\n            token_limit=token_limit,\n            tokenizer_fn=tokenizer_fn or get_tokenizer(),\n            chat_store=chat_store or SimpleChatStore(),\n            chat_store_key=chat_store_key,\n        )\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/memory/chat_memory_buffer.py#L47-L83","documentation":"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).","triggerScenarios":"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).","commonSituations":"Typos in keyword names; upgrading llama-index versions where a from_defaults parameter was renamed or removed; copy-pasting constructor kwargs into from_defaults.","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."],"exampleFix":"# before\nmemory = ChatMemoryBuffer.from_defaults(token_limt=1000)  # typo -> ValueError\n# after\nmemory = ChatMemoryBuffer.from_defaults(token_limit=1000)","handlingStrategy":"validation","validationCode":"import inspect\n\nALLOWED = set(inspect.signature(ChatMemoryBuffer.from_defaults).parameters)\n\ndef filter_memory_kwargs(kwargs: dict) -> dict:\n    return {k: v for k, v in kwargs.items() if k in ALLOWED}","typeGuard":"def are_valid_from_defaults_kwargs(kwargs: dict) -> bool:\n    ALLOWED = {\"chat_history\", \"llm\", \"chat_store\", \"chat_store_key\", \"token_limit\", \"tokenizer_fn\"}\n    return set(kwargs) <= ALLOWED","tryCatchPattern":"try:\n    memory = ChatMemoryBuffer.from_defaults(**kwargs)\nexcept ValueError as e:\n    if \"Unexpected kwargs\" in str(e):\n        kwargs.pop(\"token_limt\", None)  # fix known typo\n        memory = ChatMemoryBuffer.from_defaults(**kwargs)\n    else:\n        raise","preventionTips":["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."],"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"}