Skip to main content

Citation verifier

citation-verifier compares a model answer with the source text that your application sends in the request, and can block an answer that is not grounded in it. It also finds citations in the answer, such as quotes, DOIs, and URLs, and can look some of them up.

It is not a fact checker. It measures word overlap: an incorrect claim can overlap well, and a correct paraphrase can score low.

It runs on Chat Completions, Responses, and Messages. With streaming, the gateway holds the output until the complete-response checks finish.

Configuration​

This configuration checks the answer against the supplied context only, without external lookups. Apply it to a test gateway with the config-first workflow.

policy-config.yaml
pack:
  name: citation-verifier-example
  version: 1.0.0
  enabled: true
policies:
  chain:
    - citation-verifier
policy:
  citation-verifier:
    require_sources: true
    require_source_match: true
    min_confidence: 0.8
    min_groundedness: 0.8
    extract_patterns:
      - quote
    rag_context:
      verify_against_context: true
      min_context_overlap: 0.7
    output_action:
      unverified_action: block
    response:
      include_verification_report: true

Fields​

FieldTypeDefaultDescription
require_sourcesbooleantrueThe answer must contain source evidence
require_source_matchbooleantrueWith require_sources, a citation alone is not enough: a quote must match the context, the overlap must reach min_context_overlap, or an external lookup must succeed.
min_confidencenumber0.8Minimum share of claims whose overlap reaches min_groundedness
min_groundednessnumber0.8Minimum word overlap of one claim. Also the fallback for rag_context.min_context_overlap.
extract_patternsstring[]case_law, academic, url, quote, statistic, regulatoryCitation types to find. academic enables DOI and PubMed lookups; URL lookups also require VERDICTAN_CITATION_URL_LOOKUP=1 or true. Lint accepts all six types.
rag_context.verify_against_contextbooleantrueCompares the answer with the context documents of the request
rag_context.min_context_overlapnumber0.7Minimum word overlap of the whole answer with the context
output_action.unverified_actionstringflagflag, redact, or block. Only block changes the verdict. redact does not change the answer.
response.include_verification_reportbooleantrueWith false, the details contain only verified and groundedness.

| external_resolver.endpoint | string | | Optional citation resolver URL. Receives case-law and regulatory citations. | | external_resolver.api_key | string | | Optional literal bearer credential. This field does not accept secret_key_ref or expand environment placeholders. Protect any configuration that contains it. | | external_resolver.timeout_ms | integer | 2000 | Resolver timeout, from 1 through 60000 milliseconds | | output_action.hallucination_action | string | block | A confirmed nonexistent citation blocks when this value is block, even if other grounding checks pass. |

Phase and verdicts​

ItemValue
Phaseoutput
Enforced pathChat Completions, Responses, and Messages, including buffered streaming output
Verdictsallow, block
Reason codescitation.verified, citation.unverified, citation.hallucinated

A block returns HTTP 400 with error code content_policy_violation and a verdictan.decision object with verdict BLOCK.

Supply the text to verify against​

Put the source text in verdictan.context_documents of the request. This body gives the same source to the model and to the verifier:

request.json
{
  "model": "gpt-4o-mini",
  "stream": false,
  "messages": [
    {"role": "system", "content": "Return only this exact quoted sentence: \"The museum opens at nine.\""},
    {"role": "user", "content": "When does the museum open?"}
  ],
  "verdictan": {
    "context_documents": [{"content": "The museum opens at nine."}]
  }
}

Send it with the URL and API token from the quickstart:

curl --fail-with-body "$VERDICTAN_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $VERDICTAN_CLIENT_TOKEN" \
  -H "Content-Type: application/json" \
  --data-binary @request.json

The nested result shows citation.verified. Now change only the context document to an unrelated sentence and send it again. The result is citation.unverified when the overlap falls below the threshold.

Model wording can vary between calls. For a repeatable test, use a provider fixture that always returns the quoted sentence.

How it works​

  1. The control reads the answer from the provider response, and the verdictan.context_documents[].content strings from the request.
  2. With verify_against_context, it calculates the groundedness: the share of unique answer words that also appear in the context.
  3. It splits the answer into claims at ., !, ?, and line breaks, and scores each claim against the context. A claim passes at min_groundedness or above. The claim confidence is the share of claims that pass.
  4. It extracts DOIs, PubMed IDs, URLs, case law citations, regulatory references, and quotes, as extract_patterns selects.
  5. With academic, it looks up each DOI at api.crossref.org and each PubMed ID at eutils.ncbi.nlm.nih.gov. With url and VERDICTAN_CITATION_URL_LOOKUP=1 or true, it performs URL verification using HEAD and, when needed, GET. Each call has a 5-second timeout.
  6. It checks case-law citation formats. With external_resolver.endpoint, it also sends each case-law and regulatory citation as {"citation": "...", "kind": "case_law"} or regulatory to that endpoint. The resolver must return found as a boolean. A found result must reach min_confidence to count as verified; found: false identifies a hallucinated citation.
  7. It decides whether the answer is verified:
    • An empty answer passes.
    • Without context checks, or without context documents, the answer passes when require_sources is false, when source evidence exists, or when require_source_match is false.
    • With context documents, the overlap must reach min_context_overlap, the claim confidence must reach min_confidence, and the source rule must pass.
  8. A verified answer is allowed with citation.verified.
  9. A citation confirmed as nonexistent blocks with citation.hallucinated when hallucination_action is block. An otherwise unverified answer blocks with citation.unverified when unverified_action is block. Other actions keep an allow verdict.

The details contain verified, groundedness, claim_confidence, claims, quotes, citations, and external_lookup. A verified answer adds a verification_report. An unverified answer adds unverified_claims and unverified_claim_count.

Limits and failure behavior​

  • With stream: true, the gateway holds the output, runs this control on the complete response, and releases it only when the result permits delivery.
  • Groundedness counts shared words. A paraphrase of the context scores lower than an answer that reuses its words.
  • With academic, the gateway can call Crossref and PubMed. URL lookups are off unless VERDICTAN_CITATION_URL_LOOKUP is 1 or true. To avoid external citation calls, remove academic and url and leave external_resolver unset. A timeout is an unavailable lookup; a confirmed nonexistent citation is governed by hallucination_action.
  • The runtime and schema defaults include regulatory. External resolver results are in citations.resolver_results. Resolver errors set citations.resolver_fallback; an unavailable resolver is not the same as found: false.
  • flag and redact behave the same: the answer goes out unchanged with an allow verdict.
  • Without an external resolver, case-law citations receive a format check only. A resolver response must have a boolean found; timeouts, non-success responses, and invalid response bodies count as unavailable.
  • With the defaults and no context documents, an answer without a citation or verified source fails. Set require_sources: false on routes that do not use citations.

Starter packs that include this control are in the policy templates hub.

Next steps​