Command Palette

Search for a command to run...

Hectal
Phase 10: Security and Privacy (Defensive)
RAG and Vector Search · Exercise 3 of 6 PreviousNext
Intermediate

Wrap retrieved text as data

Write wrap_sources(chunks) where each chunk is a dict with id and text. Return one string with one line per chunk, joined by a newline: <source id="ID">TEXT</source>.

Before putting the text in, escape & as &amp;, then < as &lt; and > as &gt; (in this order), so a passage cannot close the tag or open a new one.

What Check tests

  1. Wraps one chunk
  2. Puts each chunk on its own line
  3. A passage cannot close the tag
  4. Ampersands are escaped first
  5. No chunks gives an empty string

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.