Docs
Reference

Functions

Breyta functions reference for reusable Clojure transforms in :function steps.

Quick Answer

Define transform logic once in :functions and call by stable :ref from flow/step :function to keep orchestration small and deterministic.

What Functions Are

functions define reusable Clojure transforms referenced by :function steps.

  • isolate shaping and normalization logic
  • keep orchestration readable
  • avoid duplicating transform code across steps

Definition Shape

Declare functions at top level:

{:functions [{:id :summarize
              :language :clojure
              :code "(fn [input] {:count (count (:rows input))})"}]}

Call from flow:

(flow/step :function :summarize-rows
  {:ref :summarize
   :input {:rows rows}})

Authoring Guidelines

  • keep function logic pure and deterministic
  • use functions for data transformation, not external side effects
  • use :function steps for non-trivial shaping/normalization, even if used once
  • keep inline :flow code focused on orchestration (ordering, branching, retries, waits)
  • keep ids stable; avoid renaming unless intentional
  • prefer multiline flow files over long one-line string literals

Runtime Notes

  • function code is resolved by :ref from the flow definition
  • when running a function step in isolation via CLI, include --flow <slug> so refs resolve
  • only allowlisted Java interop is available in the function runtime
  • sandboxed JSON helpers are exposed under json:
    • json/parse takes one string-or-bytes argument and keywordizes normal
      identifier-like JSON object keys by default
    • json/write-str serializes sandbox data back to a JSON string
    • keys that fail the conservative safety policy remain strings to avoid unbounded keyword interning
  • if :flow validation says it cannot resolve Long/parseLong or similar parser/helper calls,
    move that logic into a :function step or top-level :functions entry and use the supported
    breyta.sandbox/* or json/* helpers there

Example:

{:functions [{:id :parse-webhook
              :language :clojure
              :code "(fn [input]\n                      (let [payload (json/parse (:body input))]\n                        {:event (:event payload)\n                         :id (get-in payload [:data :id])}))"}]}

Troubleshooting

  • unresolved :ref: confirm function id exists and matches exactly
  • parse/EDN failures: validate file structure and avoid accidental escaped newlines outside strings
  • JSON parsing/emitting in sandboxed functions: use json/parse and json/write-str; safe
    identifier-like keys become keywords, unusual keys stay strings, json/parse does not accept
    parser option flags, and lower-level parser namespaces are not part of the supported
    function-runtime surface
  • runtime errors: run step in isolation first, then run full flow after fix

Related

As of May 15, 2026