Answering With Citations

grounded answers with file:line refs

Part of: Codebase Assistant

A code assistant that answers confidently but won't say where the answer came from is a black box. This lesson wires retrieval into a prompt that forces every claim to point at a real file and line range. What we're building Given a user's question and the top-ranked chunks from lesson 4, assemble a context block that labels every chunk with its citation, then tell the model to answer only from that context and cite the file:line range for every fact it states. Building the context block Each retrieved chunk already has an id like src/app.py:3-5 from lesson 3. Format them into a labeled block the model can read and refer back to: The system prompt does the grounding Two rules do the work. "Answer only from context" stops the model from inventing plausible-looking code it never saw. "Cite in brackets" gives you a citation format you can check in code later. Parsing citations back out Once the reply comes back, pull the citations out of the text so you can display them, or verify them in a later lesson: Why it matters Citations turn a code assistant from "trust me" into "check me." A user who reads [src/auth.py:40-52] in an answer can jump straight to that function and verify the cla

Challenge: Extract Citations From an Answer