{"record":{"id":"6bd8f46902230ddd","repo":"zylon-ai/private-gpt","slug":"unexpected-kwargs-kwargs","errorCode":null,"errorMessage":"Unexpected kwargs: {kwargs}","messagePattern":"Unexpected kwargs: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"private_gpt/components/memory/trimming_memory.py","lineNumber":125,"sourceCode":"    def from_defaults(\n        cls,\n        chat_history: list[ChatMessage] | None = None,\n        llm: LLM | None = None,\n        chat_store: BaseChatStore | None = None,\n        chat_store_key: str = DEFAULT_CHAT_STORE_KEY,\n        token_limit: int | None = None,\n        trim_strategy: TrimStrategy = TrimStrategy.LAST,\n        include_system: bool = True,\n        allow_partial: bool = False,\n        start_on: MessageRole | list[MessageRole] | None = None,\n        end_on: MessageRole | list[MessageRole] | None = None,\n        tokenizer_fn: TokenizerFn | None = None,\n        text_splitter: Callable[[str], list[str]] | None = None,\n        **kwargs: Any,\n    ) -> \"TrimmingMemory\":\n        \"\"\"Create an advanced 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            trim_strategy=trim_strategy,\n            include_system=include_system,\n            allow_partial=allow_partial,\n            start_on=start_on,\n            end_on=end_on,","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/memory/trimming_memory.py#L107-L143","documentation":"Raised by TrimmingMemory.from_defaults when extra keyword arguments remain after the declared parameters (chat_history, llm, chat_store, chat_store_key, token_limit, trim_strategy, include_system, allow_partial, start_on, end_on, tokenizer_fn, text_splitter). from_defaults intentionally refuses to silently swallow unknown kwargs — a typo'd or version-mismatched option surfaces immediately instead of being ignored.","triggerScenarios":"Memory.from_defaults(type='trim', token_limt=2048) (typo); passing fields that belong to the model constructor but not to from_defaults; passing options removed or renamed in this version; forwarding a generic **config dict containing unrelated keys.","commonSituations":"Version drift where config field names changed; copy-pasted snippets from older docs; splatting a whole settings dict into from_defaults.","solutions":["Check the error's {kwargs} content — it names exactly which keys were unexpected; fix or remove them.","Match names to from_defaults' parameters exactly (e.g. token_limit, not token_limt).","When forwarding config dicts, filter to the known parameter set instead of splatting.","Compare against the current signature after upgrading private-gpt."],"exampleFix":"# before\nmemory = Memory.from_defaults(type='trim', token_limt=2048, tokenizer_fn=tok)\n\n# after\nmemory = Memory.from_defaults(type='trim', token_limit=2048, tokenizer_fn=tok)","handlingStrategy":"validation","validationCode":"ALLOWED = {'llm','chat_history','chat_store','chat_store_key','token_limit',\n          'trim_strategy','include_system','allow_partial','start_on','end_on',\n          'tokenizer_fn','text_splitter'}\nunknown = set(config) - ALLOWED\nif unknown:\n    raise ConfigError(f'unknown memory options: {unknown}')\nmem = TrimmingMemory.from_defaults(**{k: v for k, v in config.items() if k in ALLOWED})","typeGuard":null,"tryCatchPattern":"try:\n    mem = TrimmingMemory.from_defaults(**config)\nexcept ValueError as e:\n    if 'Unexpected kwargs' in str(e):\n        fix_config_keys(config); raise  # surface names, fix mapping","preventionTips":["Never splat raw config dicts into from_defaults; filter to the known parameter set.","Re-read the signature after upgrading private-gpt — kwargs are validated strictly by design."],"tags":["memory","validation","typo","api-mismatch"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}