Skip to content

Python: Fix HTML-like tags being dropped in ChatHistory.from_rendered_prompt#13659

Open
jgarrison929 wants to merge 1 commit intomicrosoft:mainfrom
jgarrison929:fix/python-html-tag-template-rendering
Open

Python: Fix HTML-like tags being dropped in ChatHistory.from_rendered_prompt#13659
jgarrison929 wants to merge 1 commit intomicrosoft:mainfrom
jgarrison929:fix/python-html-tag-template-rendering

Conversation

@jgarrison929
Copy link

Motivation and Context

Fixes #13632

When a prompt contains valid XML elements like <p>, <div>, <b>, etc., the XML parser in ChatHistory.from_rendered_prompt treats them as elements but silently discards their content.

Description

This PR fixes the issue by serializing unrecognized XML elements back to their string representation using tostring().

After the fix:

  • Prompts with HTML-like tags are preserved exactly as written
  • No change in behavior for prompts using recognized chat message tags

Contribution Checklist

  • The code builds clean without any errors or warnings
  • Tests have been added that prove the fix works
  • All existing tests pass

…_prompt

When a prompt contained valid XML elements like <p>, <div>, etc., the XML
parser in from_rendered_prompt treated them as elements but silently
discarded their content because they weren't recognized as chat message
tags (message, history).

This fix serializes unrecognized elements back to their XML string
representation using tostring(), preserving both the tags and their
content in the final prompt text.

Added regression tests for:
- Single HTML-like tag (<p>)
- Nested HTML-like tags (<div><p>...</p></div>)

Fixes microsoft#13632
@jgarrison929 jgarrison929 requested a review from a team as a code owner March 13, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Bug: HTML tag <p> getting blocked in Semantic Kernel version 1.39.4

1 participant