{"record":{"id":"fceba0af78cd167f","repo":"home-assistant/core","slug":"response-not-found","errorCode":null,"errorMessage":"response_not_found","messagePattern":"response_not_found","errorType":"exception","errorClass":"HomeAssistantError","httpStatus":null,"severity":"error","filePath":"homeassistant/components/anthropic/ai_task.py","lineNumber":64,"sourceCode":"    _attr_supported_features = (\n        ai_task.AITaskEntityFeature.GENERATE_DATA\n        | ai_task.AITaskEntityFeature.SUPPORT_ATTACHMENTS\n    )\n    _attr_translation_key = \"ai_task_data\"\n\n    @override\n    async def _async_generate_data(\n        self,\n        task: ai_task.GenDataTask,\n        chat_log: conversation.ChatLog,\n    ) -> ai_task.GenDataTaskResult:\n        \"\"\"Handle a generate data task.\"\"\"\n        await self._async_handle_chat_log(\n            chat_log, task.name, task.structure, max_iterations=1000\n        )\n\n        if not isinstance(chat_log.content[-1], conversation.AssistantContent):\n            raise HomeAssistantError(\n                translation_domain=DOMAIN, translation_key=\"response_not_found\"\n            )\n\n        text = chat_log.content[-1].content or \"\"\n\n        if not task.structure:\n            return ai_task.GenDataTaskResult(\n                conversation_id=chat_log.conversation_id,\n                data=text,\n            )\n        try:\n            data = json_loads(text)\n        except JSONDecodeError as err:\n            _LOGGER.error(\n                \"Failed to parse JSON response: %s. Response: %s\",\n                err,\n                text,\n            )","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/anthropic/ai_task.py#L46-L82","documentation":"A HomeAssistantError with translation key 'response_not_found' raised in the Anthropic ai_task generate-data path. After up to 1000 iterations of _async_handle_chat_log, the code asserts the last entry in chat_log.content is an AssistantContent block; if the last item is instead a user message or tool call/result, the model never produced a final assistant answer.","triggerScenarios":"Calling _async_generate_data where the conversation loop terminated without a trailing assistant turn — e.g. the LLM ended on a tool call that produced no result, the chat log was mutated externally, or the stream aborted mid-iteration leaving a UserContent/tool item last.","commonSituations":"Structured data generation tasks (GenDataTask with a JSON schema) where the model loops on tool use, or an upstream library change that appends different content types to chat_log.","solutions":["Inspect chat_log.content to see which content type is last and why no assistant turn followed it","Ensure tool results are always appended after tool calls so the model gets a chance to answer","Retry the task; transient model stop-on-tool-call behavior can resolve on a new run"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"from homeassistant.components import conversation\n\ndef has_assistant_response(chat_log: conversation.ChatLog) -> bool:\n    return isinstance(chat_log.content[-1], conversation.AssistantContent)","tryCatchPattern":"try:\n    await agent.generate_data(...)\nexcept HomeAssistantError as err:\n    if err.translation_key == \"response_not_found\":\n        # retry the task on a fresh conversation\n        ...","preventionTips":["Always append tool results so the loop can end with an assistant turn","Cap iterations and inspect chat_log.content shape when extending the ai_task flow"],"tags":["home-assistant","anthropic","ai-task","chat-log"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}