Generative AI · Intermediate level

Intermediate level · Module 6: Retrieval-Augmented Generation Pipelines · Lesson 2 of 3

Grounded Answers with Citations

Learners instruct the model to answer only from passages, cite passage IDs, and decline when the evidence is missing, then check citations automatically.

In this lesson you will

  • Generate answers with passage citations
  • Check citations and refusals automatically

Key concepts

citationpassage IDrefusal rulecitation checkinganswer schema

The lesson

Give each passage an ID and instruct: 'Answer only from the passages. Cite the IDs you used. If the passages do not contain the answer, say so.' Use a Pydantic answer schema with answer, cited_ids and found fields.

Check automatically that every cited ID was among the retrieved passages, and that key numbers or names in the answer appear in the cited passages.

A good refusal names what is missing and where to go next, such as the office to contact.

Step by step

  1. Add passage IDs and an answer schema.
  2. Add citation and refusal rules.
  3. Implement automatic citation checks.
  4. Test with answerable and unanswerable questions.

Practice activity

Add grounded answering with citation checks to the project assistant.

Expected result: Cited answers, correct refusals and citation errors caught automatically.

Check your understanding

  1. How can you check a citation automatically?

    Show answer

    Confirm the cited ID was retrieved and that key facts appear in that passage.

  2. What should the assistant do if the passages lack the answer?

    Show answer

    Say so and point to where to get help.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.