{"record":{"id":"e68758aeb6ca00c9","repo":"home-assistant/core","slug":"system-message-not-found","errorCode":null,"errorMessage":"system_message_not_found","messagePattern":"system_message_not_found","errorType":"exception","errorClass":"HomeAssistantError","httpStatus":null,"severity":"error","filePath":"homeassistant/components/anthropic/entity.py","lineNumber":946,"sourceCode":"        chat_log: conversation.ChatLog,\n        structure_name: str | None = None,\n        structure: vol.Schema | None = None,\n    ) -> tuple[MessageCreateParamsStreaming, str | None]:\n        \"\"\"Get the model arguments.\"\"\"\n        options: dict[str, Any] = DEFAULT | self.subentry.data\n\n        preloaded_tools = [\n            \"HassTurnOn\",\n            \"HassTurnOff\",\n            \"GetLiveContext\",\n            \"code_execution\",\n            \"web_search\",\n            \"web_fetch\",\n        ]\n\n        system = chat_log.content[0]\n        if not isinstance(system, conversation.SystemContent):\n            raise HomeAssistantError(\n                translation_domain=DOMAIN, translation_key=\"system_message_not_found\"\n            )\n\n        messages, container_id = _convert_content(chat_log.content[1:])\n\n        model = options[CONF_CHAT_MODEL]\n\n        model_args = MessageCreateParamsStreaming(\n            model=model,\n            messages=messages,\n            max_tokens=options[CONF_MAX_TOKENS],\n            system=system.content,\n            stream=True,\n            container=container_id,\n        )\n\n        if options[CONF_PROMPT_CACHING] == PromptCaching.PROMPT:\n            model_args[\"system\"] = [","sourceCodeStart":928,"sourceCodeEnd":964,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/anthropic/entity.py#L928-L964","documentation":"A HomeAssistantError with translation key 'system_message_not_found' raised when chat_log.content[0] is not a conversation.SystemContent instance. The Anthropic entity requires the first chat log item to be the system prompt, which it passes separately as the 'system' parameter of MessageCreateParamsStreaming.","triggerScenarios":"Invoking _async_handle_chat_log with a chat log whose first element is a user or assistant message — e.g. a caller built the ChatLog without async_add_content sequencing a system prompt first, or the system prompt was stripped.","commonSituations":"Custom scripts or integrations constructing a conversation.ChatLog manually and forgetting the system message; resuming a conversation_id whose stored history lacks the leading SystemContent.","solutions":["Ensure chat_log.async_add_content is first called with SystemContent (agent's instructions) before user turns","Start a fresh conversation rather than resuming one whose stored history is missing the system block","Update to the matching core version if the ChatLog construction API changed"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from homeassistant.components import conversation\n\ndef starts_with_system(chat_log: conversation.ChatLog) -> bool:\n    return bool(chat_log.content) and isinstance(chat_log.content[0], conversation.SystemContent)","typeGuard":null,"tryCatchPattern":"system = chat_log.content[0]\nif not isinstance(system, conversation.SystemContent):\n    raise HomeAssistantError(translation_domain=DOMAIN, translation_key=\"system_message_not_found\")","preventionTips":["Add SystemContent as the first chat log item when constructing a ChatLog","Do not resume conversations whose persisted history lost the leading system block"],"tags":["home-assistant","anthropic","chat-log","system-prompt"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}