Practical technical guides / AI engineering

Agent Quote Checks Beyond Substring Matching: Half-True, Misattributed and Spliced Quotes

A normalized substring test passes or fails. Typed outcomes separate half-true quotes, wrong-source quotes, spliced ellipses and NFKC hazards.

By Sandeep Belgavi · Published 2026-12-04 · Prepared 2026-12-03

A normalized substring test passes or fails. Typed outcomes separate half-true quotes, wrong-source quotes, spliced ellipses and NFKC hazards.

A quote is a claim about a source

Agents that read documents are often asked to cite them. A help desk agent at Belgavi's Book Store summarises a customer email and quotes the sentence that justifies its recommendation. A research agent writes a briefing with quoted lines from release notes. In both cases the quote is the evidence a person will rely on instead of reading the source themselves.

Language models reproduce text well but not reliably. A quote can come back with a word changed, two sentences merged, a clause dropped, or a sentence that sounds like the source but is not in it. None of these is visible from the output. The only way to know a quote is real is to check it against the text the agent actually read, with code, before anyone sees it.

The site's guide to grounding and citations already covers the citation contract and a validator that looks for a normalised quote inside the cited source. This guide starts where that validator stops. A pass or fail answer hides the cases that matter most in review: a quote that starts true and then invents, a real sentence attributed to the wrong document, two real fragments spliced with an ellipsis in an order the source never had, and line-break hyphenation that a plain normaliser cannot undo. It also covers what normalisation itself can get wrong. The result is a checker with typed outcomes rather than a boolean, so each failure can be routed to the right response.

Worked example: one customer email, six quotes

Geetha writes to the help desk about CASE-8204. The email, as received, contains typographic characters a model rarely reproduces exactly: an em dash, a curly apostrophe, the "fi" ligature that some PDF and email pipelines produce, and a word hyphenated across a line break.

From: Geetha
Subject: CASE-8204 damaged copy

The parcel arrived on Monday and the cover was torn—the spine is cracked too. I’d like a replace-
ment rather than a refund, if the first edition is still in stock.

The agent's summary quotes the email six times. The checker classifies each quote.

Quote produced by the agentResultWhy
the cover was tornexactAppears byte for byte.
the cover was torn-the spine is cracked toonormalizedEm dash became a hyphen.
I'd like a replacement rather than a refundnormalizedCurly apostrophe and the line-break hyphen.
if the first edition is still in stocknormalizedThe ligature, which NFKC expands to "fi".
I would like a refundnot foundContradicts the source: the request was for a replacement.
the spine is cracked and the pages are loosefragments onlyFirst half is real; the loose pages are invented.

An exact-substring check would have rejected three genuine quotes and pushed the team to turn checking off. A fuzzy similarity score would probably have accepted the last quote, because most of its words are in the source. The checker distinguishes them.

The checker

