{"record":{"id":"3df6e3d7c7d4b2ac","repo":"zylon-ai/private-gpt","slug":"include-system-can-only-be-used-with-last-strate","errorCode":null,"errorMessage":"include_system can only be used with 'last' strategy","messagePattern":"include_system can only be used with 'last' strategy","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"private_gpt/components/memory/trimming_memory.py","lineNumber":102,"sourceCode":"        if tokenizer_fn is None:\n            # TODO: Replace with a default tokenizer function\n            raise ValueError(\"tokenizer_fn must be provided.\")\n\n        # Validate text splitter\n        text_splitter = values.get(\"text_splitter\")\n        if text_splitter is None:\n            values[\"text_splitter\"] = _default_text_splitter\n\n        # Validate strategy-specific constraints\n        trim_strategy = values.get(\"trim_strategy\", TrimStrategy.LAST)\n        start_on = values.get(\"start_on\")\n        include_system = values.get(\"include_system\", True)\n\n        if start_on and trim_strategy == TrimStrategy.FIRST:\n            raise ValueError(\"start_on can only be used with 'last' strategy\")\n\n        if include_system and trim_strategy == TrimStrategy.FIRST:\n            raise ValueError(\"include_system can only be used with 'last' strategy\")\n\n        return values\n\n    @classmethod\n    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,","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/memory/trimming_memory.py#L84-L120","documentation":"Companion constraint to error 154: the TrimmingMemory validator raises when include_system is truthy (note the default is True) while trim_strategy is TrimStrategy.FIRST. include_system preserves system messages when trimming with the LAST strategy; under FIRST strategy the semantics are undefined in this implementation, so the combination is rejected. Because include_system defaults to True, choosing FIRST strategy while merely leaving defaults can trigger this.","triggerScenarios":"TrimmingMemory(trim_strategy=TrimStrategy.FIRST) with include_system left at its default True; explicitly passing include_system=True with FIRST; switching an existing memory config to 'first' without adding include_system=False.","commonSituations":"Adopting FIRST trimming in an existing deployment where the config never mentioned include_system; config migration tools that preserve old defaults when the strategy changes.","solutions":["When using TrimStrategy.FIRST, set include_system=False explicitly.","Or stay with the default LAST strategy if you need system-message preservation.","Add cross-field checks in config validation so strategy flips force include_system review."],"exampleFix":"# before\nTrimmingMemory(trim_strategy=TrimStrategy.FIRST, ...)\n\n# after\nTrimmingMemory(trim_strategy=TrimStrategy.FIRST, include_system=False, ...)","handlingStrategy":"validation","validationCode":"if trim_strategy == 'first':\n    include_system = False  # FIRST strategy forbids include_system\nkwargs['trim_strategy'] = trim_strategy\nkwargs['include_system'] = include_system","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember include_system defaults to True: switching to FIRST strategy requires setting it False explicitly.","Encode the strategy/flags matrix in config validation so illegal pairs never reach the model validator."],"tags":["memory","validation","configuration","trimming"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}