Skip to main content
The genai_extract_assistant_response function extracts the assistant’s response from a GenAI messages array. It returns the content of the last message with the ‘assistant’ role, which typically contains the AI model’s generated response to the user. You can use this function to analyze AI responses, evaluate response quality, perform sentiment analysis on AI outputs, or track specific response patterns for monitoring and debugging.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
In Splunk SPL, you would need to use complex eval statements with mvfilter and mvindex to extract assistant messages.
In ANSI SQL, you would need to unnest arrays, filter by role, and select the last message, which is more verbose.

Usage

Syntax

Parameters

Returns

Returns a string containing the content of the last assistant message in the conversation, or an empty string if no assistant message is found.

Example

Extract the assistant’s response from a GenAI conversation. Query
Run in Playground Output This query extracts AI responses, helping you analyze response quality and patterns.