# RAG Evidence & Citation Auditor (`rayanna/rag-evidence-citation-auditor`) Actor

Audit RAG claims for citation coverage, evidence support, freshness, and provenance integrity with deterministic, privacy-safe reports.

- **URL**: https://apify.com/rayanna/rag-evidence-citation-auditor.md
- **Developed by:** [Ray Ana](https://apify.com/rayanna) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $50.00 / 1,000 rag evidence audits

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## RAG Evidence & Citation Auditor

Deterministic release checks for RAG answers. The auditor measures citation coverage, validates cited source IDs, checks lexical and numeric support, verifies source hashes, flags stale evidence, and scores provenance completeness.

It does not call an LLM, invent a correctness verdict, or send source data to a model. Reports contain hashes and metrics by default; raw claim text and raw numeric claim values are opt-in.

### Input contract

Use a JSON array or NDJSON file. Every record needs:

- `question`: the user question.
- `answer`: the generated answer. Inline citations use `[source-id]`.
- `sources`: evidence objects with `id`, `text`, `url`, `retrievedAt`, and `sha256`.
- Optional `claims`: explicit `{ "text": "...", "sourceIds": ["..."] }` objects for pipelines that already segment claims.

### Local CLI

```bash
pip install .
rag-evidence-audit examples/good-rag-bundle.json \
  --output reports/report.json \
  --markdown reports/report.md \
  --sarif reports/report.sarif
```

Exit codes: `0` passed, `1` quality gate failed, `2` input/runtime error.

### Apify Actor

The Actor accepts up to five inline or public-HTTPS evaluation bundles. Every successful dataset audit produces one compact summary result and one `rag-evidence-audit` pay-per-event charge. The detailed JSON and Markdown reports are then stored in the run key-value store under the keys shown in that summary. A detail-storage failure is logged but does not remove the already delivered summary. Invalid inputs produce an uncharged error record.

Suggested initial price: **$0.05 per successfully audited dataset**. Remove the synthetic `apify-default-dataset-item` pricing event before enabling the custom event so a dataset write is not charged twice.

### What the score means

The score combines citation coverage (30%), deterministic evidence support (35%), provenance completeness (20%), freshness (10%), and citation-reference accuracy (5%). A hash mismatch caps the score below 50. This is an engineering signal, not a claim that an answer is factually correct.

### Limits

- Public remote input is HTTPS-only, port 443, with DNS/IP validation and redirect revalidation.
- Remote payloads: 10 MB. Inline Actor input: 2 MB and 500 records. File input: 5,000 records.
- Raw claims, raw numeric claim values, and evidence text are not copied into the report unless `includeClaimText` is enabled. Numeric values are represented by SHA-256 hashes by default.
- Each record supports at most 100 evidence sources and 200 claims. Source token sets are computed once before bounded near-duplicate comparisons.
- Charged dataset items are compact summaries; detailed reports use key-value-store records so allowed inputs cannot exceed Apify's per-dataset-item size limit.
- Deterministic lexical support can produce false positives or false negatives. Use it as a repeatable release gate, not as a substitute for domain review.

See `docs/PRIVACY_AND_LIMITS.md` and `docs/AUTOMATION_FLOW.md` for the operating model.

# Actor input Schema

## `datasets` (type: `array`):

Each dataset needs a name and exactly one of inline records or a public HTTPS JSON/NDJSON URL.

## `qualityThreshold` (type: `number`):

Reports below this score fail the quality gate.

## `minSupportOverlap` (type: `number`):

Minimum normalized claim-to-source token overlap required for deterministic evidence support.

## `maxSourceAgeDays` (type: `integer`):

Sources retrieved earlier than this age are reported as stale.

## `requireSourceUrl` (type: `boolean`):

Mark a source incomplete when it does not include a provenance URL.

## `requireRetrievedAt` (type: `boolean`):

Mark a source incomplete when it does not include an ISO 8601 retrieval timestamp.

## `requireDeclaredHash` (type: `boolean`):

Mark a source incomplete when it does not include a declared SHA-256 content hash.

## `includeClaimText` (type: `boolean`):

Disabled by default so reports contain hashes and metrics instead of raw answer text.

## `failOnQuality` (type: `boolean`):

The report is delivered before the run is marked failed.

## Actor input object example

```json
{
  "datasets": [
    {
      "name": "RAG release candidate",
      "records": [
        {
          "id": "qa-1",
          "question": "When was the API released?",
          "answer": "The API was released in 2024 [release-note].",
          "sources": [
            {
              "id": "release-note",
              "url": "https://example.com/release",
              "retrievedAt": "2026-09-18T00:00:00Z",
              "sha256": "replace-with-sha256-of-text",
              "text": "The API was released in 2024."
            }
          ]
        }
      ]
    }
  ],
  "qualityThreshold": 75,
  "minSupportOverlap": 0.2,
  "maxSourceAgeDays": 365,
  "requireSourceUrl": true,
  "requireRetrievedAt": true,
  "requireDeclaredHash": true,
  "includeClaimText": false,
  "failOnQuality": false
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `jsonReport` (type: `string`):

No description

## `markdownReport` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "datasets": [
        {
            "name": "RAG release candidate",
            "records": [
                {
                    "id": "qa-1",
                    "question": "When was the API released?",
                    "answer": "The API was released in 2024 [release-note].",
                    "sources": [
                        {
                            "id": "release-note",
                            "url": "https://example.com/release",
                            "retrievedAt": "2026-09-18T00:00:00Z",
                            "sha256": "replace-with-sha256-of-text",
                            "text": "The API was released in 2024."
                        }
                    ]
                }
            ]
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("rayanna/rag-evidence-citation-auditor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "datasets": [{
            "name": "RAG release candidate",
            "records": [{
                    "id": "qa-1",
                    "question": "When was the API released?",
                    "answer": "The API was released in 2024 [release-note].",
                    "sources": [{
                            "id": "release-note",
                            "url": "https://example.com/release",
                            "retrievedAt": "2026-09-18T00:00:00Z",
                            "sha256": "replace-with-sha256-of-text",
                            "text": "The API was released in 2024.",
                        }],
                }],
        }] }

# Run the Actor and wait for it to finish
run = client.actor("rayanna/rag-evidence-citation-auditor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "datasets": [
    {
      "name": "RAG release candidate",
      "records": [
        {
          "id": "qa-1",
          "question": "When was the API released?",
          "answer": "The API was released in 2024 [release-note].",
          "sources": [
            {
              "id": "release-note",
              "url": "https://example.com/release",
              "retrievedAt": "2026-09-18T00:00:00Z",
              "sha256": "replace-with-sha256-of-text",
              "text": "The API was released in 2024."
            }
          ]
        }
      ]
    }
  ]
}' |
apify call rayanna/rag-evidence-citation-auditor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,rayanna/rag-evidence-citation-auditor"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/0CcyQ7CYEgupLefXT/builds/47JHBwv9jNWgJoZXS/openapi.json
