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. Not with a parse_result source. 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", the only value a parse_result source takes.

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

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