Skip to main content
Code Execution stage showing custom code transformations
The Code Execution stage allows you to run custom Python code to transform, filter, or enrich documents. This provides maximum flexibility for complex logic that can’t be expressed with other stages.
Stage Category: APPLY (Transforms documents)Transformation: N documents → M documents (custom logic)

When to Use

When NOT to Use

Parameters

Configuration Examples

Code Structure

Your code must define a transform function:

Available in Scope

Input Document Structure

Output Options

Performance

Code execution adds latency. Keep transformations simple and avoid heavy computation. For complex processing, consider pre-computing during ingestion.

Common Pipeline Patterns

Custom Scoring Pipeline

Data Normalization Pipeline

Advanced Filtering

Security

Allowed Packages

Built-in packages available:
  • json, re, math, datetime, collections
  • itertools, functools, operator
The sandbox provides a standard runtime environment for the selected language.

Error Handling

Always handle missing fields gracefully using .get() with defaults to avoid runtime errors.

Debugging

Enable debug mode to see execution details: