# PDF Citation Validator — Verify RAG Page References (`flyerlin/pdf-citation-validator-paid`) Actor

Check stored RAG citation text against the original PDF. Get MATCH, WRONG_PAGE, AMBIGUOUS or NOT_FOUND verdicts with evidence, page counts and a SHA-256. No OCR or LLM.

- **URL**: https://apify.com/flyerlin/pdf-citation-validator-paid.md
- **Developed by:** [林 吴](https://apify.com/flyerlin) (community)
- **Categories:** AI, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.70 / 1,000 citation checkeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## PDF Citation Validator — Verify RAG Page References

Verify that stored RAG citation text actually appears on the PDF page it claims.

### Use it when

- Audit a RAG index after ingestion or after replacing a PDF.
- Catch wrong-page citations with evidence excerpts.
- Quantify ambiguous or missing citations before shipping answers.
- Keep a SHA-256 and physical page count for each audited PDF.

**Input → output:** Original PDF + existing citation records → page verdicts and evidence.

Works with Apify Schedules, webhooks/API and the Apify MCP server (Claude, Cursor and other MCP clients).

### Quick start

1. Provide an authorized public HTTPS PDF URL, or PDF bytes in `pdfBase64` (without a data URL prefix). Supply exactly one source.
2. Add `chunks`: objects with `text`, optional `id`, and optional `page`.
3. Run and inspect dataset records and the `SUMMARY` key-value record. Review suggestions before changing your index.

`page` always means **1-based physical PDF page**, including covers and blank pages. Printed page labels such as roman numerals are not mapped.

```json
{
  "pdfUrl": "https://www.rfc-editor.org/rfc/rfc9457.pdf",
  "chunks": [{"id": "intro", "page": 2, "text": "Problem Details for HTTP APIs"}]
}
```

The example quotation may occur on several pages; `AMBIGUOUS` is a useful result, not a failure. Replace the quotation with your actual stored text.

### Results

| Status | Meaning |
|---|---|
| MATCH | One exact normalized match, on the claimed page. |
| WRONG_PAGE | One exact normalized match, on a different physical page. |
| PAGE_FOUND | One exact normalized match; no original page was supplied. |
| AMBIGUOUS | Text matches multiple pages. No page correction is suggested. |
| NOT_FOUND | No exact single-page match. This does not prove the citation is fabricated. |
| OCR_REQUIRED | No match and a relevant page has no extracted text. It may be blank or image-only; OCR is not performed. |

Each row includes the chunk ID, claimed page, candidate pages, suggested page where unique, reason and normalized evidence excerpts. `SUMMARY` includes PDF SHA-256, physical page count, pages without extracted text, method and status counts. Candidate pages are capped at 50 per row; evidence excerpts at 10. Counts and truncation flags remain explicit.

### Matching and limitations

Matching applies Unicode NFKC, line-ending dehyphenation, whitespace normalization and case folding, then requires an exact substring within one page. It does not use an LLM or fuzzy similarity score. Hyphen normalization can alter genuinely hyphenated text; inspect evidence.

Paraphrases, cross-page chunks, unusual PDF reading order, tables, OCR errors, different file versions and extraction differences may produce NOT_FOUND. Repeated headers or repeated quotations produce AMBIGUOUS. A text match does not establish that the answer is true or supported in context. Physical page counts preserve blank pages. No database writes, automatic fixes or OCR are performed.

Limits: one PDF per run; 20 MB; 300 pages; 1,000 citation records; 20–10,000 normalized characters per quotation. Encrypted PDFs are unsupported. Invalid input fails the run. Network downloads allow public HTTPS port 443 and validate redirect destinations; private/local/reserved addresses are rejected. For sensitive documents, assess your Apify storage and retention requirements before uploading; input and results are stored by Apify. Avoid secrets in URLs. Server content is parsed as data, never executed.

### Pricing at launch

Developer fee: **$0.001 per delivered citation verdict ($1 per 1,000 citations)**, with platform usage included. Apify paid plans receive volume discounts — Bronze 10%, Silver 20%, Gold and above 30%. All delivered verdicts are charged, including ambiguous or missing matches. Invalid input or unreadable PDFs generate no citation event charge. No separate developer start fee. Set a maximum charge; SDK limits dataset delivery to the remaining budget. SUMMARY counts describe all analyzed citations; dataset delivery can be smaller at the charge limit. No third-party API key or paid OCR service is required. Start with one small PDF, use 256 MB and a run spending limit; large or complex PDFs may need more memory. No measured cost or accuracy guarantee is implied.

### Automation

Run through Apify API, schedules, n8n or Make. Retrieve the default dataset for per-citation results and key-value `SUMMARY` for totals. Branch on WRONG_PAGE for manual review; do not automatically modify or delete production records based on this output.

### Validation

The included local tests cover known physical page offsets, preserved blank pages, repeated quotations, missing text, absent page metadata, invalid inputs and conservative rejection of paraphrases. Synthetic samples are generated for tests and are not customer data. Test success does not establish universal PDF extraction accuracy.

### FAQ

**Does it check whether a citation is true or supported?**
No. It verifies that the quoted text appears on the claimed physical PDF page. It does not judge truth or semantic entailment.

**Does it use OCR?**
No. It works on extractable text. Pages without extracted text are reported as OCR_REQUIRED.

**What are the limits?**
One PDF per run, 20 MB, 300 pages and 1,000 citation records. Encrypted PDFs are unsupported.

**What does AMBIGUOUS mean?**
The same text appears on multiple pages, so no single page correction is suggested.

**How much does it cost?**
$0.001 per delivered citation verdict. Invalid input or unreadable PDFs generate no citation charge.

### Related Actors

- [Webpage to JSON — Text, Tables, Links & JSON-LD](https://apify.com/flyerlin/webpage-clean-json)
- [JSONL Toolkit — Validate, Dedupe & Redact NDJSON](https://apify.com/flyerlin/jsonl-toolkit)
- [Data Cleaner — Dedupe, Map & Validate JSON / CSV](https://apify.com/flyerlin/advanced-data-cleaner)
- [All Actors by flyerlin](https://apify.com/flyerlin)

# Actor input Schema

## `pdfUrl` (type: `string`):

Provide a public authorized HTTPS PDF, or use base64 below. Maximum 20 MB, 300 physical pages.

## `pdfBase64` (type: `string`):

Alternative to URL, no data: prefix. Provide exactly one source.

## `chunks` (type: `array`):

Each object requires text (20–10000 normalized characters), optional positive page (1-based physical PDF page) and id. Maximum 1000 records.

## Actor input object example

```json
{
  "pdfUrl": "https://www.rfc-editor.org/rfc/rfc9457.pdf",
  "chunks": [
    {
      "id": "intro",
      "page": 2,
      "text": "Problem Details for HTTP APIs"
    }
  ]
}
```

# Actor output Schema

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

Per-citation pages, verdicts and evidence.

## `summary` (type: `string`):

PDF hash, page count, method and status counts.

# 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 = {
    "pdfUrl": "https://www.rfc-editor.org/rfc/rfc9457.pdf",
    "chunks": [
        {
            "id": "intro",
            "page": 2,
            "text": "Problem Details for HTTP APIs"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("flyerlin/pdf-citation-validator-paid").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 = {
    "pdfUrl": "https://www.rfc-editor.org/rfc/rfc9457.pdf",
    "chunks": [{
            "id": "intro",
            "page": 2,
            "text": "Problem Details for HTTP APIs",
        }],
}

# Run the Actor and wait for it to finish
run = client.actor("flyerlin/pdf-citation-validator-paid").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 '{
  "pdfUrl": "https://www.rfc-editor.org/rfc/rfc9457.pdf",
  "chunks": [
    {
      "id": "intro",
      "page": 2,
      "text": "Problem Details for HTTP APIs"
    }
  ]
}' |
apify call flyerlin/pdf-citation-validator-paid --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,flyerlin/pdf-citation-validator-paid"
        }
    }
}
```

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/ZjGEUKwu90U93LTdy/builds/Y3OJrhRQTpBIAsB1c/openapi.json
