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:
escape_xml/escape_xml_attributeescape a whole string.escape_xml_body_boundedescapes while capping the output at a byte budget, appending a caller-supplied truncation marker (wording is consumer-specific, the arithmetic is shared).
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
valueinto an XML body capped atmax_bytes, appendingtruncation_markerwhen 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).