zylon-ai/private-gpt · error · ValueError
Condensed history exceeds maximum length after applying cond
Error message
Condensed history exceeds maximum length after applying condensation strategy.
What it means
Post-condition check in the TLDR processor: after build_condensed_history assembled system messages + condensed conversation history, the final token count still exceeds max_length. The chosen strategy produced a summary/trimmed history that, together with the always-kept system messages, is too large for the budget.
Source
Thrown at private_gpt/components/chat/processors/chat_history/memory/tldr_processor.py:159
condensation_timeout,
**kwargs,
)
# 4. Build final history with TLDR
condensed_history, condense_blocks = await asyncio.to_thread(
build_condensed_history,
system_messages=system_messages,
conversation_history=conversation_history,
)
current_token_count = await estimate_token_count(
condensed_history,
tokenizer_fn=tokenizer_fn,
message_to_input=message_to_input,
**kwargs,
)
if current_token_count > max_length:
raise ValueError(
"Condensed history exceeds maximum length after applying condensation strategy."
)
logger.debug(
"Applied condensation strategy '%s' to conversation history. "
"Current token count: %d, Available max length: %d, Max length: %d",
strategy_type,
current_token_count,
remaining_max_length,
max_length,
)
yield CondenseResponse(
is_condensed=True,
chat_history=condensed_history,
condense_blocks=condense_blocks,
)
View on GitHub (pinned to 4a030776a3)
Solutions
- Increase max_length so remaining budget after system messages fits a typical summary
- Lower the number of recent messages retained by the strategy
- Cap the summary output length in the strategy's LLM prompt
- Shrink the system prompt to free budget (see also error 41)
Example fix
# before condensed = build_condensed_history(system_messages, strategy_result) # may exceed max_length # after condensed = build_condensed_history(system_messages, strategy_result) assert await estimate_token_count(condensed, ...) <= max_length
Defensive patterns
Strategy: fallback
Validate before calling
remaining = max_length - system_token_count
if remaining < min_summary_budget:
raise ConfigError(f"only {remaining} tokens left for condensed history") Try / catch
try:
async for resp in condense(...):
...
except ValueError as e:
if "exceeds maximum length after applying" in str(e):
# fall back to hard truncation of the condensed history
condensed = condensed[:keep_last_n]
else:
raise Prevention
- Cap summary length in the strategy's prompt
- Retain fewer recent turns when the system prompt grows
- Monitor remaining_max_length vs actual condensed size in debug logs
When it happens
Trigger: Running the tldr condense flow where system_token_count < max_length (passes error 41) but system + condensed history > max_length; the remaining_max_length given to the strategy is too small for the summary it generates.
Common situations: Large system prompt leaving a tiny remaining budget; an LLM-generated TLDR summary longer than the space left; aggressive keep-last-N strategy with many retained turns.
Related errors
- Condensed chat history exceeds maximum length after applying
- System messages alone exceed the maximum length. Cannot cond
- No user messages found in the chat history.
- Maximum number of iterations for condensing exceeded.
- The last user message exceeds the maximum length allowed.
AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15).
Data as JSON: /api/errors/451f41e892f321aa.
Report an issue: GitHub.