zylon-ai/private-gpt · error · ValueError

Unexpected kwargs: {kwargs}

Error message

Unexpected kwargs: {kwargs}

What it means

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.

Source

Thrown at private_gpt/components/memory/trimming_memory.py:125

    def from_defaults(
        cls,
        chat_history: list[ChatMessage] | None = None,
        llm: LLM | None = None,
        chat_store: BaseChatStore | None = None,
        chat_store_key: str = DEFAULT_CHAT_STORE_KEY,
        token_limit: int | None = None,
        trim_strategy: TrimStrategy = TrimStrategy.LAST,
        include_system: bool = True,
        allow_partial: bool = False,
        start_on: MessageRole | list[MessageRole] | None = None,
        end_on: MessageRole | list[MessageRole] | None = None,
        tokenizer_fn: TokenizerFn | None = None,
        text_splitter: Callable[[str], list[str]] | None = None,
        **kwargs: Any,
    ) -> "TrimmingMemory":
        """Create an advanced 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,
            trim_strategy=trim_strategy,
            include_system=include_system,
            allow_partial=allow_partial,
            start_on=start_on,
            end_on=end_on,

View on GitHub (pinned to 4a030776a3)

Solutions

  1. Check the error's {kwargs} content — it names exactly which keys were unexpected; fix or remove them.
  2. Match names to from_defaults' parameters exactly (e.g. token_limit, not token_limt).
  3. When forwarding config dicts, filter to the known parameter set instead of splatting.
  4. Compare against the current signature after upgrading private-gpt.

Example fix

# before
memory = Memory.from_defaults(type='trim', token_limt=2048, tokenizer_fn=tok)

# after
memory = Memory.from_defaults(type='trim', token_limit=2048, tokenizer_fn=tok)
Defensive patterns

Strategy: validation

Validate before calling

ALLOWED = {'llm','chat_history','chat_store','chat_store_key','token_limit',
          'trim_strategy','include_system','allow_partial','start_on','end_on',
          'tokenizer_fn','text_splitter'}
unknown = set(config) - ALLOWED
if unknown:
    raise ConfigError(f'unknown memory options: {unknown}')
mem = TrimmingMemory.from_defaults(**{k: v for k, v in config.items() if k in ALLOWED})

Try / catch

try:
    mem = TrimmingMemory.from_defaults(**config)
except ValueError as e:
    if 'Unexpected kwargs' in str(e):
        fix_config_keys(config); raise  # surface names, fix mapping

Prevention

When it happens

Trigger: 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.

Common situations: Version drift where config field names changed; copy-pasted snippets from older docs; splatting a whole settings dict into from_defaults.

Related errors


AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15). Data as JSON: /api/errors/6bd8f46902230ddd. Report an issue: GitHub.