Standard conditions work well for most situations, but sometimes you need to build stricter rules, like checking if a date is exactly 30 days ago, or seeing if a list contains a specific item.
Code evaluation in the Condition step allows you to define reliable, deterministic logic for your Fin Procedures using a single line of Python. We recommend using this method because it is faster and more reliable than asking AI to interpret the data for you.
The basics of code conditions
To ensure your logic runs correctly, your code must follow these specific rules:
Boolean result: The expression must always evaluate to
TrueorFalse.Namespace access: You can access attributes using the inputs dictionary.
Accessing data attributes
You can reference data from various sources using the specific namespace structure:
Company data:
inputs["company"]["name"]User data:
inputs["user"]["first_name"]Conversation data:
inputs["conversation"]["has_attachments"]Temporary data:
inputs["temporary"]["order_verified"]Data Connector data:
inputs["data_connector"]["order_verified"]
Note: Attribute names should be referenced exactly as they appear in your data schema.
Common expression examples
Here are standard Python patterns you can use to build your conditions:
Boolean checks
Check if a value is explicitly true or false.
inputs["temporary"]["order_verified"] == false
String comparisons
It is best practice to normalize strings (e.g., make them lowercase) before comparing them to avoid case-sensitivity errors.
inputs["temporary"]["order_fulfillment_status"].lower() == "partial"
Combined logic
You can combine multiple checks using and / or operators.
inputs["temporary"]["order_verified"] == true and inputs["temporary"]["order_fulfillment_status"].lower() == "partial"
"Contains" checks
Check if a specific substring exists within a larger string.
"uk" in inputs["temporary"]["url"].lower()
Working with datetime attributes
Code conditions have access to Python’s standard datetime module, allowing you to perform complex time-based logic.
Understanding timezones and formatting
To prevent errors, it is critical to understand how Intercom handles different types of date attributes:
Customer-defined attributes: Attributes stored in Intercom (User, Conversation, Custom, or Standard) are always exposed as UTC-normalized ISO 8601 strings (e.g.,
2025-05-27T00:00:00Z).Data connector attributes: Dates received from external APIs are exposed exactly as received. No normalization is applied. You may need to manually parse or convert these to UTC if consistency is required.
Note: All code within the Intercom sandbox environment operates in a UTC-based timezone by default. The function datetime.datetime.now() always returns the current UTC time, regardless of your local system settings.
Datetime examples
Check if the current time is greater than yesterday
(datetime.datetime.now() > datetime.datetime.now() - datetime.timedelta(days=1)) and len(inputs["temporary"]["Get movies"]) > 0
Check if an order date is within the last 30 days
This example compares the current UTC time against a temporary order date attribute.
(datetime.datetime.now(datetime.timezone.utc) - datetime.datetime.fromisoformat(inputs["temporary"]["order_date"])).days <= 30
Check if an order time is before 2 PM today (UTC)
This complex check extracts the date and time components to verify a specific cutoff window.
(datetime.datetime.combine((d := datetime.datetime.now(datetime.timezone.utc).date()), datetime.time(0, tzinfo=datetime.timezone.utc)) < (p := datetime.datetime.fromisoformat(inputs["temporary"]["order_time"])) < datetime.datetime.combine(d, datetime.time(14, 0, tzinfo=datetime.timezone.utc)))
Tip: Fin is fully aware of a customer's timezone. When Fin collects a datetime attribute during a conversation, it interprets the value in the customer's local timezone, converts it to UTC, and stores it.
Looping and arrays
You can iterate over arrays (lists) of data to validate specific conditions.
Supported: You can iterate over an array to check if a specific condition is met (e.g., "Does any order in this list have a status of 'fulfilled'?").
Not Supported: You cannot iterate over an array to run a workflow step for each item. Code conditions are strictly for evaluation, not action execution.
Example: Check for a specific fulfilled order
This code checks a list of orders to see if a specific ID exists AND if that order is fulfilled.
any(str(o["id"]) == "4308316520546" and o.get("fulfillment_status") == "fulfilled" for o in inputs["temporary"]["Shopify all orders"]["orders"])
Generate code with AI
If you are not comfortable writing Python, you can use an LLM (like Claude or ChatGPT) to generate these snippets for you. Use the prompt below to ensure the AI understands the specific constraints of Intercom's code conditions.
Copy and paste this prompt into your AI tool:
You are helping me write Fin Procedure /Condition code evaluation expressions.
Your job: When I describe a condition in natural language, respond with a single-line Python expression that evaluates to True or False. Do not provide explanation or extra text.
Context:
These are for /Condition steps in Fin procedures.
Fin evaluates branches top to bottom and runs the first condition that is True.
Prefer code evaluation (Python) over AI/natural language evaluation for reliability.
Data model:
inputs["user"]["first_name"], inputs["company"]["name"]inputs["conversation"]["has_attachments"]inputs["temporary"]["order_verified"]
Python rules:
Expression must be valid Python and return a boolean.
Use comparisons, logical operators, and simple loops/comprehensions.
For dates: You can use
datetime. Customer datetime attributes are UTC ISO strings (e.g. "2025-05-27T00:00:00Z").
Output format: Reply with only the Python expression on one line.
Need more help? Get support from our Community Forum
Find answers and get help from Intercom Support and Community Experts
