# Custom Python, SQL, and formula processing

Use built-in mapping, filtering, grouping, and extraction before adding custom code. A smaller declarative step is easier to inspect and maintain. Use custom processing when the built-in operation cannot express the required transformation clearly.

## Python snippets

Python exec provides a restricted execution environment. The snippet reads `records`, a list of input objects, and appends output objects to `out`.

```python
for record in records:
    amount = record.get("amount")
    if isinstance(amount, (int, float)):
        out.append({"id": record.get("id"), "amount": amount * 100})
```

The default snippet passes records through. Supported imports are restricted; arbitrary filesystem, network, operating-system access, and installed libraries should not be assumed. An unsupported isolated execution fails rather than falling back to unrestricted processing.

The built-in settings bound code length, timeout, and allocation. Common defaults are 30 seconds and 256 MB, with allowed timeout and memory ranges shown in the form. Those values do not override wider platform or handler limits.

## SQL operations

SQL query supports a configured read or write operation. Read mode requires a query and cursor column and returns a bounded page of rows. Its default limit is 500 and the declared maximum is 10,000. Incoming records are not automatically substituted into a read query.

Write mode inserts incoming records into the configured table. A plain insert can duplicate rows after retries. PostgreSQL natural-key upsert columns provide different repetition behavior; choose keys backed by an appropriate uniqueness rule.

Prefer managed connection workflows for credentials and routine database access. Never put connection secrets into public examples, prompts, or sample output.

## Formulas and templates

For field-level expressions, use [Map fields](/docs/steps/map) and its supported functions rather than embedding a general programming language. Test null and invalid-type cases explicitly.

Validate with representative input, then check an actual small run. Custom code can be syntactically valid while producing an incompatible output shape. See [Python exec](/docs/steps/python-exec), [SQL query](/docs/steps/sql-query), and [reliability](/docs/workflows/reliability).
