{"record":{"id":"3a4f32ecd6542a80","repo":"zylon-ai/private-gpt","slug":"tldr-blocks-can-only-be-used-in-assistant-messages","errorCode":null,"errorMessage":"TLDR blocks can only be used in assistant messages: {message}","messagePattern":"TLDR blocks can only be used in assistant messages: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":422,"severity":"error","filePath":"private_gpt/server/chat/chat_models.py","lineNumber":410,"sourceCode":"                    elif isinstance(block, ToolUseBlock):\n                        if message.role != \"assistant\":\n                            raise ValueError(\n                                f\"Tool use blocks can only be used in assistant messages: {message}\"\n                            )\n                        if block.id in tool_uses_ids:\n                            raise ValueError(f\"Duplicate tool use ID found: {block.id}\")\n                        tool_uses_ids.add(block.id)\n\n                    elif isinstance(block, ToolResultBlock):\n                        if block.tool_use_id not in tool_uses_ids:\n                            raise ValueError(\n                                f\"Tool result block references an unknown tool use ID: {block.tool_use_id}\"\n                            )\n                        tool_results_ids.add(block.tool_use_id)\n\n                    elif isinstance(block, TLDRBlock):\n                        if message.role != \"assistant\":\n                            raise ValueError(\n                                f\"TLDR blocks can only be used in assistant messages: {message}\"\n                            )\n\n        if tool_results_ids != tool_uses_ids:\n            raise ValueError(\n                \"Tool result blocks must match the tool use IDs in the same message.\"\n                f\" Found tool use IDs: {tool_uses_ids}, but tool result IDs: {tool_results_ids}\"\n            )\n\n        return self\n","sourceCodeStart":392,"sourceCodeEnd":421,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/server/chat/chat_models.py#L392-L421","documentation":"Raised while validating ChatMessages: a TLDRBlock (extended content block for conversation summaries) was found in a message whose role is not 'assistant'. TLDR blocks are only meaningful as part of assistant output, so the validator enforces role == 'assistant' for any message containing one.","triggerScenarios":"Building a ChatMessages payload that puts a TLDRBlock into a 'user' or 'system' role message content list; e.g. a client trying to pre-seed a summary block on the user turn.","commonSituations":"Custom clients using the extended block protocol who assume summary blocks go with user context; copy-pasting block arrays between messages of different roles.","solutions":["Move the TLDRBlock into an assistant-role message","If you want to provide context/summary on the user side, send it as a plain text block instead of TLDRBlock"],"exampleFix":"# before\n{\"role\": \"user\", \"content\": [{\"type\": \"tldr\", \"text\": \"summary...\"}]}\n\n# after\n{\"role\": \"assistant\", \"content\": [{\"type\": \"tldr\", \"text\": \"summary...\"}]}","handlingStrategy":"type-guard","validationCode":"for m in messages:\n    for b in (m.content or []):\n        if isinstance(b, TLDRBlock) and m.role != \"assistant\":\n            raise ValueError(\"move TLDRBlock to an assistant message\")","typeGuard":"def tldr_blocks_in_assistant_messages(messages: list) -> bool:\n    for m in messages:\n        role = m.get(\"role\") if isinstance(m, dict) else m.role\n        blocks = m.get(\"content\", []) if isinstance(m, dict) else (m.content or [])\n        if any((b.get(\"type\") if isinstance(b, dict) else getattr(b, \"type\", None)) == \"tldr\" for b in blocks) and role != \"assistant\":\n            return False\n    return True","tryCatchPattern":"try:\n    ChatMessages(messages=msgs)\nexcept ValueError as e:\n    if \"TLDR blocks\" in str(e):\n        move_tldr_blocks_to_assistant(msgs)\n    else:\n        raise","preventionTips":["Only emit TLDR blocks on assistant turns","Send user-side summaries as plain text blocks"],"tags":["chat","content-blocks","validation"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}