Skip to content

AI Extract

Type: ai-extract  ·  Package: AI Activities v1.0.0  ·  Output: object

Extracts specific fields from a document using a large language model. You describe the fields you want with a JSON Schema and the model is required to answer in exactly that shape, so the result is used directly as an object.

This is the activity for reading documents whose layout changes: the same configuration reads one supplier’s invoice and another’s, because you describe what each field means rather than where it sits.

Sends the model the prompt (the document text), the images if there are any, and the schema. The answer arrives already validated against the schema and is returned as an object, ready to read with result["field"].

ParameterEditorDescription
credentialcredentialZoan Cloud credential holding the provider’s API key.
promptexpressionThe document text to extract from, plus any instruction about it.
schemaJSONJSON Schema of the object to extract. The root must be "type": "object".
ParameterEditorDescription
providerenumAI provider. Defaults to Anthropic (Claude).
modelexpressionModel id. Leave empty to use the provider’s default model.
systemexpressionSystem instructions: what kind of document this is and how to read it.
imageslistPaths of images to extract from (.jpg, .png, .gif, .webp).
effortenumHow much work the model puts in: low, medium, high, xhigh, max.
thinkingbooleanLet the model reason before answering.
maxTokensexpressionMaximum size of the extracted object, in tokens. Default 16000.
timeoutexpressionSeconds to wait. Default 600.

Returns an object shaped as defined in schema. Read the fields with result["name"].

The model reads the description of each field to decide what belongs in it, so write them the way you would explain them to someone seeing the document for the first time:

{
"type": "object",
"properties": {
"number": { "type": "string", "description": "Invoice number exactly as printed" },
"date": { "type": "string", "description": "Issue date in YYYY-MM-DD format" },
"total": { "type": "number", "description": "Total amount including taxes" },
"supplier": { "type": "string", "description": "Legal name of the issuing company" }
},
"required": ["number", "date", "total", "supplier"],
"additionalProperties": false
}

Read a PDF invoice and use its fields:

PDF Get Text path = = invoicePath → output: text
AI Extract credential = = credential("anthropic-key")
prompt = = text
schema = {…}
→ output: invoice
Log message = = "Invoice " + invoice["number"] + ": " + invoice["total"]

Extract from a scanned document, going through OCR first:

PDF To Images path = = scanPath dpi = 200 → output: pages
OCR Get Lines path = = pages[0] → output: lines
AI Extract credential = = credential("anthropic-key")
prompt = = join(map(lines, "l => l[\"text\"]"), "\n")
schema = {…}
→ output: equipment
MessageWhat happened
'schema' must be a JSON Schema whose root is "type": "object"The schema asks for a list or a bare value. Wrap it in an object with a field holding that list.
The model hit the 'maxTokens' limit before finishingThe extracted object does not fit. Raise maxTokens or ask for fewer fields per call.
The credential does not contain an Anthropic API keyThe credential exists but is empty or holds something else.
Claude declined this request for safety reasonsThe model refused the content. This is an answer from the model, not a configuration failure.
  • AI Complete — when you want text instead of fields.
  • PDF Get Text — get the text before extracting.
  • OCR — read scanned documents.
  • Queue Process — extract a large batch of documents with retries.