Schedule icon
WorkingDirectory icon
Script icon
Process icon
If icon
Parallel icon
Create icon
SlackIncomingWebhook icon

Catch Fabricated Citations with an Answer Grounding Guard

Catch Fabricated Citations with an Answer Grounding Guard

Categories
AI

What it does

AI answers sound confident even when the citations under them are invented. This blueprint checks a set of questions and answers against the sources they cite and proves the link is real: the sources exist, the quotes appear in them word for word, the numbers in the answer carry a citation, and the sources are not years out of date. Every check feeds one grounding scorecard with per-category pass rates and a trend against the last run. A failed gate opens a GitHub issue and pages Slack.

Run it as-is first: switch stub_mode to "fabricated" and the set cites a source that does not exist, alters a 30 day refund window into 90 days inside a quote, makes a numeric claim with no citation at all, and leans on a source from January 2025. The gate fails with critical findings and you see the full escalation path.

Checks

  • Grounding: every answer carries at least one citation, numeric claims are cited, and the answer's own words overlap the cited sources, so an answer cannot drift away from what it claims to rest on.

  • Citation integrity: cited source IDs must exist in the corpus, and every quoted span must appear in its source after normalising case and whitespace. An altered quote is a critical failure, because that is how fabricated evidence ships.

  • Freshness: cited sources older than max_source_age_days are flagged, and sources past twice that age raise the severity, so answers stop resting on retired documentation.

How it works

  1. daily_grounding_guard (Schedule trigger) runs the guard daily at 07:30 UTC. Run it on demand after any model, prompt, or corpus change.

  2. load_eval_set (Python) resolves the evaluation set from inline JSON, a URL, or the bundled stub sets, validates sources and items, and normalises the fields the checks need.

  3. analyse_set (Python) runs the six checks: citation coverage, citation validity, quote fidelity, numeric claims cited, answer to source overlap, and source freshness.

  4. build_scorecard (Python) turns the findings into per-category pass rates and one grounding score, applies the gate, compares with the previous scorecard for the trend, and writes scorecard.json, scorecard.md, and the trend record.

  5. triage (flow tasks) branches on the gate: passing runs are recorded; failing runs open the GitHub issue and post the Slack alert in parallel.

Prerequisites

  • An evaluation set as JSON: sources keyed by ID with text and an updated date, plus items with question, answer, citations, and quotes. Sample production answers into it, or use the bundled stub sets.

  • A GitHub token with issue-write scope on the tracking repository.

  • A Slack incoming webhook URL for the team channel.

Secrets

  • GITHUB_TOKEN: token used to open the tracking issue (required).

  • SLACK_WEBHOOK_URL: incoming webhook for the team-channel alert (required).

Quick start

  1. Add the two secrets above to your Kestra namespace.

  2. Import this blueprint and run it with the default "grounded" stub: the gate passes and the scorecard records a clean run.

  3. Run it again with stub_mode set to "fabricated" and then "mixed" to see both failure shapes and the escalation.

  4. Point eval_set_url at your own sampled answers, set max_source_age_days to your documentation's real shelf life, and leave the daily schedule enabled.

How to adapt it

  • Sample live traffic: replace the stub load with a subflow that pulls yesterday's answers from your serving logs and builds the set automatically.

  • Add an LLM judge stage for the answers that pass the mechanical checks but still read as unsupported, and feed its verdicts into the same scorecard.

  • Write the scorecard to a warehouse table for a grounding quality dashboard.

  • Gate releases: fail the deployment pipeline when the grounding score drops below threshold or the trend verdict is regressed.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.