The Python Tool step allows you to use Python to take outputs from other Tool steps and manipulate data for other Tool steps and LLMs.

What is Python?

Python is a widely used programming language known for its clarity and simplicity. It’s popular among beginners and experts alike because it’s easy to read, quick to write, and versatile enough for tasks ranging from web development and automation to data analysis and machine learning. With a massive library ecosystem and strong community support, Python is a powerful tool for solving real-world problems efficiently.

In order to use this Tool step, we would recommend having a beginner level of understanding of Python programming.

Add the Python Tool step to your Tool

You can add the Python Tool step to your Tool by:

  1. Creating a new Tool, then searching for the ‘Convert PDF to text’ Tool step
  2. Click ‘Expand’ to see the full Tool step
  3. Enter your code in the ‘Code’ field
  4. Click ’+ New item’ under ‘PyPl Packages’ if you need to install any packages
  5. Click ‘Run step’ to run the Tool step
In order to access the output of this codeblock, you will need to return a value in the return statement.

Accessing variables

You can access Tool input variables, other Tool step outputs, and API keys you’ve created in Relevance in your Python Tool step.

Input variables

You can access Input variables by following this syntax, where ‘name’ is the variable for your input.

  params['name']

Other Tool step outputs

You can access other Tool step outputs by following this syntax, where ‘tool_step’ is the variable for the Tool step you’re trying to access the output of.

  steps['tool_step']

You can then access a specific output of that Tool step by adding another variable.

  steps['tool_step']['output']

API keys

You can access one of your saved API keys by using this syntax, where ‘api_key’ is the variable for the key you’re trying to access.

  '{{api_key}}'

Advanced Settings

Backend

You can choose between two backend services to run the code, ‘Modal Labs’ or ‘e2b.dev’.

Runtime Commands

You can include a list of Linux terminal commands to be run before running your code.

Session ID

Define a custom session that saves all local variables between Python executions.

This setting is only available when the backend is set to ‘Modal Labs’.

Enable ‘Long Output’ Mode

Allow the output to be longer than 127,000 characters, in exchange for 2-4 seconds of extra latency.

Number of GPUs

Allows you to specify a number of GPUs for your code to use.

This setting is only available when the backend is set to ‘Modal Labs’.

Number of CPU Cores

Allows you to specify a number of CPU cores for your code to use.

This setting is only available when the backend is set to ‘Modal Labs’.

Memory Size

Allows you to specify an amount of RAM for your code to use.

This setting is only available when the backend is set to ‘Modal Labs’.

Session Timeout

Allows you to specify (in seconds) how long the code should run before timing out.

This setting is only available when the backend is set to ‘Modal Labs’.

Raise Error

Allows you to specify how errors are raised:

  • Error with Full Traceback
  • Error
  • Print Error to Stderr

Enable fallback

If the selected backend fails, when this is selected, your code will attempt to run via the other backend.

Common errors

Additional resources