Skip to main content
Code is in Beta. Its shape may change without a version.
Code runs a function you write. You give it Python source that defines transform(input_data: Input) -> Output, and the fields of Output. For each document the node runs your function in a sandbox with no network access and stores the JSON object it returns. No model writes or checks the code when a document runs, and saving the workflow stores the code only. Nothing runs until a document does. In Studio, you can describe what the function should do and ask for a draft. The draft replaces the code in the editor, uses the node’s Input and the fields of Output, and is not run or saved until you do it. Check it before you save.

The node

Options

The node does not accept the retired instructions and template fields. The schema the API accepts is generated from the same source: Code node schema.

What the function receives

  • After an Extract, Input has one field for each extracted field, named by the field’s sanitized name (the name made safe as a Python identifier). Every value can be None. A value that does not fit its declared type arrives as text. There is no confidence and no evidence.
  • After a Parse, Input holds pages, and each page holds number, text and blocks.
A node behind a splitter runs once per split.

Limits

The code may not exceed 64 KiB (65,536 bytes of UTF-8). The function runs for at most 60 seconds and 1024 MB of memory. Its output may not exceed 1 MiB. A run that breaks a limit, raises, or returns something that is not a valid Output fails the whole run.

When the function fails

If your function raises, returns something that does not match output_schema, writes more than 1 MiB, or runs out of time or memory, the run ends in error. It is not retried, because the same code would fail on the same document, and it is not charged. The error message names the exception and the lines of your code that raised it; fix the code and run the document again. The error message is recorded on the node’s run, but the public run response carries only status: error and no reason yet. An organization with zero data retention records only the exception type. A succeeded function bills 5 credits for each run of the node, once per split behind a splitter.

Connects to

The Python and TypeScript builders attach the node to the single Extract, or to Parse when the workflow has no Extract. Send the node in the API JSON to attach it to one branch of a classified workflow.

What it returns

The node fills the code_outputs section of the run results: one entry per split the node ran for.
status is succeeded. A function that fails ends the run in error, and a failed run has no results, so the value is always succeeded. output is the JSON object your function returned, and null when its stored output is no longer available. In the SDKs, result.code_outputs (Python) and result.codeOutputs (TypeScript) hold the same entries.