{"record":{"id":"529a598b46f3057c","repo":"zylon-ai/private-gpt","slug":"system-messages-alone-exceed-the-maximum-length-c","errorCode":null,"errorMessage":"System messages alone exceed the maximum length. Cannot condense conversation history.","messagePattern":"System messages alone exceed the maximum length\\. Cannot condense conversation history\\.","errorType":"exception","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"private_gpt/components/chat/processors/chat_history/memory/tldr_processor.py","lineNumber":84,"sourceCode":"        trim_to_last_tldr, conversation_history\n    )\n\n    # 2. Check if condensation is needed\n    if not chat_history or not max_length:\n        yield CondenseResponse(chat_history=chat_history, condense_blocks=None)\n        return\n\n    # 2. Ensure that max_length - system_messages_length is greater than 0\n    remaining_max_length = max_length\n    if system_messages:\n        system_token_count = await estimate_token_count(\n            system_messages,\n            tokenizer_fn=tokenizer_fn,\n            message_to_input=message_to_input,\n            **kwargs,\n        )\n        if system_token_count >= max_length:\n            raise ValueError(\n                \"System messages alone exceed the maximum length. Cannot condense conversation history.\"\n            )\n\n        remaining_max_length -= system_token_count\n\n    if condense_strategy is None:\n        strategy_type = CondenseStrategyType.from_string(str(strategy_type))\n        if strategy_type == CondenseStrategyType.UNKNOWN:\n            yield CondenseResponse(chat_history=chat_history, condense_blocks=None)\n            return\n\n        if str(strategy_type) in CACHE_CONDENSE_STRATEGY:\n            condense_strategy = CACHE_CONDENSE_STRATEGY[str(strategy_type)]\n        else:\n            condense_strategy = get_condense_memory_strategy(\n                strategy_type,\n                injector=injector,\n                message_to_input=message_to_input,","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/chat/processors/chat_history/memory/tldr_processor.py#L66-L102","documentation":"Raised in the TLDR condensation pipeline before any condensing happens: the token count of the system messages alone is >= max_length, leaving zero (or negative) budget for the conversation. Because system messages are always preserved, condensation cannot proceed and the processor aborts with this ValueError.","triggerScenarios":"Calling the tldr condense flow with a system prompt whose estimated token count >= max_length; estimate_token_count(system_messages, ...) returning a value >= the configured max_length.","commonSituations":"RAG/system prompts stuffed with retrieved context or long instructions combined with a small max_length; changing to a model with a smaller context window without retuning condensation settings; tokenizer_fn that overestimates tokens.","solutions":["Increase max_length (raise the condensation budget setting)","Reduce the system prompt size — trim instructions, remove injected context","Check tokenizer_fn matches the target model so the count is accurate","Fail fast at startup with a config validation asserting system_tokens < max_length"],"exampleFix":"# before\nsettings.condenser.max_length = 1024  # system prompt is ~1500 tokens\n\n# after\nsettings.condenser.max_length = 8192  # comfortably above system prompt size","handlingStrategy":"validation","validationCode":"sys_tokens = await estimate_token_count(system_messages, tokenizer_fn=tokenizer_fn)\nif sys_tokens >= max_length:\n    raise ConfigError(\"system prompt too large for condensation budget\")","typeGuard":null,"tryCatchPattern":"try:\n    async for resp in run_tldr_condense(chat_history, max_length=ml, system_messages=sys_msgs):\n        ...\nexcept ValueError as e:\n    if \"System messages alone exceed\" in str(e):\n        ml = sys_tokens + fallback_conversation_budget  # or abort with a clear message\n    else:\n        raise","preventionTips":["Track system-prompt token count in CI as a guarded metric","Never let retrieved context land in the system message without a size cap","Document a minimum max_length per model in deployment settings"],"tags":["chat-history","system-prompt","token-limit","condensation"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}