Skip to content

AI Flows

Python step

Run your own Python code inside an AI flow to calculate, reshape or check data.

What it does#

A Python step runs code you write, with every earlier result as input. Use it when a rule is easier to write as code than as a prompt: calculating a price, cleaning a phone number, or combining several fields.

No AI model runs in a Python step. Its result is available to later steps as {{StepName}}.

The Python step

Add a Python step#

  1. 1

    Add a step

    Click + Add agent where the code should run, double-click the new step and choose Python in the type menu.

  2. 2

    Name it

    Give it a short name, such as Price. Later steps use this name.

  3. 3

    Write the code

    Under Code, write Python. Type @ to insert an input; the editor writes the right o.inputs[...] for you.

  4. 4

    Run it once

    Right-click the step and choose Run once to see its output. See Run, preview and publish.

Read inputs#

All inputs are in o.inputs, by step name:

WriteReads
o.inputs['question']The customer's latest message
o.inputs['chat_history']The conversation so far
o.inputs['Answer']The full output of a step named Answer
o.inputs['Classify']['order_id']One field of a step that answers with a schema

In an LLM step's schema, Copy for Python copies the exact line for a field.

Example: reading two schema fields
quantity = int(o.inputs['Order']['quantity'])
unit_price = float(o.inputs['Order']['unit_price'])
total = round(quantity * unit_price, 2)

Common mistakes#

  • KeyError on an input. The step name or field is spelled differently, or that step hasn't run yet on this path. Type @ and pick the input instead of typing it.
  • Text instead of a number. Schema fields and messages can arrive as text. Convert with int() or float() before doing math.
  • Using it for language tasks. Summaries, replies and classification belong in an LLM step.