{"record":{"id":"0710a1c36500a0ba","repo":"rohitg00/ai-engineering-from-scratch","slug":"user-text-must-not-be-empty","errorCode":null,"errorMessage":"user_text must not be empty","messagePattern":"user_text must not be empty","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/08-messages-api-and-application-lifecycle/code/main.py","lineNumber":88,"sourceCode":"\nclass MessageLifecycle:\n    \"\"\"Own conversation state and advance it until the model ends the turn.\"\"\"\n\n    def __init__(\n        self,\n        transport: ScriptedTransport,\n        tools: dict[str, Callable[[dict[str, Any]], Any]] | None = None,\n        max_turns: int = 8,\n    ) -> None:\n        if max_turns < 1:\n            raise ValueError(\"max_turns must be positive\")\n        self.transport = transport\n        self.tools = tools or {}\n        self.max_turns = max_turns\n\n    def run(self, user_text: str) -> RunResult:\n        if not user_text.strip():\n            raise ValueError(\"user_text must not be empty\")\n        messages: list[dict[str, Any]] = [\n            {\"role\": \"user\", \"content\": [{\"type\": \"text\", \"text\": user_text}]}\n        ]\n\n        for turn in range(1, self.max_turns + 1):\n            response = self.transport.create(messages)\n            blocks = _validated_blocks(response)\n            stop_reason = response.get(\"stop_reason\")\n\n            # The assistant tool_use block must be retained before tool_result.\n            messages.append({\"role\": \"assistant\", \"content\": copy.deepcopy(blocks)})\n\n            if stop_reason == \"end_turn\":\n                return RunResult(_text_from_blocks(blocks), messages, turn)\n            if stop_reason != \"tool_use\":\n                raise ProtocolError(f\"unsupported stop_reason: {stop_reason!r}\")\n\n            tool_results = [self._execute_tool(block) for block in blocks if block[\"type\"] == \"tool_use\"]","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/08-messages-api-and-application-lifecycle/code/main.py#L70-L106","documentation":"Error \"user_text must not be empty\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at certifications/claude/lessons/08-messages-api-and-application-lifecycle/code/main.py:88 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}