Update Callers for Dict Chunks
Exit

Update Callers for Dict Chunks

Fix build_prompt to extract text from dict chunks returned by index_folder

💻

Writing code and entering commands is only available on desktop. Open this page on a larger screen to complete this chapter.

A type mismatch waiting to crash

In Lesson 1, you updated index_folder to return a list of dicts — each with a "text" key and a "source" key. That change made it possible to track which file each chunk came from.

But build_prompt still calls "\n\n".join(context_chunks), which expects plain strings. Passing dicts to str.join raises a TypeError at runtime. You need to extract the text from each dict before joining.

The fix is a generator expression inside join:

context = "\n\n".join(chunk["text"] for chunk in context_chunks)

This iterates over context_chunks, pulls the "text" value from each dict, and joins those strings — one line, no intermediate list.

Instructions

  1. In build_prompt, change context = "\n\n".join(context_chunks) to context = "\n\n".join(chunk["text"] for chunk in context_chunks).