Sometimes it can be useful to include end-user input in a generative AI system prompt. You can do this with both the Generate Text with AI dynamic action, as well as the Show AI Assistant one. We’ll explore two simple APEX 24.2 sample apps that illustrates the respective techniques.
Generating Text with AI from User Input
Imagine you want to let a user find synonyms using a large language model. This is a simple use case for the Generate Text with AI dynamic action, and requires including the original word the user wants alternatives for in the system prompt. As shown below, we can use a P1_BASE_WORD Text Field page item to let the user type a word, and the (Find Synonyms) button to trigger the synonym lookup.

The (Find Synonyms) button has a dynamic action event handler on the Click event whose first True action step uses a Generate Text with AI dynamic action configured as shown below. Notice it includes a simple System Prompt asking the LLM to:
Find ten synonyms for word the user provides marked as <WORD>…</WORD> in a bulleted list formatted in markdown, answer only.
For the Input Value it uses the JavaScript Expression option with an expression that concatenates the $v('P1_BASE_WORD') value of the user’s page item input in between “<WORD>” and “</WORD>” literal strings to make the user input more clear to the LLM. And finally, it uses the response from the AI service by storing it into the hidden page item P1_SYNONYM.

The second dynamic action step uses a Refresh dynamic action to refresh a Dynamic Content region whose function body returning CLOB is the one liner below. The region mentions the P1_SYNONYM hidden page item in its Page Items to Submit property.
return apex_markdown.to_html(:P1_SYNONYM);
That’s the only setup required to get the job done. You can download the Synonym Finder sample app from here to study it further.
Including User Input in a Chatbot
To include user input in a chatbot, use an AI configuration with a RAG source that returns the page item value. The second sample app uses an AI configuration containing a system prompt:
You can only answer questions about fruit.
… and a RAG source with a description of:
Limit your questions to fruit contained in the following list:
… with a corresponding function returning CLOB that looks like the following one-liner:
return :P1_ADDITIONAL_USER_PROMPT;
As shown below, the Additional User Prompt Text Field page item lets the user type in a list of fruits that will influence the system prompt used by the chatbot. This works since the AI configuration’s RAG sources are evaluated before each interchange with the AI Service.
In the quick session I captured in the screenshot, I had first typed in “apples, oranges” into the field and asked the chatbot the first two questions, then I changed the Additional User Prompt field to the value “watermelon, figs” and asked the next question.

Since the APEX engine evaluates the RAG sources on the server side, it’s important to “push” the user-entered Additional User Prompt into server-side session state whenever it changes. This is easy to do using a dynamic action event handler on the text field page item’s Change event. It only needs an Execute Server-side Code dynamic action step with a “no-op” PL/SQL block of:
null;
…along with a Items to Submit property mentioning the P1_ADDITIONAL_USER_PROMPT page item.
The rest of the chatbot interaction is handled automatically by the combination of the following “ingredients” in the recipe:
- A Static Content region on the page with a static id set to
chatbot - A Dynamic action event handler on the page’s Page Load event with a single Show AI Assistant action step.
- This Show AI Assistant action step uses the
my_ai_configurationAI configuration explained above, has Display As set to Inline, and mentions#chatbotas the Container Selector.
As in the first sample, these few steps are the only setup required to get the job done. You can download the RAG Query with User Input sample app from here to study it further.
