Python Tool : run code in Phacet
Phacet's Python Tool enables custom computations and automations directly within your Phacet, leveraging Python scripts to interact dynamically with cell data.
The Python tool also allows you to run logic without consuming AI credits.
The Python Tool can be used when you need clear, repeatable logic such as:
- Standardizing data for reporting: Normalize dates, prices, or product names.
- Embedding business rules: Assign tax codes, risk levels, or warning flags.
- Comparing data sources: Calculate differences, spot mismatches, or generate JSON diffs.
- Preparing inputs for AI: Clean text, strip HTML, or extract IDs before processing with AI.
1. Setting up the Python Tool
- Add a new Column
- Select your Column type (Text, Single/Multi Select or JSON). This will set the output format for your Python Snippet
- Set Tool : Python Code
- Add your code Snippet in the Instruction field
- You can use @ to reference any other column in your Phacet
- Click on Generate Values to apply your code across all rows

In this example, we are using Python tool to uppercase text.
2. Defining your Python function
To function correctly, your script must meet two requirements:
- It must contain valid Python code.
- It must define a
main()
function that:- Takes no arguments
- Returns an object compatible with the column type
All standard Python packages are available by default, so you can use any built-in modules to enhance your logic.
Phacet will execute the main()
function for each row.
3. Referencing the value of other cells
You can reference the value of other cells in the same row using the @ symbol followed by the column name.
This lets you dynamically use data from any column as input for your logic.

Example Scripts
- Extract a value from a CSV field
Assuming the column CSV Row
contains a parsed dictionary from a CSV row (e.g., JSON from a file upload or a parsing step):
def main():
csv_data = @"CSV Row" # This should be a dict-like object
return csv_data.get("Product Code", "Not Found")
- Compare two columns and label as "Match" if they are equal
def main():
if @"System ID" == @"Input ID":
return "Match"
else:
return "Mismatch"
4. Applying Python tool to column types
The Python Tool works with the following column types in Phacet:
- Text: Return a string or number to populate the cell.
- JSON: Return a valid dictionary or list object.
- Single Select: Return a string matching one of the predefined tag options set by the user.
- Multiple Select: Return a list of strings, each matching one of the allowed tag options.
5. Looking beyond Python: tap into the AI Tool
Depending on your use case, it might be more relevant to use AI (LLM) Instructions instead of Python code. AI Instructions are especially useful when you want to:
- Parse or summarize unstructured text
- Enrich or rewrite content using natural language
- Generate outputs from examples or instructions instead of strict logic
6. Common errors and how to fix them
Tip : use ChatGPT to fix your Python code when your encounter an error.
⚡Missing or invalidmain()
function
Your script must include a main()
function with no arguments. If missing or improperly defined, the script will not run.
Incorrect
# No main function defined
value = @Price * @Quantity
return value
Fix
def main():
return @Price * @Quantity
⚡ Invalid return type for column
Each column type (e.g. Single Select, JSON) expects a specific type of value. Returning the wrong type (like returning a dict in a text column) will fail silently or show incorrect results.
Incorrect
def main():
return {"status": "active"} # This won't work in a Text column
Fix
Ensure the return value in main()
matches the expected column type. For a Single Select column, return one of the predefined options.
def main():
return "active" # Return a string instead
⚡ Syntax errors or typos in Python code
Simple issues like missing colons, unmatched quotes, or indentation errors will break execution.
Incorrect
def main()
return "Ready"
Fix
Double-check syntax. Use consistent indentation and close all brackets or quotes.
def main():
return "Ready"
Updated 26 days ago