If the HTTP response is HTML code, it is highly recommended to use a template engine like https://jinja.palletsprojects.com/[Jinja] to generate it.
This template engine separates the view from the business logic and automatically encodes the output of variables, drastically reducing the risk of cross-site scripting vulnerabilities.
If you do not intend to send HTML code to clients, the vulnerability can be fixed by specifying the type of data returned in the response with the `content-type` HTTP header.
This HTTP header tells the client browser that the response does not contain HTML code and should not be parsed and interpreted as HTML.
Thus, the response is not vulnerable to reflected cross-site scripting.
For example, setting the content-type header to `text/plain` allows to safely reflect user input because browsers will not try to parse and execute the response.