Rendering AI Output Safely
Turn a model's streamed Markdown into a safe, fast screen: half-finished marks, code blocks, untrusted links and images, long answers, sources and reasoning.
A model does not send a web page. It sends text, and that text is written by a machine that has read the whole internet, your documents, and whatever the user typed. This phase is about the moment that text reaches the screen: how to draw Markdown while it is still arriving, and how to do it without ever giving the text a chance to act.
You will build a small Markdown renderer by hand so that every rule is visible, then meet the real tools (react-markdown, Streamdown, DOMPurify, Shiki) and learn what each one does for you. You will handle code blocks and copy buttons, links and images that can leak data, very long answers, citations to sources, and the model's visible reasoning.
The phase ends by upgrading Mitra, the shop assistant, so its answers are formatted, safe and sourced. Everything here is defensive: the threats are described, detected and blocked, with harmless stand-ins instead of working attacks.
Practise this phase
Hands-on exercises: write the code, see your page live, and press Check to have it tested automatically.