Skip to main content
Extract fills a JSON Schema from a document. not_found on a field is an answer about the document, not an HTTP error. Exactly one of json_schema / schema or schema_id is required.
Reuse a parse with ParseResultSource so the parse is not paid for twice. On a parse-result source, page_ranges keeps only those pages of the reused parse. For checkbox forms, choose parse_mode="medium" or parse_mode="high" on the original Parse request and check that its output preserves the selection marks. The default low-effort parse may omit them. Extract reuses a ParseResultSource as it is; it does not reparse the form to recover missing marks. To change parsing effort, create a new parse from the original upload or URL and extract from that new result. Validate a schema first with client.documents.validate_extract_schema or POST /v1/extract/schema-validation. Register reusable schemas with extraction schemas and pass schema_id.

Supported schema keywords

Extract supports a limited subset of JSON Schema. The root must have "type": "object" and a non-empty properties object.
  • Supported keywords: type, properties, items, required, description, enum, title, additionalProperties, maxItems, and uniqueItems.
  • additionalProperties is supported only as false.
  • maxItems and uniqueItems apply only to arrays directly inside the root object’s properties.
  • Common JSON Schema forms are accepted and rewritten into this subset, so a schema generated from a Pydantic model works as is:
    • $ref into $defs (or definitions) is inlined. A recursive $ref is rejected.
    • anyOf/oneOf of one type and {"type": "null"} becomes a nullable type.
    • const becomes a one-value enum. The field still needs an explicit type.
    • format, pattern, minimum, maximum, minLength, maxLength, minItems, default and examples are kept as guidance in the field’s description. Extract does not enforce them on extracted values. The same applies to maxItems and uniqueItems on nested arrays.
    • $schema, $id, $comment, deprecated, readOnly and writeOnly are dropped.
  • Other keywords, such as allOf or other unions, are rejected with 422 invalid_schema.
The validation endpoint returns the rewritten schema in normalized_schema. warnings lists only the keywords kept as guidance in a field’s description, one entry per node with its path. Inlined $refs, nullable anyOf/oneOf, const rewritten to enum and dropped metadata appear only in normalized_schema, so compare it with your schema to see them. A rejected schema lists every problem at once. The validation endpoint returns them in errors, and a rejected extract returns them in the 422’s error.detail.errors. Each entry has a path, the JSON Pointer of the offending node (for example /properties/lines/items/properties/amount), and a message. For dates, "format": "date" works, or describe the representation yourself:
Descriptions guide extraction but do not enforce date validation. Validate returned dates in your application if strict date validation is required. When a document names related records, put their known names in an enum on each link’s key field. Enums also work on leaves inside nested arrays. For example, this schema requests film–actor links using names from your own catalog:
Pass this as json_schema to Extract with your document source. Build each enum from the records you already know; the example lists are placeholders for your catalog. Include null to represent a missing match and declare the key nullable ("type": ["string", "null"]), as in the example. Null in an enum on a plain "string" is rejected. Each enum accepts at most 100 values, including null, so a nullable key can list up to 99 names. The complete schema must fit within 50,000 characters when serialized with a space after each : and ,. The same limit applies after normalization: inlined references, const converted to enum, and guidance moved into descriptions can make the schema longer. It can define at most 128 properties and nest at most 5 properties or items levels below the root. The key fields above are already at that depth, so do not wrap this example in another object. Check a schema near these limits with schema validation first. Map each returned name to its stored ID in your application. Request the names needed for that lookup; omit database ID fields when the document does not print IDs: a requested ID the document does not print may come back as an invented value rather than null. An enum supplies candidate values, not their IDs or a uniqueness guarantee. Extract constrains or validates enum fields against your listed values, so a name the document prints that is not in your enum is not returned as written: it comes back as null or an absent link, or it may be matched to a listed name that resembles it. Treat every returned key as a candidate and confirm it against the source text before linking records; a missing or null key is not proof that the document names no other record. The original recipe evaluation did not test absent candidates. Use unambiguous names, handle duplicate names and aliases in your application, and check both that a returned key belongs to your catalog and that the document supports the relationship. A missing match may be an absent or empty link array, a null key, or a link item without key. Validate the returned data before using it to update records. This recipe is for small candidate sets. It does not establish exhaustive matching against a larger table, and independent enums do not constrain which film–actor pairs are valid. Do not truncate a larger catalog and interpret missing links as evidence that the document contains no matching records.

Options

Next