Command Palette

Search for a command to run...

Hectal
PHASE 8Intermediate ~19 min· topic 7 of 9

Topic 8.7

Checking the Answer Against the Sources

In one line

A valid citation does not prove a sentence is supported. Cheap checks in code (content-word overlap, numbers that must appear in the source) catch many unsupported claims, and a judge model gives a second opinion on the sentences that are flagged.

Think of it like this

A fact-checker with an article and a folder of notes. For each sentence they find the note that backs it up. 'The pass costs 25 dollars' is in the notes. 'Riders also get a free helmet' is not in the note that was cited, even if it sounds likely. They put a mark next to every sentence they cannot find. Grounding checks are that mark.

Words you'll meet

New words in this topic, in plain English. Come back here whenever one feels fuzzy.

Grounded
Every claim in the answer can be traced to the sources provided.
Content word
A word that carries meaning, as opposed to very common words like the, a, of.
Overlap
The share of a sentence's content words that appear in a source.
Unsupported claim
A statement the cited source does not contain or contradicts.
False alarm
A correct sentence that a check flags, for example a paraphrase.
Judge model
A second model asked to grade whether the sources support an answer.
Hallucination
A fluent statement not supported by the sources or by facts.

Step by step

01Step 1: split the answer into sentences

Check claims one sentence at a time. A paragraph score hides the one bad sentence. The example gives the sentences as a list; real code splits on sentence ends and keeps each sentence's citation markers.

02Step 2: compute overlap with the cited source

Lower-case, split into words, drop the stop words, and count how many of what is left appear in the source. Report a whole-number percentage.

support.pywhole filepython
def support(sentence, source):
    content = [w for w in words(sentence) if w not in STOP]
    in_source = set(words(source))
    return 100 * sum(1 for w in content if w in in_source) // len(content)

03Step 3: check the numbers separately

Take every digit-only word in the sentence and check it is among the source's words. A wrong price is flagged even at 80 percent overlap.

Step 3: check the numbers separatelydiagram
Rendering diagram…

04Step 4: read the table

Five sentences, five verdicts. The helmet sentence is unsupported (0 percent). The 30-dollar sentence is a wrong number. The paraphrase is flagged although it is right. Which of those do you want a person or a judge to look at?

05Step 5: add a judge for flagged sentences

The judge prompt gives one source and one sentence and asks for 'yes' or 'no' plus a reason. Parse the yes or no in code. The paraphrase should come back 'yes' and clear the false alarm; the helmet sentence 'no'.

06Step 6: decide the action and log it

Drop, regenerate, warn or refuse; then log the sentence, the checks that flagged it and the action, so the rates can be watched.

Try it yourself

  1. 1

    Move the cutoff

    Change 70 to 50 and run. Which sentence stops being flagged? Is that a good trade? Try 90 and see which correct sentences you start rejecting.

  2. 2

    Add a negation

    Add the sentence 'Normal wear is always charged.' against a source that says 'Normal wear is never charged.' What does overlap say? What would catch it?

  3. 3

    Normalise a price

    Add the sentence 'The pass costs $25.' Does the number check handle it? Write a small normaliser that treats $25 and 25 dollars alike.

Code & diagrams

Overlap and number checks on five sentences New tab

Look at lines 4 and 5: the wrong number passes the overlap check, and the correct paraphrase fails it. Each check needs the other.

Sign in to run this example in your browser.

Expected output

100%  supported      The monthly pass costs 25 dollars.
100%  supported      It includes unlimited rides of up to 45 minutes.
  0%  unsupported    Riders also get a free helmet.
 80%  wrong number 30 The monthly pass costs 30 dollars.
 60%  unsupported    A month of unlimited riding is 25 dollars.

Break it on purpose

Errors are the best teachers. Make each change, read the error, guess what went wrong, then reveal the answer.

Break #1

Skip the number check

In the Python tab, change the line elif numbers: to elif False:.

terminal
$ Run
── what you'll see ──
80% supported The monthly pass costs 30 dollars.
60% unsupported A month of unlimited riding is 25 dollars.

Myth vs fact

Myth

If the model cites the right source, the sentence is supported.

Fact

The citation shows where it looked. The sentence can still add or change facts.

Myth

A high overlap proves the claim.

Fact

It proves shared words. A changed number, a flipped condition or a negation can pass with a high score.

Myth

A judge model settles it.

Fact

