Skip to main content

Overview

An extraction schema is a JSON object that defines which fields to extract from a document and how to structure the output. You pass the schema to the API along with Markdown content generated by the API. Use this article as a reference for understanding how schemas are structured and how the API handles unsupported keywords.

Basic Structure

The extraction schema must follow this structure:
Example This schema extracts two fields from an invoice. It also includes the optional x-alternativeNames keyword to account for field name variations across documents:

Top-Level Type Requirement

The top-level type keyword must be "object". Schemas with a different top-level type will return an error. In the following example, the highlighted line shows the required top-level type keyword:

Define Each Field

Each field you want to extract is defined as a property inside the properties keyword. Each property can include the following:

Field Names

Required. The field name is the key that identifies each property in the properties object and determines how the extracted value is labeled in the output. Field names can contain letters, numbers, underscores, and hyphens. Use descriptive, specific names that clearly indicate what data to extract:
  • invoice_number instead of number
  • patient_name instead of name
In the following example, the highlighted lines are field names:

Supported Field Types

Required. Use the type keyword to define the data type of the extracted value. Supported types are: In the following example, the highlighted line shows the type keyword:
To restrict a field to a specific set of allowed values, use the enum keyword.

Restrict Values with Enum

Optional. Use the enum keyword to restrict the extracted value to a specific set of allowed values. Only string values are supported. Include "type": "string" in the field definition. Any non-string values are converted to strings. For example, the following schema restricts the extracted account type to one of three allowed values. The highlighted lines show the type and enum keywords:
In the Playground, “enum” appears as a field type option in the Type drop-down menu. When you export the schema, the Playground outputs this correctly using the enum keyword.

Field Descriptions

Optional. Use the description keyword to help the API identify and extract the correct data. The more specific your descriptions, the more accurate the extraction. Include the following in your descriptions:
  • Exactly what data to extract
  • What to include or exclude (for example, “excluding tax” or “including area code”)
In the following example, the highlighted line shows the description keyword:

Format

Optional. Use the format keyword to specify how the extracted value should be formatted. This is most commonly applied to string fields. The format keyword accepts natural-language instructions and standard JSON Schema format values. Natural-language instructions offer more flexibility, since you can describe formatting requirements that don’t have a standard equivalent. We recommend experimenting with different values to find what works best for your use case. The following examples illustrate the range of options: In the following example, the highlighted line shows the format keyword:

Alternative Names

Optional. Use the x-alternativeNames keyword to list alternative labels for a field. This helps the API locate the correct data when documents use different labels for the same field, such as “Invoice Number” versus “Reference Number.” In the following example, the highlighted lines show the x-alternativeNames keyword:

Properties (For Objects)

Required for object types. Use the properties keyword to define the fields within a nested object. For a full example, see Nested Objects.

Format Arrays with items

Required for array types. Use the items keyword to define the structure of items in an array. For a full example, see Arrays.

Nested Objects

Use nested objects when the data you want to extract has a natural hierarchical structure. For example, an invoice might include a billing address with multiple sub-fields (street, city, state, and ZIP code), or a patient form might have separate sections for personal details and insurance information. In the following example, the highlighted lines show a nested properties keyword inside the invoice object:

Arrays

Use arrays to extract repeating structures from a document, such as all rows in a table. Each item in the array follows the same schema, making arrays well-suited for data like transaction lists, invoice line items, or lists of charges. To define an array field:
  1. Set "type": "array" on the field.
  2. Include the items keyword to define the structure of each item.
  3. Inside items, define the fields each item should contain.
The following example extracts financial transactions from a bank statement, where each transaction is an object with three fields:

Keyword Support

The API only supports a specific set of JSON Schema keywords. Unsupported keywords are removed before extraction runs; they do not cause errors.

Supported Keywords

The API supports the following keywords. For details on each, see Define Each Field.

Ignored Keywords

The following keywords are not supported but will not cause errors. The API removes or resolves them before running extraction.

Other Unsupported Keywords

Any keyword not listed in Supported Keywords or Ignored Keywords is removed during schema conversion, and extraction continues with the remaining schema. The following list provides common examples and is not exhaustive:
  • allOf
  • const
  • maxItems
  • maxLength
  • maximum
  • minItems
  • minLength
  • minimum
  • oneOf
  • pattern
  • propertyOrdering
  • uniqueItems

How the API Handles Required Fields

The API treats all fields as required and always attempts to extract every property defined in your schema. The required keyword is not supported and is ignored if included. For more information, see Ignored Keywords. If the API cannot find a field in the document, it returns null rather than an error. For more information, see How the API Handles Missing Fields.

How the API Handles Missing Fields

All fields are nullable, meaning the API returns null when it cannot find a field in the document rather than returning an error. Because of this, the API ignores null and nullable if included in your schema. For more information, see Ignored Keywords. For example, if your schema includes a first_name field but the document does not contain a first name, the API returns null for that field. The exact behavior depends on the field type:

Schema Validation

The API processes your schema in two stages:

Validate Schema Structure (Before Extraction)

The API checks that your schema is valid JSON and follows the required structure. If validation fails, the API returns a 422 error before processing begins. Common causes are a schema that is not valid JSON, a root that is not "type": "object", or recursive $ref cycles.

Convert Schema (During Processing)

The API converts your schema before running extraction. Keywords that are not supported are removed during this step (see Ignored Keywords and Other Unsupported Keywords), and extraction continues with the remaining schema.

FAQs for Extraction Schemas

Does the order of properties in the schema need to match the order of the fields in the document?

No. The order of properties in the schema has no impact on extraction. For example, a property defined last in the schema can still extract data from a field that appears at the top of the document.

Is there a maximum number of fields that can be extracted?

No. There is no maximum number of properties in an extraction schema.

Can I put formatting and alternative names in the description field?

You can include formatting instructions and alternative field names in description, but using the dedicated format and x-alternativeNames keywords is more effective. When you use dedicated keywords, the API knows exactly what each piece of information is: format contains only formatting instructions, and x-alternativeNames contains only alternative field labels. This allows the API to apply each more precisely than if the same information were embedded in a general description. For more information, see Format and Alternative Names.

What is the best practice for writing field descriptions?

Be as specific as needed so there is no ambiguity about what to extract. Think of it as natural-language instructions (like prompting an LLM). The clearer and more specific it is, the better the results. You may want to iterate on your descriptions to find what works best for your use case. For more information, see Field Descriptions.