# URL to Structured Rows - LLM Extraction with Your JSON Schema (`omar_jarvis/url-to-structured-rows`) Actor

Give a list of URLs and a JSON Schema. Get one schema-valid row per URL, filled by an LLM (your own Claude, Gemini or OpenAI key) from the page text. Off-schema output is never returned and never charged.

- **URL**: https://apify.com/omar_jarvis/url-to-structured-rows.md
- **Developed by:** [Omar Nassar](https://apify.com/omar_jarvis) (community)
- **Categories:** AI, Automation
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$2.00 / 1,000 valid rows

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

## URL to Structured Rows: LLM Extraction with Your JSON Schema

Give a list of URLs and a JSON Schema. The actor returns **one row per URL that is valid against your schema**. An LLM fills the schema from the page text, with your own Claude, Gemini or OpenAI API key.

### How it works

1. The actor fetches each URL with a plain HTTP request. It does not use a browser.
2. It extracts the visible text and any JSON-LD structured data (schema.org Product, Person, Organization).
3. It sends the text, your schema and your instructions to the model. The model uses constrained JSON output where the provider supports it.
4. It validates the answer against your full schema with Ajv (draft-07 or 2020-12, formats included).
5. If the answer is not valid, the actor asks the model once more and tells it what failed.
6. If the second answer is also not valid, the row is dropped. **Off-schema data is never returned and never charged.**

### Input

```json
{
  "urls": [
    "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html",
    "https://www.scrapingcourse.com/ecommerce/product/abominable-hoodie/"
  ],
  "schema": {
    "type": "object",
    "properties": {
      "name": { "type": "string" },
      "price": { "type": "number", "minimum": 0 },
      "currency": { "type": "string", "pattern": "^[A-Z]{3}$" },
      "sku": { "type": ["string", "null"] },
      "in_stock": { "type": "boolean" }
    },
    "required": ["name", "price", "currency", "sku", "in_stock"]
  },
  "instructions": "price is the main selling price. currency is the ISO 4217 code.",
  "provider": "anthropic",
  "apiKey": "<your Anthropic API key>"
}
```

| Field | Required | Description |
|---|---|---|
| `urls` | yes | Page URLs. One row per URL. Duplicates are removed. Up to 5,000 per run. |
| `schema` | yes | JSON Schema for one row. |
| `apiKey` | yes | Your own API key for `provider`. Secret input, stored encrypted by Apify. |
| `instructions` | no | Plain-language instructions for the model. |
| `provider` | no | `anthropic` (default), `gemini` or `openai`. |
| `model` | no | Model ID. Defaults: `claude-haiku-5-5`, `gemini-2.5-flash-lite`, `gpt-4.1-mini`. |
| `maxChars` | no | Page text is cut at this length (default 30,000). Lower means fewer tokens. |
| `concurrency` | no | URLs in parallel (default 5, max 20). |

### Output

This row is from the local test run, where the model was mocked:

```json
{
  "url": "https://sandbox.oxylabs.io/products/1",
  "data": {
    "name": "The Legend of Zelda: Ocarina of Time",
    "price": 91.99,
    "currency": "EUR",
    "sku": null,
    "in_stock": true
  },
  "final_url": "https://sandbox.oxylabs.io/products/1",
  "title": "The Legend of Zelda: Ocarina of Time | Oxylabs Scraping Sandbox",
  "text_chars": 2019,
  "truncated": false,
  "model": "mock/mock",
  "attempts": 2,
  "tokens": { "input": 1810, "output": 55 },
  "error": null,
  "checked_at": "2026-11-09T20:29:59.659Z"
}
```

`data` always matches your schema. `tokens` shows what your provider bills for the row, including the retry.

Failed URLs are returned with `error` set and are **not charged**. Causes: HTTP 4xx or 5xx, timeout, a page with almost no text in its HTML (rendered by JavaScript), or model output that failed the schema twice.

### Pricing

**$0.002 per valid row** (pay per event `row`). Failed and dropped rows are not charged.

Your model provider bills you for tokens directly. A typical page (about 6,000 characters of text) costs about $0.0005 with `claude-haiku-5-5` and about $0.0003 with `gemini-2.5-flash-lite`.

A hosted-key option, where you do not need your own model key, can come later at a higher per-row price.

### Limits

- No browser. Pages that render their content with JavaScript and have no JSON-LD fail with an error and are not charged.
- Each URL has a hard timeout of 180 seconds.
- Provider-side constrained decoding does not support every JSON Schema keyword (for example `minimum`, `pattern`, `minItems`). The actor removes those keywords from the copy sent to the provider. Ajv still enforces them on the answer.
- Page text is untrusted. The model is told to treat it as data and to ignore instructions inside it.
- The actor stops starting new URLs when your **Max cost per run** is reached.

### Local test

`bash test/mock-test.sh` runs both test inputs with real page fetches, real schema validation, pay-per-event test mode and a **mocked model** (`test/mock-replies.json`, enabled by the `URL_ROWS_MOCK` environment variable). `scripts/test-all.sh` needs a real key in `test/input.json` for this actor.

# Actor input Schema

## `urls` (type: `array`):

One page URL per line. Each URL gives one row. Duplicates are removed.

## `schema` (type: `object`):

The JSON Schema that every row must match (draft-07 or 2020-12). Rows that do not match after one retry are dropped and not charged.

## `instructions` (type: `string`):

Optional plain-language instructions for the model, e.g. "price is the sale price including VAT".

## `provider` (type: `string`):

Which provider your API key is for.

## `apiKey` (type: `string`):

Your own API key for the selected provider. The provider bills you for tokens. Stored encrypted by Apify.

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

Optional model ID. Defaults: claude-haiku-5-5 (Anthropic), gemini-2.5-flash-lite (Gemini), gpt-4.1-mini (OpenAI).

## `maxChars` (type: `integer`):

Page text sent to the model is cut at this length. Lower means cheaper tokens.

## `concurrency` (type: `integer`):

How many URLs to process in parallel.

## Actor input object example

```json
{
  "urls": [
    "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html"
  ],
  "schema": {
    "type": "object",
    "properties": {
      "name": {
        "type": "string"
      },
      "price": {
        "type": "number"
      },
      "currency": {
        "type": "string"
      },
      "sku": {
        "type": [
          "string",
          "null"
        ]
      }
    },
    "required": [
      "name",
      "price",
      "currency",
      "sku"
    ]
  },
  "provider": "anthropic",
  "maxChars": 30000,
  "concurrency": 5
}
```

# Actor output Schema

## `results` (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 = {
    "urls": [
        "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html"
    ],
    "schema": {
        "type": "object",
        "properties": {
            "name": {
                "type": "string"
            },
            "price": {
                "type": "number"
            },
            "currency": {
                "type": "string"
            },
            "sku": {
                "type": [
                    "string",
                    "null"
                ]
            }
        },
        "required": [
            "name",
            "price",
            "currency",
            "sku"
        ]
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("omar_jarvis/url-to-structured-rows").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 = {
    "urls": ["https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html"],
    "schema": {
        "type": "object",
        "properties": {
            "name": { "type": "string" },
            "price": { "type": "number" },
            "currency": { "type": "string" },
            "sku": { "type": [
                    "string",
                    "null",
                ] },
        },
        "required": [
            "name",
            "price",
            "currency",
            "sku",
        ],
    },
}

# Run the Actor and wait for it to finish
run = client.actor("omar_jarvis/url-to-structured-rows").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 '{
  "urls": [
    "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html"
  ],
  "schema": {
    "type": "object",
    "properties": {
      "name": {
        "type": "string"
      },
      "price": {
        "type": "number"
      },
      "currency": {
        "type": "string"
      },
      "sku": {
        "type": [
          "string",
          "null"
        ]
      }
    },
    "required": [
      "name",
      "price",
      "currency",
      "sku"
    ]
  }
}' |
apify call omar_jarvis/url-to-structured-rows --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,omar_jarvis/url-to-structured-rows"
        }
    }
}
```

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/UewMpPwexcH32ygy2/builds/B0VdeBZjSIqeL87n8/openapi.json