A judge is a second opinion with its own errors and biases. Use it on flagged sentences and calibrate it against human labels.

Pro corner

Extra depth for experienced readers. New to this? Skip it for now and come back later.

  • ▸

    Natural-language inference models (they label a sentence as supported, contradicted or unrelated given a premise) are a middle option between word overlap and a general judge: smaller, cheaper and trained for exactly this question. Evaluate one on your own labelled sentences before relying on it.

  • ▸

    Check cost against risk. Overlap and numbers run on every answer for free. A judge on every sentence can double your model bill. Run it on flagged sentences, on a random sample for monitoring, and on high-stakes topics (refunds, safety, money).

  • ▸

    Per-claim attribution is stronger than per-answer. If every sentence carries its own citation, you check each sentence against only its own source, which removes a large class of false passes where a sentence is supported by a different source than the one it cites.

Remember this

  1. 1

    Why check. Topic 8.3 showed how to check that a citation points at a real source. A model can still write a sentence that the cited source does not say: it adds a plausible extra from memory, swaps a number (30 dollars for 25), or flips a condition. Each one is fluent, cited and wrong. Grounded means every claim can be traced to the sources given.

  2. 2

    Check one: content-word overlap. Split the answer into sentences. For each, take its content words (drop very common words such as 'the', 'a', 'of') and compute the percentage that also appear in the cited source. A sentence with 0 percent, like 'Riders also get a free helmet.', is almost certainly not from that source. The example flags anything below 70 percent. It is free, instant and runs on every answer.

  3. 3

    Its limits are real. Overlap is a blunt tool in both directions. A paraphrase can score low although it is correct: 'A month of unlimited riding is 25 dollars.' scores 60 percent against the pass passage and gets flagged (a false alarm). A wrong number can score high: 'The monthly pass costs 30 dollars.' scores 80 percent because four of five content words match. Negation ('never charged' versus 'charged') barely moves it at all.

  4. 4

    Check two: facts that must match exactly. Numbers, dates, prices, ids and names must appear in the source verbatim. Pull every number out of the sentence and test that it is in the cited source. This catches the 30-versus-25 swap that overlap missed. It is the cheapest high-value check in this topic. Units and formats need normalising ('25 dollars' versus '$25' versus 'twenty-five').

  5. 5

    Check three: a judge model. For sentences that the cheap checks flag, ask a second model: 'Does the source support this sentence? Answer yes or no and give a reason.' Judges are useful but imperfect (LLM Engineering Topic 9.4 covers rubrics and biases). Use a different model from the one that wrote the answer when you can, run it only on flagged sentences to keep cost down, and calibrate it on examples you labelled by hand.

  6. 6

    Quotes are the strongest form. If the answer includes a quoted phrase, test that the phrase is in the source (Topic 8.6). Exact match beats any fuzzy score.

  7. 7

    What to do with a flagged sentence. Options: drop it, regenerate with the problem listed, show it with a warning, or refuse. Which one fits depends on the cost of an unsupported claim. For a refund rule, refuse; for a chatty tip, a warning may do. Log the rate of flagged sentences. A rise after a prompt or model change is an early warning (Topic 9.5 builds the full answer evaluation).

Explain it without notes

01

Why is checking citations not the same as checking that an answer is grounded?

02

Explain how word overlap fails in both directions.

03

Why check numbers separately?

04

How would you use a judge model without making every answer twice as expensive?

Practice

01

Write numbers_in(text) that returns the list of digit-only words in text in order (use re.findall(r"[0-9]+", text)). Print it for "The pass costs 25 dollars for up to 45 minutes.".

02

Write missing_numbers(sentence, source) that returns the numbers of the sentence that do not appear among the numbers of the source. Print it for the sentence "The pass costs 30 dollars for 45 minutes." and the source "The monthly pass costs 25 dollars and includes unlimited rides of up to 45 minutes.".

Trade-offs

  • ↔

    Overlap: free and instant, but blunt in both directions.

  • ↔

    Exact number checks: precise and cheap, but only for facts that are numbers or ids, and need normalising.

  • ↔

    Judge model: understands meaning, but costs money and time and is itself fallible.

Done when you can

  • Done when you can compute content-word overlap per sentence and explain its limits.

  • Done when you can check numbers and ids by exact match.

  • Done when you can say where a judge model fits and how to keep it affordable.

  • Done when you can choose an action for a flagged sentence and log it.