Search RU
Tasks / AI / LLM / Source citation in a RAG answer
Statement medium

Source citation in a RAG answer

`has_citation(answer, sources)` checks that the answer references at least one
source from the list.

Rules:

- the comparison is case-insensitive;
- empty strings in `sources` are ignored;
- if there are no sources — `False`.

Write tests for this function. It is an example of checking a RAG answer without
calling the model: the answer itself is non-deterministic, while the invariant is
an ordinary function.

AIRAGcitation
test_solution.py Python 3.14
AI mentor

The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.

Log in and ask
Hints 1 of 3 unlocked · attempts: 0
Hint 1

What exactly counts as a reference: an exact match, a substring, or a separate
marker? Start with that decision.

Hint 2 — unlocks after 1 attempt
Hint 3 — unlocks after 3 attempts