Can Digital Experience Chatbots Parse HTML?

Can Digital Experience Chatbots Parse HTML?

On June 4, 2025, Posted by , In Salesforce, By ,,, , With Comments Off on Can Digital Experience Chatbots Parse HTML?

Question

We are using Prompt Builder to generate outputs in abridged HTML format to be written into Salesforce records with long rich text area fields. The HTML formatting ensures that the output appears correctly when stored and viewed in Salesforce.

However, in the near future, we also need this information to be displayed properly in the agent’s response within a Digital Experience site—without exposing raw HTML tags. Based on our testing, prompt outputs in Digital Experience currently appear as plain text, meaning HTML tags and elements are displayed as raw text rather than being parsed for formatting.

Our key question is:

  • Can the agent be configured (or the prompt crafted) to parse or ignore HTML before outputting text directly into the Digital Experience chat, ensuring the content is formatted correctly?
  • Or will we need to maintain separate prompts—one for Digital Experience (plain text output) and another for writing to records (rich text with HTML formatting)?
  • Alternatively, is there another approach that would allow us to dynamically determine the correct format without duplicating prompts?

We are triggering the prompt using Flow but do not currently have a way to let the prompt “know” whether its output will be viewed in the chatbot or as stored content in a record. Any guidance on how to best handle this scenario would be greatly appreciated.

Answer

The key challenge here is ensuring that the same prompt output can be used both in a Salesforce record (where HTML formatting is needed) and in a Digital Experience chatbot (where raw HTML should not be displayed). Below are potential solutions and their explanations.

1. Can the Agent Parse HTML in Digital Experience?

No, out-of-the-box Salesforce bots in Digital Experience currently display prompt output as plain text, meaning any included HTML tags will be shown as raw text rather than being parsed for formatting. This behavior occurs because:

The Digital Experience chatbot does not automatically interpret HTML.
Unlike rich text areas in Salesforce records, the chatbot output is not designed to render HTML elements.

Since the chatbot does not support HTML rendering natively, you cannot rely on a single formatted prompt expecting HTML to be properly displayed in both contexts.

2. Possible Solutions

Option 1: Use Conditional Formatting with Flow or Custom Logic

Since you are triggering the prompt via Flow, you could introduce a mechanism to detect whether the output will be stored in a rich text field (which supports HTML) or displayed in the chatbot (which does not). A few ways to implement this:

Custom Flow Variables: Add a Flow variable that determines the output context (Chatbot vs. Record Storage). Use this to apply different formatting before calling the prompt.

Custom Apex Action: If Flow alone cannot determine the context, an Apex action could detect whether the response is being sent to Digital Experience and strip HTML accordingly.

Implementation Approach:

  1. For record storage, store the full HTML-formatted text in the long rich text field.
  2. For chatbot output, use a helper function to strip HTML before sending it to the Digital Experience agent.

In Apex (or Flow), you can remove HTML with a regex like:

String plainText = myHtmlOutput.replaceAll('<.*?>', '');

If using Flow, you can use the Text Template element to handle basic stripping.
Pros: No need to maintain duplicate prompts.
Cons: Requires customization via Flow or Apex.

Option 2: Create Two Versions of the Prompt

If dynamically determining the output format is not feasible, a simple alternative is to maintain two separate prompts:
One prompt outputs HTML for storage in Salesforce records.
Another prompt outputs plain text for chatbot use.

This would involve:
Using Flow to select which prompt to call based on context.
Ensuring prompt variations are kept in sync when updates are needed.

Pros: Simple to implement with minimal technical effort.
Cons: Duplicating prompts requires additional maintenance.

Option 3: Post-Processing HTML in the Chatbot

If the chatbot framework supports custom pre-processing, you might be able to configure the Digital Experience agent to interpret basic HTML. However, Salesforce’s Digital Experience bot does not have built-in HTML rendering, so this would likely require:

A custom Lightning Web Component (LWC) to process and format the response before displaying it.
Using JavaScript within Digital Experience pages to strip or process HTML dynamically before showing the output.

Pros: Future-proof if HTML rendering is needed later.
Cons: Requires customization in the Digital Experience environment.

3. Best Approach for Your Scenario

Based on your setup (using Flow to trigger prompts), the best balance between effort and maintainability would be Option 1 (Conditional Formatting via Flow or Apex). This allows a single prompt to be used, with minor modifications applied dynamically.

If customization is limited, Option 2 (Separate Prompts) is a simple, low-effort alternative.
If Salesforce improves chatbot HTML handling in the future, Option 3 (Post-Processing in Digital Experience) may become viable.

Currently, Salesforce Digital Experience chatbots do not parse HTML, meaning HTML tags will be displayed as raw text. To handle this:

If customization in Digital Experience is possible, explore pre-processing HTML in a custom LWC or JavaScript.
Use Flow logic or Apex to determine the output context and apply appropriate formatting.
If conditional logic is not feasible, maintain two separate prompts (one for chatbot, one for records).

Enroll for Career-Building Salesforce Training with 100% Money Back Guarantee

Our Salesforce Course is structured to give you a deep understanding of the Salesforce platform, equipping you with the essential skills to excel in the CRM industry. The curriculum covers vital modules like Salesforce Admin, Developer, and AI, integrating theoretical knowledge with hands-on practice. By working on real-world projects and practical assignments, you will gain the expertise needed to solve complex business challenges using Salesforce solutions. Our experienced trainers ensure you develop both technical proficiency and industry insights to succeed in the Salesforce ecosystem.

In addition to technical skills, our Salesforce Training in New York provides personalized mentorship, certification assistance, and interview preparation to boost your career prospects. You will have access to extensive study materials, live project experience, and dedicated support throughout your learning journey. By the end of the course, you will be fully prepared for certification exams and equipped with the practical problem-solving abilities that employers value. Begin your Salesforce journey with us and explore a world of exciting career opportunities. Enroll in a Free Demo today!

Comments are closed.