There are a lot of examples about SQL in comments. In the SQL case you want something like:
def process_template(template: Template) -> tuple[str, tuple]:
sql_parts = []
args = []
for item in template:
if isinstance(item, str):
sql_parts.append(item)
else:
sql_parts.append("?")
args.append(process_value(item.value))
return "".join(sql_parts), tuple(args)
(of course it would be more nuanced, but I hope you get the point)