# Error URL: /docs/primitives/error Accessible error display for messages with automatic error text extraction. The Error primitive renders error states on messages using an accessible `role="alert"` container with automatic error text extraction. `Root` always renders its container; `Message` only renders when the message has an error. Wrap in `MessagePrimitive.Error` if you need the entire block to be conditional. ```tsx import { ErrorPrimitive, MessagePrimitive } from "@assistant-ui/react"; function AssistantMessage() { return ( ); } ``` Quick Start \[#quick-start] A minimal error display below a message: ```tsx import { ErrorPrimitive, MessagePrimitive } from "@assistant-ui/react"; ``` `Root` renders a `
` with `role="alert"` for screen reader accessibility. `Message` renders a `` that auto-reads the error text from message state, and it returns `null` when there is no error. `Root` itself always renders. Wrap in `` if you want the entire block (including `Root`) to be conditional. ErrorPrimitive must be placed inside a `MessagePrimitive.Root` because it reads the error state from the nearest message context. Runtime setup: primitives require runtime context. Wrap your UI in `AssistantRuntimeProvider` with a runtime (for example `useLocalRuntime(...)`). See [Pick a Runtime](/docs/runtimes/pick-a-runtime). Core Concepts \[#core-concepts] Auto-Rendering on Error \[#auto-rendering-on-error] `Message` checks the message status and only renders when `status.type === "incomplete"` and `status.reason === "error"`. `Root` always renders its `
` container. For fully conditional rendering, wrap in ``. Automatic Error Text \[#automatic-error-text] `ErrorPrimitive.Message` reads the error object from message state and converts it to a string. If you pass `children`, they override the automatic text: ```tsx // Auto-reads error text from state // Custom children override the default Something went wrong. Please try again. ``` ErrorPrimitive vs MessagePrimitive.Error \[#errorprimitive-vs-messageprimitiveerror] `MessagePrimitive.Error` is a simpler alternative. It renders its children when the message has an error but does not provide `role="alert"` or auto-extract the error text. Use `ErrorPrimitive` when you want accessible error rendering with automatic text. ```tsx // ErrorPrimitive: accessible, auto-reads error text // MessagePrimitive.Error: simpler, manual text
Something went wrong.
``` Parts \[#parts] Root \[#root] Container for an error message block. Renders a `
` element unless `asChild` is set. ```tsx ``` Message \[#message] Renders the current error text for the active message. ```tsx ``` Patterns \[#patterns] Styled Error Alert \[#styled-error-alert] ```tsx ``` Custom Error Content \[#custom-error-content] ```tsx

Error

``` Relationship to Components \[#relationship-to-components] The shadcn [Thread](/docs/ui/thread) component uses `ErrorPrimitive` inside its `AssistantMessage` to display errors below the message content. If you need a pre-built error display, start there. API Reference \[#api-reference] For full prop details on every part, see the [ErrorPrimitive API Reference](/docs/api-reference/primitives/error). Related: * [MessagePrimitive API Reference](/docs/api-reference/primitives/message)