The normalisation is deliberately narrow. It applies Unicode compatibility normalisation (NFKC, defined in Unicode Standard Annex #15), maps curly quotes and dashes to their ASCII forms, removes hyphenation at line breaks, collapses whitespace and folds case. Everything else must match.

import re, unicodedata

QUOTE_MAP = str.maketrans({"‘": "'", "’": "'", "“": '"', "”": '"',
                           "–": "-", "—": "-"})

def norm(s):
    s = unicodedata.normalize("NFKC", s).translate(QUOTE_MAP)
    s = re.sub(r"-\s*\n\s*", "", s)            # a word hyphenated across a line break
    return re.sub(r"\s+", " ", s).strip().casefold()

def check(quote, source):
    if quote in source:
        return "exact"
    nq, ns = norm(quote), norm(source)
    if nq in ns:
        return "normalized"
    words, vocab = nq.split(), set(ns.split())
    windows = [words[i:i + 4] for i in range(max(1, len(words) - 3))]
    if any(len(w) == 4 and all(x in vocab for x in w) for w in windows):
        return "fragments only"
    return "not found"

SOURCE = ("From: Geetha\nSubject: CASE-8204 damaged copy\n\n"
          "The parcel arrived on Monday and the cover was torn—the spine is cracked too. "
          "I’d like a replace-\nment rather than a refund, if the first edition is still in stock.")

for q in ["the cover was torn", "I'd like a replacement rather than a refund",
          "if the first edition is still in stock", "I would like a refund",
          "the spine is cracked and the pages are loose"]:
    print(f"{check(q, SOURCE):15} {q}")
# exact           the cover was torn
# normalized      I'd like a replacement rather than a refund
# normalized      if the first edition is still in stock
# not found       I would like a refund
# fragments only  the spine is cracked and the pages are loose

Only "exact" and "normalized" pass. "Fragments only" is a separate result because it is the most dangerous case: a quote that starts true and drifts. It should be shown to a reviewer with the real source sentence beside it, never silently accepted.

What the normalisation must not do

Each normalisation step widens what counts as a match, so each must be justified by a real formatting difference, not by a wish to pass more quotes.

  • NFKC folds characters that are visually or semantically compatible: ligatures, full-width letters, superscript digits. It also folds some characters whose difference matters, such as the superscript two in "m²" becoming a plain "2". If your sources contain units, formulas or code, check whether NFKC is too aggressive and consider NFC, which only composes characters.
  • Dehyphenation joins "replace-" and "ment", but it also joins a genuinely hyphenated word that was broken at its hyphen, turning "well-\nknown" into "wellknown". That causes misses, not false passes, which is the safer direction.
  • Case folding is safe for prose and unsafe for code identifiers and product codes. Do not fold case for quotes from code or structured data.
  • Never drop punctuation wholesale, stem words, or remove stop words. Each of those lets "I would like a refund" approach "I'd like a ... refund".

Display the source span, not the model output

Once a quote passes, show the user the span from the source document, not the string the model produced. For an exact match that is the same text. For a normalised match it differs only in typography, but the source span is the evidence, and a reviewer who clicks through should land on exactly what they read. Keep a mapping from normalised offsets back to original offsets, or search the original text with a pattern built from the quote, so you can highlight the real span.

Record the result per quote in the agent's trace: the quote, the classification, the source document id and version, and the offsets. When a customer disputes a decision, that record shows what the agent relied on.

Several sources, one quote

Agents often read more than one document for a case: the customer email, the order record, the returns policy. When the output says "the policy states" followed by a quote, check the quote against the policy, not against everything the agent read. A sentence that exists in the customer's email but is attributed to the policy is a misattribution, and it is more harmful than an invented quote because it passes a naive check against the combined text.

This means the agent's citation format has to carry the source identifier with each quote, and the checker has to resolve that identifier to the exact text that was provided. If the format allows a quote without a source, treat it as unverifiable rather than searching for any document that happens to contain it. Report the result per quote and per source: a summary that cites three documents correctly and one incorrectly should show exactly which one failed, so a reviewer does not have to re-read all four.

Where to put the check

Run the check in the harness, after the model responds and before anything leaves the system. Do not ask the model to check its own quotes; it will usually agree with itself. Three policies are common:

  1. Strip and flag. Remove failing quotes from the output and attach a note that a quote could not be verified. Good for summaries shown to staff.
  2. Retry once. Send the failing quote back with the source passage and ask for an exact quote or a paraphrase without quotation marks. Accept the result only if it passes.
  3. Block. For decisions with consequences, such as a refund refusal citing the customer's own words, refuse to proceed until a person reviews.

Failure modes

  • Checking against the wrong text. The source must be the exact text the agent received, after the same extraction step. If the PDF is extracted twice with different tools, a quote can pass against one and fail against the other.
  • Truncated sources. If the agent saw only the first part of a long document, check against that part. A quote found later in the document was not read; it was guessed.
  • Ellipses. Models often join two real fragments with "...". Split the quote on the ellipsis and check each part, and require the parts to appear in order.
  • Paraphrase in quotation marks. A paraphrase is fine; a paraphrase dressed as a quote is not. The check makes the difference visible, which is the point.

Verification

Build a test set from your own documents: genuine quotes with typographic differences that must pass, edited quotes that must fail, and spliced quotes that must be flagged as fragments. Run it whenever the normalisation changes. A checker that passes everything is as useless as one that passes nothing, and the test set is how you notice which one you have.

Primary references and authorship

Sources checked 2026-12-03. Original explanation and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/python/quote_evidence_check. Views are my own and do not represent any employer, past or present.