Sanitization html output itself

The more elaborate data is, the harder it is to both formulate and implement sanitization process.

For a number this might be as simple as “integer” and (int)$number.

For HTML this is highly not trivial with different possibilities of desired scope (no HTML tags? some blacklisted tags? some whitelisted tags? what about embedded scripts? CSS?) and very challenging implementation.

While WP does have wp_kses() implementing sanitization of HTML, it’s relatively slow and its reputation is less than stellar (or so I read in context of other established sanitization libraries).

I would say that in question as stated, the practical expectation is that function engineered to act as template tag is expected to produce sanitized output.

If you don’t believe it to, it would probably make more sense to audit it (and report any discovered shortcomings to developer) rather than try to sanitize complex output.