Schema (JSON Schema)
JSON Schema Structure (schema
)
We use JSON Schema to define the structure of the data we extract. Before you get started, we recommend familiarizing yourself with the JSON Schema documentation to understand how to define your schema.
The standard JSON Schema is extremely flexible. We’ve implemented a subset of the standard to support the needs of document extraction. Your schema must follow these rules:
- The root must be an
object
type - Allowed types are
string
,number
,integer
,boolean
,object
, andarray
- All primitive fields (
string
,number
,boolean
,integer
) must be nullable (use array type with “null” as an option e.g."type": ["string", "null"]
). If you do not provide a “null” option, it will be automatically added. - Maximum nesting level is 3 (each non-root object counts as 1 level)
- Property keys and names can contain letters, numbers, underscores, and hyphens
- Array items must be objects
- Enums must only contain strings and must contain a
null
option. If you do not provide anull
option, it will be automatically added. - Custom types are supported by adding a
"extend:type": "currency"
,"extend:type": "signature"
, or"extend:type": "date"
property to the appropriate field type with the required properties. See below for examples. - Property names can be added using the
"extend:name"
property. If supplied, this will override the name of the property as it will appear to the model, but not in the output returned to you. This is useful for providing more descriptive names or instructions to the model without altering the actual keys in your output data structure. - You can add descriptions to individual enum values using the
"extend:descriptions"
property.
Unsupported Features
While we support the JSON Schema structure, we do not support many of the additional features some of which include:
- Schema composition like
anyOf
,oneOf
,allOf
, schema definitions, or recursive schemas - Regular expressions and other type-specific validation keywords
- Conditional schema validation
- Constant values
Schema Examples
Primitive Schema
All primitive types must be nullable.
Object Schema
Objects must have properties. If you set a required array of the properties, we will respect that order when extracting. If you do not set required array, we will generate it and enforce order.
Array Schema
Arrays items must be objects.
Enum Schema
Enums must include null as an option. Only strings are supported for enums. The extend:descriptions
is an optional array of strings. It is recommended to give more context for each enum option for more accurate extraction.
Custom Field Types
The extend:type
keyword enables custom pre-processing and post-processing of fields which bake in best practices and heuristics for the field type.
Date Schema
Date fields must be strings and use the extend:type
keyword with the value date
. This will guarantee the date format is always an ISO compliant date (yyyy-mm-dd).
Currency Schema
Currency fields must be objects with specific properties.
Signature Schema
Signature fields must be objects with specific properties. This will auto-enable our advanced signature detection in the parsing step prior to extraction, and apply a number of prompt and post-processing heuristics to improve accuracy, particularly on reduction of false positives for signature blocks that are not actually signed.