Skip to main content
With only a prompt, the AI decides the shape of the answer: field names, types and nesting can change between pages and runs, and prices come back as text like "£51.77". Add a schema and every result has exactly the fields and types you define. Use one whenever code reads the result. Schemas work on Scrape, Batch scrape, Crawl and Parse.

A first schema

result.content:
  • price is the number 51.77; the £ moved into currency.
  • in_stock is a real boolean, not the text “In stock”.
  • rating is null: the site shows its stars as an image, and Spidra reads the page’s text.
It cost 2 credits: 1 for the page and 1 for the AI.

Every field comes back

Every field in your schema is in the result. When the page doesn’t have a value, the field is null; it’s never left out. On a book page with no ISBN:
The answer was the same whether required listed the fields or not, so code can always read every key. Give fields that may be missing a nullable type, as below, so null is a valid value.

Nullable fields

Write the type as a list that includes "null":
This works for every type: ["number", "null"], ["boolean", "null"], ["array", "null"].

Lists of items

The root of a schema is always an object. To get a list, put an array inside it:
That returned all 20 books on the page. The first three:
A flat schema (no array) on a list page returns one item. In a crawl, the schema runs on every returned page, so write it for one page of the kind you asked for.

Fixed choices with enum

enum limits a field to the values you list. Include null for “none of these”:
stars is null because the rating isn’t in the page’s text.

Nested objects

Define properties inside a property:

Prompt and schema together

The schema sets the shape; the prompt tells the AI what to pick and how to write it. Here the prompt filters the quotes and lowercases the tags:
(Shortened to two of the Einstein quotes on the page.)

Generate a schema from Zod or Pydantic

Spidra takes standard JSON Schema, so you can generate it from the models you already have.
Validating the result with the same model gives you typed data end to end. There’s also a visual JSON Schema generator.

What a schema can contain

Supported keywords: type (including lists with "null"), properties, required, items, enum, description and nullable. A description on a field is a good place for hints (“price without the currency symbol”). Keywords Spidra can’t use, such as $ref, oneOf, allOf, not and if, are ignored, and the submit response lists them in schema_warnings:
The job still runs. Pydantic writes Optional fields as anyOf with null, which shows this warning; those fields still come back, as null when missing.

Schema errors

A schema with a structural problem is refused with 422 before anything runs, and nothing is charged:
  • The root type must be "object". Wrap lists in an object property, as above.
  • Nesting goes 5 levels deep at most.
  • The schema can be up to 10 KB.

Sites that come back structured already

Links from supported sites such as Amazon, Google Maps and LinkedIn have the site’s own fields in structuredData, and with "output": "json" and no prompt or schema those fields are the content, with no AI. Add a schema only if you want to reshape them.