# Citation Sentinel

> Stops RAG answers from fabricating numbers, thresholds, or steps. Verifies [1][2] citations against sources, feeds failures back for retry, then refuses with a reason instead of guessing.

Citation Sentinel is a free AI agent skill on Agensi by milesoyang, in LLM Ops. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [milesoyang](https://www.agensi.io/creators/milesoyang)
- Category: [LLM Ops](https://www.agensi.io/skills/llm-ops)
- Version: 1.0
- Last updated: 2026-11-18
- Security: scan passed (2026-11-18); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/citation-sentinel
- Tags: llm-ops, rag, python, hallucination-detection, testing

## About this skill

### The problem

"Only answer from the sources, never make things up" in a system prompt is a hope, not a guarantee. A model that ignores it faces no consequence — and in ops, finance, or legal work one invented threshold can cause real damage.

Citation Guard turns that promise into a deterministic gate that runs after every generation. Nothing ships until it passes.

### What it does

Given an answer and the full text of the cited sources, it runs four checks:

1. **Marker stripping** — removes `[1]`, `[12]` before any numeric analysis, so the "1" in a citation marker is never mistaken for a fabricated number. This alone eliminates the most common false positive.
2. **Number consistency (zero tolerance)** — every number in the answer (including `50%`, `3000ms`) must appear in a cited source. `50` and `50%` are treated as the same value. The single most dangerous failure — a wrong threshold — is caught every time.
3. **Citation existence** — any `[n]` that doesn't resolve to a real citation card is rejected.
4. **Sentence support (soft threshold)** — sentences whose content words barely overlap the sources are counted; reject only when they exceed a cap, so one weak sentence isn't fatal.

Failed answers are **not** dropped silently. The exact failure reasons are fed back into the prompt, the model gets a corrected retry, and only after repeated failure does the skill refuse — with `needs_human=true`, `confidence=0`, and a reason string naming what was wrong (without presenting the fabricated value as a conclusion).

A `verify_citations` kill switch lets you A/B guarded vs. raw generation, and every rejection is logged for a refusal-rate dashboard.

### Why it's different

- **Executable, not advisory** — the "never hallucinate" rule becomes code, with a verdict object (`ok`, `reasons`, `fabricated_numbers`, `missing_citations`) rather than a boolean.
- **Portable** — works with any LLM/agent, any language (mixed CJK/English tokenizer built in), no external dependencies.
- **Battle-tested edge cases** — percent normalization, multi-source unions, full-text vs. truncated-snippet traps, and threshold recalibration as your corpus grows are all handled and documented.

### What's included

- `SKILL.md` — concise instructions with trigger terms for reliable activation
- `references/verification-rules.md` — thresholds, tokenization, edge cases, calibration procedure
- `references/retry-and-refusal.md` — generation loop, refusal copy, observability, wiring checklist
- `scripts/verify_answer.py` — standalone stdlib-only verifier, runnable immediately with built-in examples

Works with Claude Code, Cursor, Copilot, Codex CLI, Gemini CLI and any agent that loads SKILL.md files.

## Requires

- Python 3.10+

Nothing to install in the agent itself — instructions run inside the agent. The optional verifier uses only the Python standard library.

## Known limitations

Requires full source text rather than snippets for accurate number matching. High-volume document overlap may require manual recalibration of the support thresholds.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Citation Sentinel skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### Do I need an API key or paid LLM subscription?

No. The checks run in code with no external service, alongside whatever LLM your agent already uses.

### Does it work with Chinese / non-English answers?

Yes. The tokenizer handles mixed CJK + English with bigrams. Thresholds are documented for recalibration to your corpus.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
