Python Code Tool
The Python Code Tool allows users to write and execute custom Python code within the platform. Users can access input variables and other steps' output, as well as configure guardrails validators to ensure the code meets certain criteria. This guide will walk you through the steps to effectively use this tool.
Steps to Use the Python Code Tool
Step 1: Access the Tool
To access the Python Code Tool, follow these steps:
- Click on
Add User Step
. - From the available options, select the
Python Code
Tool.
Step 2: Write the Python Code
After selecting the tool, you need to write your Python code. Enter the Python code you want to execute. Make sure your code is well-structured and follows Python syntax.
Step 3: Access Input Variables
To use input variables within your Python code, use the syntax {{variable_name}}
to access the value of an input variable. For example, if there is an input parameter named “title”, you can access its value using {{title}}
.
Step 4: Access Other Steps' Output
To use the output from other steps within your Python code, use the syntax {{step_name.result}}
to access the output value of a previous step. For example, if there is a step named “llm_call”, you can access its produced value using {{llm_call.answer}}
.
Step 5: Configure Guardrails Validators (Optional)
You can set up guardrails validators to ensure the code meets certain criteria. Set up validators based on your specific needs. This may include rules for code quality, error handling, or other criteria.
Step 6: Execute the Code
Once you have written your Python code and configured any necessary validators, execute the code:
- Execute the code: Click the
Run
button to execute your Python code. - Results: The tool will execute the Python code. The results will be displayed after execution.
Step 7: View the Output
The output of your Python code will be displayed in the results section. The results will be presented in a structured format, often in JSON or plain text, depending on the nature of the output.
Step 8: Utilize the Results
You can now use the output from your Python code for further processing, analysis, or integration into your application.
Tips for Effective Use
- Clear Code: Write clear and concise Python code to ensure easy readability and maintenance.
- Effective Use of Variables: Utilize input variables and other steps' output effectively to create dynamic and flexible code.
- Guardrails Validators: Configure guardrails validators to maintain output quality.
If you have any questions or need further assistance, please contact the helpdesk([email protected]).