Perception

Extract

client.documents.extract(params, options?) fills a JSON Schema from a document. params is an ExtractParams: the shared parameters, and either an inline schema or a saved schema_id, never both.

ParameterTypeRequiredDescription
schemaRecord<string, unknown>Yes, or schema_idThe fields to extract, as a JSON Schema.
schema_idstringYes, or schemaA saved schema's id (sch_...).
schema_versionnumberNoThe saved version to use, with schema_id only. Default: the latest.
instructionsstringNoExtra guidance for filling the declared fields. Can't add fields the schema doesn't list.
page_rangesArray<{ start, end }>NoPages to read. With a parse_result source, keeps only those pages of the earlier parse. Default: all pages.
citations{ enabled?, include_source_text? }NoWhere each field was read from. See citations.
parse_mode"low" | "medium" | "high"NoHow hard the parse behind the extraction works. A parse_result source runs at low whatever you pass, with a note in the result's warnings. Default: "low".

Both schema and schema_id, neither of them, or a schema_version without schema_id fail to compile, and throw a NaceError before sending if the types are bypassed.

Schemas must use the supported schema keywords. format is converted to descriptive guidance for the extraction model. Match the hint to the field, such as date for an invoice date. Guidance can influence the returned value; validate that value in your application if a strict format is required. For dates, you can also use a string and put the desired representation in description.

citations

KeyTypeDefaultDescription
citations.enabledbooleantrueSay where in the document each field was read.
citations.include_source_textbooleantrueAdd a short quote from the source.
extract.ts
const parsed = await client.jobs.wait(
  (await client.documents.parse({ source: "https://example.com/invoice.pdf" })).job_id,
);

const job = await client.documents.extract({
  source: { type: "parse_result", job_id: parsed.job_id },
  schema: {
    type: "object",
    properties: { invoice_number: { type: "string" }, total: { type: "number" } },
    required: ["invoice_number", "total"],
  },
});
const done = await client.jobs.wait(job.job_id);
console.log((done.result as { data: unknown }).data); // { invoice_number: 'INV-1042', total: 1200.5 }

See Extract for the result: data, shaped by your schema, and fields, one entry per schema field with its path, value, status (found, not_found or ambiguous), confidence and citations.

On this page