Skip to main content
The genai_extract_user_prompt function extracts the user’s prompt from a GenAI messages array. It returns the content of the last message with the ‘user’ role, which typically contains the user’s question or request to the AI. You can use this function to analyze user queries, understand common question patterns, perform sentiment analysis on user inputs, or track user behavior and needs.

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 filter messages by user role and extract the last one.
In ANSI SQL, you would unnest the array, filter by user role, and select the last message.

Usage

Syntax

Parameters

Returns

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

Example

Extract the user’s prompt from a GenAI conversation to analyze common questions. Query
Run in Playground Output This query identifies the most common user questions, helping you understand user needs and improve responses.