Perception

Extract

client.documents.extract(source, *, schema=None, schema_id=None, schema_version=None, instructions=None, **options)

ParameterTypeRequiredDescription
sourcestr | UrlSource | WorkspaceFileSource | ParseResultSourceYesThe document to extract from. Reuse a finished parse with ParseResultSource so it isn't parsed and paid for twice.
schemadictYes, or schema_idThe fields to extract, as a JSON Schema.
schema_idstrYes, or schemaA saved schema's id (sch_...).
schema_versionintNoThe saved schema's version to use. Only with schema_id. Default: its latest version.
instructionsstrNoExtra guidance for filling the declared fields. Can't add fields the schema doesn't list.
page_rangeslist[dict]NoOne-based, inclusive ranges. With a parse_result source, keeps only those pages of the earlier parse. Default: all pages.
citationsdictNoWhere each field was read from. See citations.
parse_mode"low" / "medium" / "high"NoEffort of the parse Extract runs first. Default: "low". A parse_result source runs at "low" whatever you pass, with a note in the result's warnings.

Pass exactly one of schema and schema_id. Both, neither, or a schema_version without schema_id raises NaceError before anything is sent.

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.enabledboolTrueSay where in the document each field was read.
citations.include_source_textboolTrueAdd a short quote from the source.
extract.py
from nace_sdk import NaceClient, ParseResultSource

with NaceClient() as client:
    parsed = client.jobs.wait(client.documents.parse("https://example.com/invoice.pdf").job_id)
    job = client.documents.extract(
        ParseResultSource(job_id=parsed.job_id),
        schema={
            "type": "object",
            "properties": {
                "invoice_number": {"type": "string"},
                "total": {"type": "number"},
            },
            "required": ["invoice_number", "total"],
        },
        wait_seconds=60,
    )
    if job.status != "succeeded":
        job = client.jobs.wait(job.job_id)

print(job.result["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