Skip to main content

Module untrusted_xml

Module untrusted_xml 

Source
Expand description

XML escaping for untrusted content embedded in model-facing fences.

Tool descriptions, skill instructions, and similar untrusted payloads are wrapped in XML-style fences before being shown to the model. Escaping here is a single-sourced security primitive: every consumer must produce byte-identical escapes so a payload cannot close one consumer’s fence with syntax another consumer would have escaped.

Two flavors exist:

Functions§

escape_xml
Escape every XML-significant and control character in value.
escape_xml_attribute
Escape a value for use inside an XML attribute or text node.
escape_xml_body_bounded
Escape value into an XML body capped at max_bytes, appending truncation_marker when characters had to be dropped. The marker’s byte length is reserved up-front so the closing marker never overflows the budget.
escape_xml_character
Escape one character: the five XML entities, plus control characters outside the ordinary-whitespace set replaced with U+FFFD (XML 1.0 does not allow most control characters; ordinary whitespace stays useful to the model).