Skip to main content
Function blocks execute sandboxed function code. The language config field currently supports Python, where code receives upstream data as a typed Input Pydantic model and returns a typed Output model, enabling arbitrary transformations, validations, and computed fields.

Overview

When processing documents, you often need values that aren’t directly extracted but can be computed from other fields. For example:
  • Line item totals: quantity * unit_price
  • Invoice totals: Sum of all line item amounts
  • Reconciliation checks: Verify that computed totals match stated totals
  • Conditional values: Apply different logic based on field values
With language: "Python", function blocks let you write Python code with access to the full standard library plus packages like pydantic, pandas, numpy, duckdb, and rapidfuzz.

Configuration


Output Schema

Define the output contract as a JSON schema:

Code

Import the auto-generated Input and Output models from the virtual models module:

Validation Patterns

Function blocks are commonly used after Extract blocks to validate extracted data.

Sum Check

Verify a total matches the sum of its parts:

Difference Check

Verify a result equals A - B - C:

Equality Check

Verify two fields match:

Conditional Labeling

Categorize values:

String Extraction

Extract structured parts from text:

Fuzzy Matching with DuckDB

Look up values in a mounted workflow table:

Available Packages

Standard library (json, re, datetime, math, os, collections, itertools, etc.), plus:
Outbound network access is disabled inside function sandboxes. Use the api_call block when you need to call external HTTP APIs, then pass the response into the function block.

Workflow Tables

Mount workflow tables (managed via the Tables UI or API) as CSV files in the sandbox:
Use /tmp/ or /data/ as the mount prefix. See Workflow Tables for CSV upload rules, query APIs, validation, and more table examples.

Rules

  1. Always provide an output_schema that matches what transform() returns.
  2. transform() must accept input_data: Input and return an Output instance.
  3. Access input fields via dot notation: input_data.field_name.
  4. Do not redefine the Input class — it is auto-generated from the upstream block’s schema.
  5. If the output is nested, return plain dict/list structures matching output_schema.
  6. Use os.environ["VAR_NAME"] for secrets — never hardcode credentials.

Go Further

  • Extraction - Learn how to extract structured data, design schemas, add reasoning prompts, and inspect provenance
  • Schema - Design your extraction schemas