Skip to main content
Triggered when a response contains an unrecognized or user_defined response type. Use this event to render custom UI elements for specialized content types that are not natively supported by the chat widget. The userDefinedResponse event enables the following use cases:
  1. Custom response types: Handle any unrecognized response types with custom rendering logic.
  2. Tool-generated widgets: Render custom widgets returned by tools that use the user_defined response type. For more information, see Structuring custom widgets.
The user_defined response type from tools is supported only in embedded chat. The webpage builder is responsible for implementing the rendering logic.

Event properties

type
string
required
Always 'userDefinedResponse'.
contentItem
object
required
The individual message item with the user_defined response type. This might contain the widget data directly or reference it from the message’s _meta field.
contentItem.text
string
Text content of the item, if any.
contentItem.user_defined
object
Widget data when provided directly in the content item. This approach is still fully supported alongside the new _meta approach for tool-generated widgets.
message
object
required
The complete message containing the user-defined response item.
message._meta
object
Metadata field that might contain widget data under com.ibm.orchestrate/widget. Use this approach for tool-generated widgets.
message._meta['com.ibm.orchestrate/widget']
object
Widget metadata object containing the user_defined widget data.
message._meta['com.ibm.orchestrate/widget'].response_type
string
Must be 'user_defined' for custom widgets.
message._meta['com.ibm.orchestrate/widget'].user_defined
object
The actual widget data object containing all custom properties.
hostElement
HTMLElement
required
The DOM element where you can insert custom content. Use this to render your custom widget HTML.

Structuring custom widgets

Custom widgets in tool responses is a custom solution that operates independently of standardized UI protocols such as MCP-UI or A2UI. Application builders are responsible for implementing the rendering logic and managing security considerations.
When a tool returns a user_defined widget, the data is available in the _meta field. For information on how to create tools that return user_defined widgets, including code examples and structure requirements, see Custom widgets with user_defined.

Widget data location

You can find the widget data in multiple locations depending on the implementation:
  1. Direct content approach: event.contentItem.user_defined
    Use when widget data is provided directly in the content item.
  2. Tool-generated widgets: event.message._meta['com.ibm.orchestrate/widget'].user_defined
    Use when tools return widgets through the _meta parameter.
You can check all locations to ensure compatibility with both approaches, for example:

State persistence

When loading from message history, the system automatically filters widgets from the content array to prevent duplicate rendering. The system preserves the widget data in message_state for reference, ensuring that widget information remains available for context without causing duplicate UI elements.

Examples

The following example demonstrates rendering a custom HTML card with structured content and interactive elements for handling user-defined response type.
The following example demonstrates how to handle custom widgets returned by tools through the _meta field. The handler extracts widget data from multiple possible locations in the event object, normalizes the properties with fallback values, renders a fully styled custom widget with interactive elements, and includes a fallback for cases where widget data is unavailable.

Do you need practical examples?

Learn how to apply the features available for embedded chat into your implementation with guidance and examples.