{"record":{"id":"285afca7c24b2996","repo":"zylon-ai/private-gpt","slug":"chat-history-contains-multiple-user-blocks-this-i","errorCode":null,"errorMessage":"Chat history contains multiple user blocks. This is not supported.","messagePattern":"Chat history contains multiple user blocks\\. This is not supported\\.","errorType":"exception","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"private_gpt/components/chat/processors/chat_history/memory/utils/repairs.py","lineNumber":209,"sourceCode":"            )\n\n\ndef _assert_only_one_user_block(\n    chat_history: list[ChatMessage],\n) -> None:\n    \"\"\"Assert that the chat history contains exactly one user block.\n\n    This is used to ensure that the chat history\n    is clean and contains only one user block.\n    \"\"\"\n    if not chat_history:\n        return\n\n    matrix = get_user_blocks(chat_history)\n    if not matrix:\n        raise ValueError(\"Chat history does not contain any user messages.\")\n    if len(matrix) > 1:\n        raise ValueError(\n            \"Chat history contains multiple user blocks. This is not supported.\"\n        )\n","sourceCodeStart":191,"sourceCodeEnd":212,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/chat/processors/chat_history/memory/utils/repairs.py#L191-L212","documentation":"Raised by _assert_only_one_user_block when the history splits into more than one user block (multiple user turns separated by assistant replies). repair_with_tools is a single-turn reduction — it only accepts one user block — so multi-turn conversations must be reduced (e.g. condensed) before this repair path.","triggerScenarios":"Calling repair_with_tools() on a full multi-turn conversation containing two or more user messages with assistant replies between them.","commonSituations":"Feeding an entire chat session into the tools path without prior condensation; a session loader appending prior turns; conflating repair_with_tools with the general repair_without_tools path (which tolerates multiple blocks).","solutions":["Condense/trim history to the last user block before calling repair_with_tools()","Use repair_without_tools() if multiple blocks are expected and tools are absent","Split the session into per-turn requests and repair only the current turn"],"exampleFix":"# before\nrepaired = repair_with_tools(conversation_messages)\n\n# after\n# keep only the last user block\nfrom private_gpt.components.chat.processors.chat_history.memory.utils.splitting import get_user_blocks\nblocks = get_user_blocks(conversation_messages)\nrepaired = repair_with_tools(blocks[-1])","handlingStrategy":"validation","validationCode":"blocks = get_user_blocks(conversation_messages)\nif len(blocks) > 1:\n    conversation_messages = blocks[-1]  # reduce to the last user block before repair_with_tools","typeGuard":"def is_single_user_block(history: list[ChatMessage]) -> bool:\n    return len(get_user_blocks(history)) <= 1","tryCatchPattern":"try:\n    repaired = repair_with_tools(conversation_messages)\nexcept ValueError as e:\n    if \"multiple user blocks\" in str(e):\n        repaired = repair_with_tools(get_user_blocks(conversation_messages)[-1])\n    else:\n        raise","preventionTips":["Condense multi-turn sessions to the last user block before the tools repair path","Use repair_without_tools for general multi-turn histories","Document the single-block contract of repair_with_tools at its call sites"],"tags":["chat-history","validation","repair","multi-turn"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}