# Q\&A Dataset Extractor for LLM Fine-Tuning (`deniz_schloesser/qa-dataset-extractor`) Actor

Crawl any website, documentation or FAQ and turn it into clean, deduplicated question-answer pairs in OpenAI / Alpaca / plain JSONL format - ready for fine-tuning and RAG.

- **URL**: https://apify.com/deniz\_schloesser/qa-dataset-extractor.md
- **Developed by:** [Deniz Schlösser](https://apify.com/deniz_schloesser) (community)
- **Categories:** AI, Developer tools
- **Stats:** 2 total users, 1 monthly users, 0.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 q\&a pairs

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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Q&A Dataset Extractor for LLM Fine-Tuning

**Turn any website, documentation portal, or FAQ into clean, deduplicated question-answer pairs — ready to fine-tune a model or power a RAG / support chatbot.**

Most scrapers stop at raw HTML or Markdown and leave the hard part to you: turning a pile of text into actual *training examples*. This Actor goes the whole way. It crawls your source, extracts the real content (no nav, ads, or boilerplate), splits it into context-preserving chunks, and uses Claude to generate grounded, self-contained **Q&A pairs** in the exact JSONL format your training pipeline expects.

You bring a source URL. You get back a fine-tuning-ready dataset.

---

### Why this Actor

- 🎯 **Training-ready output, not raw text.** Get `{question, answer}` pairs in OpenAI, Alpaca, or plain JSONL — drop them straight into a fine-tuning job.
- 🧹 **Clean extraction.** Mozilla Readability strips navigation, sidebars, cookie banners, and ads. The model never sees junk, so your dataset doesn't either.
- 🔒 **Grounded answers, no hallucination.** Every answer is constrained to the crawled content — the prompt forbids inventing facts.
- ♻️ **Automatic deduplication.** Near-identical questions across pages are collapsed, so you don't pay to train on the same thing twice.
- 💸 **Bring your own Claude key (BYOK).** You control model choice and token spend. Default `claude-haiku-4-5` keeps costs at roughly **$1 per 1,000 pairs** in tokens.
- 🧪 **Free dry run.** Preview crawling and chunking with zero LLM cost before you spend anything.

---

### What it does

````

Start URL(s)
│  1. Crawl       → follows same-domain links up to your page limit
▼
Clean Markdown      → Mozilla Readability + Turndown (main content only)
│  2. Chunk       → paragraph-aware, with overlap to preserve context
▼
Content chunks
│  3. Generate    → Claude produces up to N grounded Q\&A pairs per chunk
▼
│  4. Deduplicate → collapses repeated questions
▼
JSONL dataset       → OpenAI / Alpaca / plain, with source\_url + source\_title

````

---

### Example

**Input:**

```json
{
  "startUrls": [{ "url": "https://docs.apify.com/academy/web-scraping-for-beginners" }],
  "maxPagesToCrawl": 5,
  "maxQuestionsPerChunk": 3,
  "outputFormat": "openai",
  "model": "claude-haiku-4-5",
  "anthropicApiKey": "sk-ant-..."
}
````

**Output (one dataset item, `openai` format):**

```json
{
  "messages": [
    {
      "role": "user",
      "content": "What is the main project you'll build in this JavaScript web scraping course?"
    },
    {
      "role": "assistant",
      "content": "In this course, you'll create an application for watching prices. It will be able to scrape all product pages of an e-commerce website and record prices. Data from several runs of such a program would be useful for seeing trends in price changes, detecting discounts, and more."
    }
  ],
  "source_url": "https://docs.apify.com/academy/web-scraping-for-beginners",
  "source_title": "Web scraping basics for JavaScript devs | Academy | Apify Documentation"
}
```

Every item carries `source_url` and `source_title` so you can trace, filter, or cite each example.

***

### Output formats

Pick the shape your training pipeline expects with the `outputFormat` setting:

| Format | Shape | Use it for |
|--------|-------|------------|
| `openai` | `{ "messages": [{ "role": "user", ... }, { "role": "assistant", ... }] }` | OpenAI fine-tuning, chat-format SFT |
| `alpaca` | `{ "instruction": "...", "input": "", "output": "..." }` | Llama / Mistral / open-model instruction tuning |
| `plain`  | `{ "question": "...", "answer": "..." }` | RAG eval sets, custom pipelines, embeddings |

> The output format is independent of the model that generates the pairs — Claude produces pairs in whichever training shape you choose.

***

### Use cases

**🤖 Build a support chatbot from your docs.** Point it at your help center or product docs and generate a Q\&A set to fine-tune or seed a RAG index — so the bot answers in your product's own words.

**🎓 Fine-tune a domain expert model.** Turn a knowledge base, wiki, or set of guides into thousands of instruction examples for a specialized model, without hand-writing them.

**📚 Create RAG evaluation sets.** Generate grounded question-answer pairs to benchmark retrieval quality — does your RAG system actually find the right answer?

**🌍 Localize training data.** Use `customInstructions` (e.g. *"Write all questions and answers in German"*) to produce datasets in any language your source covers.

***

### Input reference

| Field | Description | Default |
|-------|-------------|---------|
| `startUrls` | Pages to crawl (follows same-domain links) | — (required) |
| `maxPagesToCrawl` | Hard limit on pages crawled | `10` |
| `maxQuestionsPerChunk` | Q\&A pairs generated per content chunk | `3` |
| `chunkSize` / `chunkOverlap` | Chunking in characters (overlap auto-capped at half) | `4000` / `200` |
| `outputFormat` | `openai` | `alpaca` | `plain` | `openai` |
| `model` | `claude-haiku-4-5` | `claude-sonnet-4-6` | `claude-opus-4-8` | `claude-haiku-4-5` |
| `anthropicApiKey` | Your Anthropic (Claude) API key — `sk-ant-...` (secret) | — |
| `customInstructions` | Extra guidance, e.g. *"answer in German"* or *"focus on pricing"* | — |
| `dryRun` | Skip the LLM and just output chunks — **free preview** | `false` |

***

### Choosing a model

| Model | Token cost (your key) | Best for |
|-------|----------------------|----------|
| **Claude Haiku 4.5** (default) | ~$1 / 1,000 pairs | High-volume datasets, the cost-conscious default |
| **Claude Sonnet 4.6** | ~$3 / 1,000 pairs | Nuanced answers, technical or complex sources |
| **Claude Opus 4.8** | ~$5 / 1,000 pairs | Highest quality where it matters most |

***

### Quick start

1. Add one or more **Start URLs** (e.g. your docs site).
2. Paste your **Anthropic (Claude) API key** (`sk-ant-...`). Get one at [console.anthropic.com](https://console.anthropic.com).
3. *(Optional)* Set `dryRun: true` first to preview crawling and chunking for free.
4. Run, then download the dataset as **JSONL** and feed it to your fine-tuning job.

***

### Notes & responsible use

- **Bring your own key.** This Actor calls the Claude API with the key you provide; you are billed by Anthropic for token usage directly.
- **Answers are grounded.** The prompt forbids inventing facts — answers are constrained to the crawled content.
- **Respect each site's rules.** Only crawl content you are permitted to use. Honor the target site's Terms of Service and `robots` directives, and respect copyright and data-protection law (e.g. GDPR) for any personal data you process.

***

*Questions or a source that doesn't extract cleanly? Open an issue on the Actor page — feedback shapes the roadmap.*

# Actor input Schema

## `startUrls` (type: `array`):

Pages to crawl. The crawler follows links on the same domain until 'Max pages' is reached.

## `maxPagesToCrawl` (type: `integer`):

Hard limit on the number of pages crawled.

## `maxQuestionsPerChunk` (type: `integer`):

How many question-answer pairs the model should generate per content chunk.

## `chunkSize` (type: `integer`):

Target size of each content chunk fed to the model.

## `chunkOverlap` (type: `integer`):

Characters of overlap between consecutive chunks to preserve context. Automatically capped at half the chunk size.

## `outputFormat` (type: `string`):

Schema of each dataset item.

## `model` (type: `string`):

Claude model used to generate the Q\&A pairs.

## `anthropicApiKey` (type: `string`):

Your Anthropic API key (sk-ant-...). Required unless 'Dry run' is enabled.

## `customInstructions` (type: `string`):

Extra guidance for the model, e.g. 'Write answers in German' or 'Focus on pricing and setup questions'.

## `dryRun` (type: `boolean`):

Skip the LLM step and just output the extracted chunks. Use this to test crawling/chunking for free.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://docs.apify.com/academy/web-scraping-for-beginners"
    }
  ],
  "maxPagesToCrawl": 10,
  "maxQuestionsPerChunk": 3,
  "chunkSize": 4000,
  "chunkOverlap": 200,
  "outputFormat": "openai",
  "model": "claude-haiku-4-5",
  "dryRun": false
}
```

# 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 = {
    "startUrls": [
        {
            "url": "https://docs.apify.com/academy/web-scraping-for-beginners"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("deniz_schloesser/qa-dataset-extractor").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 = { "startUrls": [{ "url": "https://docs.apify.com/academy/web-scraping-for-beginners" }] }

# Run the Actor and wait for it to finish
run = client.actor("deniz_schloesser/qa-dataset-extractor").call(run_input=run_input)

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

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

```

## CLI example

```bash
echo '{
  "startUrls": [
    {
      "url": "https://docs.apify.com/academy/web-scraping-for-beginners"
    }
  ]
}' |
apify call deniz_schloesser/qa-dataset-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=deniz_schloesser/qa-dataset-extractor",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Q&A Dataset Extractor for LLM Fine-Tuning",
        "description": "Crawl any website, documentation or FAQ and turn it into clean, deduplicated question-answer pairs in OpenAI / Alpaca / plain JSONL format - ready for fine-tuning and RAG.",
        "version": "0.1",
        "x-build-id": "Ihb6D6ErOnF7lb5qm"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/deniz_schloesser~qa-dataset-extractor/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-deniz_schloesser-qa-dataset-extractor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/deniz_schloesser~qa-dataset-extractor/runs": {
            "post": {
                "operationId": "runs-sync-deniz_schloesser-qa-dataset-extractor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/deniz_schloesser~qa-dataset-extractor/run-sync": {
            "post": {
                "operationId": "run-sync-deniz_schloesser-qa-dataset-extractor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "startUrls"
                ],
                "properties": {
                    "startUrls": {
                        "title": "Start URLs",
                        "type": "array",
                        "description": "Pages to crawl. The crawler follows links on the same domain until 'Max pages' is reached.",
                        "items": {
                            "type": "object",
                            "required": [
                                "url"
                            ],
                            "properties": {
                                "url": {
                                    "type": "string",
                                    "title": "URL of a web page",
                                    "format": "uri"
                                }
                            }
                        }
                    },
                    "maxPagesToCrawl": {
                        "title": "Max pages to crawl",
                        "minimum": 1,
                        "maximum": 5000,
                        "type": "integer",
                        "description": "Hard limit on the number of pages crawled.",
                        "default": 10
                    },
                    "maxQuestionsPerChunk": {
                        "title": "Max Q&A pairs per chunk",
                        "minimum": 1,
                        "maximum": 20,
                        "type": "integer",
                        "description": "How many question-answer pairs the model should generate per content chunk.",
                        "default": 3
                    },
                    "chunkSize": {
                        "title": "Chunk size (characters)",
                        "minimum": 500,
                        "maximum": 16000,
                        "type": "integer",
                        "description": "Target size of each content chunk fed to the model.",
                        "default": 4000
                    },
                    "chunkOverlap": {
                        "title": "Chunk overlap (characters)",
                        "minimum": 0,
                        "maximum": 4000,
                        "type": "integer",
                        "description": "Characters of overlap between consecutive chunks to preserve context. Automatically capped at half the chunk size.",
                        "default": 200
                    },
                    "outputFormat": {
                        "title": "Output format",
                        "enum": [
                            "openai",
                            "alpaca",
                            "plain"
                        ],
                        "type": "string",
                        "description": "Schema of each dataset item.",
                        "default": "openai"
                    },
                    "model": {
                        "title": "Model",
                        "enum": [
                            "claude-haiku-4-5",
                            "claude-sonnet-4-6",
                            "claude-opus-4-8"
                        ],
                        "type": "string",
                        "description": "Claude model used to generate the Q&A pairs.",
                        "default": "claude-haiku-4-5"
                    },
                    "anthropicApiKey": {
                        "title": "Anthropic (Claude) API key",
                        "type": "string",
                        "description": "Your Anthropic API key (sk-ant-...). Required unless 'Dry run' is enabled."
                    },
                    "customInstructions": {
                        "title": "Custom instructions (optional)",
                        "type": "string",
                        "description": "Extra guidance for the model, e.g. 'Write answers in German' or 'Focus on pricing and setup questions'."
                    },
                    "dryRun": {
                        "title": "Dry run (no LLM, no cost)",
                        "type": "boolean",
                        "description": "Skip the LLM step and just output the extracted chunks. Use this to test crawling/chunking for free.",
                        "default": false
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
