How to convert raw string to structured text using trados api

I'm developing a batch task that call segments source and target to python file and replace returned text as translation.
program runs fine when using simple text but for formatted text or texts with link, it treats markup text as string not tags like:

returning "sample <cf bold=True>text</cd>" as text lead to "sample <cf bold=True>text</cd>" in translation not "sample text"

in other word I want to use built-in function that parse raw strings to nicely structured text.

currently the batch task uses  ItemFactory.CreateText(ItemFactory.PropertiesFactory.CreateTextProperties("Result")) to replace translation.

what function should I call after receiving the result that solve this problem?