zylon-ai/private-gpt · error · ValueError

Chat history does not contain any user messages.

Error message

Chat history does not contain any user messages.

What it means

Raised by _assert_only_one_user_block (used by repair_with_tools) when get_user_blocks returns an empty matrix on a non-empty history: there are messages, but none of them is a user message, so no user block can be formed. repair_with_tools expects exactly one user block, so it aborts.

Source

Thrown at private_gpt/components/chat/processors/chat_history/memory/utils/repairs.py:207

            raise ValueError(
                f"Chat history contains a tool message: {message.content}. Reason: {reason or 'Unknown'}"
            )


def _assert_only_one_user_block(
    chat_history: list[ChatMessage],
) -> None:
    """Assert that the chat history contains exactly one user block.

    This is used to ensure that the chat history
    is clean and contains only one user block.
    """
    if not chat_history:
        return

    matrix = get_user_blocks(chat_history)
    if not matrix:
        raise ValueError("Chat history does not contain any user messages.")
    if len(matrix) > 1:
        raise ValueError(
            "Chat history contains multiple user blocks. This is not supported."
        )

View on GitHub (pinned to 4a030776a3)

Solutions

  1. Ensure the history passed to repair_with_tools contains a user message
  2. Fix upstream splitting so user messages stay in conversation history
  3. Prepend a user message if the pipeline requires one to exist

Example fix

# before
repaired = repair_with_tools(conversation_messages)

# after
if not any(m.role == "user" for m in conversation_messages):
    conversation_messages = [ChatMessage(role=MessageRole.USER, content="(query)")] + conversation_messages
repaired = repair_with_tools(conversation_messages)
Defensive patterns

Strategy: validation

Validate before calling

if conversation_messages and not any(m.role == "user" for m in conversation_messages):
    raise ValueError("cannot repair_with_tools without a user message")

Type guard

def has_user_message(history: list[ChatMessage]) -> bool:
    return any(m.role == "user" for m in history)

Try / catch

try:
    repaired = repair_with_tools(conversation_messages)
except ValueError as e:
    if "does not contain any user messages" in str(e):
        conversation_messages = [ChatMessage(role=MessageRole.USER, content="(query)")] + conversation_messages
        repaired = repair_with_tools(conversation_messages)
    else:
        raise

Prevention

When it happens

Trigger: Calling repair_with_tools() on a conversation containing only assistant/system messages, or where all user messages were filtered/misrouted away upstream.

Common situations: System-prompt classification pulling the user message into system_messages; histories loaded with the user turn dropped; test fixtures built without a user message.

Related errors


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