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:
- Custom response types: Handle any unrecognized response types with custom rendering logic.
- Tool-generated widgets: Render custom widgets returned by tools that use the
user_definedresponse 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
Always
'userDefinedResponse'.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.Text content of the item, if any.
Widget data when provided directly in the content item. This approach is still fully supported alongside the new
_meta approach for tool-generated widgets.The complete message containing the user-defined response item.
Metadata field that might contain widget data under
com.ibm.orchestrate/widget. Use this approach for tool-generated widgets.Widget metadata object containing the
user_defined widget data.Must be
'user_defined' for custom widgets.The actual widget data object containing all custom properties.
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.
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:-
Direct content approach:
event.contentItem.user_defined
Use when widget data is provided directly in the content item. -
Tool-generated widgets:
event.message._meta['com.ibm.orchestrate/widget'].user_defined
Use when tools return widgets through the_metaparameter.
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 inmessage_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._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.

