home-assistant/core · error · HomeAssistantError

response_not_found

Error message

response_not_found

What it means

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.

Source

Thrown at homeassistant/components/anthropic/ai_task.py:64

    _attr_supported_features = (
        ai_task.AITaskEntityFeature.GENERATE_DATA
        | ai_task.AITaskEntityFeature.SUPPORT_ATTACHMENTS
    )
    _attr_translation_key = "ai_task_data"

    @override
    async def _async_generate_data(
        self,
        task: ai_task.GenDataTask,
        chat_log: conversation.ChatLog,
    ) -> ai_task.GenDataTaskResult:
        """Handle a generate data task."""
        await self._async_handle_chat_log(
            chat_log, task.name, task.structure, max_iterations=1000
        )

        if not isinstance(chat_log.content[-1], conversation.AssistantContent):
            raise HomeAssistantError(
                translation_domain=DOMAIN, translation_key="response_not_found"
            )

        text = chat_log.content[-1].content or ""

        if not task.structure:
            return ai_task.GenDataTaskResult(
                conversation_id=chat_log.conversation_id,
                data=text,
            )
        try:
            data = json_loads(text)
        except JSONDecodeError as err:
            _LOGGER.error(
                "Failed to parse JSON response: %s. Response: %s",
                err,
                text,
            )

View on GitHub (pinned to 58a3fdb3ea)

Solutions

  1. Inspect chat_log.content to see which content type is last and why no assistant turn followed it
  2. Ensure tool results are always appended after tool calls so the model gets a chance to answer
  3. Retry the task; transient model stop-on-tool-call behavior can resolve on a new run
Defensive patterns

Strategy: type-guard

Type guard

from homeassistant.components import conversation

def has_assistant_response(chat_log: conversation.ChatLog) -> bool:
    return isinstance(chat_log.content[-1], conversation.AssistantContent)

Try / catch

try:
    await agent.generate_data(...)
except HomeAssistantError as err:
    if err.translation_key == "response_not_found":
        # retry the task on a fresh conversation
        ...

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of home-assistant/core@58a3fdb3ea (2026-08-14). Data as JSON: /api/errors/fceba0af78cd167f. Report an issue: GitHub.