An answer about refunds is a promise the shop has to keep. So the customer, and the shop's own team, should be able to see where it comes from. Every passage in the prompt already carries its source in its tag, so you can ask the model which ones it used.
Ask for JSON: tell the model to reply with a JSON object that has two keys, answer and sources. json.loads turns that text into a dictionary your code can read. For a bike shop, a reply could look like this:
{"answer": "We are open Monday to Friday, 9 to 17.", "sources": ["hours.md", "holidays.md"]}
But a model can make up a source, the same way it can make up anything else. If the only passages you sent came from hours.md, then holidays.md points nowhere, and it makes the answer look checked when it isn't. You can't stop a model from inventing a name, but you know exactly which sources are real: the ones you sent. So plain code keeps a cited source only if it is one of those. When your own code can verify something the model says, let the code do it.
When your program is finished, it prints the answer with its one real source. Then the check asks two more questions through your function:
Yes, in most cases. You can return any item within 14 days of delivery if it is unused and in its original packaging. Gift cards and items bought on sale can't be returned or refunded. Source: returns.md Do you ship to Canada? -> Yes. Shipping to Canada costs a flat $15 and takes 7 to 10 business days. ['shipping.md'] Can I pay with PayPal? -> Yes, we accept PayPal. ['payments.md'] Calls to the model: 3
Your task: ask the model for JSON in SYSTEM, and make answer(question) return a dictionary with "answer" and "sources", where "sources" holds only the sources of passages that were in the prompt. Then print the answer to "Can I get my money back?" and one Source: line for each source.
Assignment
Follow the Coding Tutorial to get the answer and its sources as JSON, and to drop every source the model made up.
Hint
Write down the real sources in the same loop that builds the prompt, so the list always matches the passages you sent. The model's own list is never handed on as it came: your checked list takes its place.
Free plan: 30 tutor messages. PRO is unlimited.
