All docs
/
Getting started
/
Conditional statements

Conditional statements

Control the logic of your workflow

Overview

Conditional statements overview

Conditional statements in Clay help you control the flow of logic of your workflow, allowing you to perform different actions based on conditions. For example, if Company Size > 100, the output will be true.

In Clay, you can use conditional statements in:

  • Conditional runs: Run a certain enrichment based on certain criteria.
  • AI formulas: Transform data, like scoring leads or qualifying opportunities.
  • Conditional Snippets: Embed conditional logic to send outbound messages based on contact criteria.
  • Waterfalls: Maximizing coverage with multiple providers.

Conditional statement structure

Conditional statements have the following structure:

  1. IF (Condition) – Executes a command when the condition is true.
  2. ELSE IF (secondCondition) – Executes a command if the second condition is true (optional).
  3. ELSE – Executes a command when none of the above conditions are true.

Walkthrough

IF Condition

(command to execute if condition is true)

ELSE IF secondCondition

(command to execute if secondCondition is true)

ELSE

(command to execute if no conditions are true)

Best practices

Testing

Prevent unexpected errors with edge cases or missing data.

Examples

  • Empty fields: IF({{company_size}} > 100) THEN "Qualified" ELSE "Not Qualified" , Ensure blank company_size defaults to "Not Qualified".
  • Boundary values: Test company_size = 50 in IF({{company_size}} >= 50) THEN "Medium" ELSE "Small" to avoid misclassification.
  • Unexpected formats: Handle company_size = "unknown" by defaulting to "Not Qualified".

Error handling

Handle missing or invalid data properly.

Examples:

  • Missing fields: In IF({{company_size}} AND {{location}}) THEN "Valid" ELSE "Invalid", return "Invalid" if fields are missing.
  • Clear errors: Use IF({{email}} == "") THEN "Error: Missing Email" ELSE "Valid Email" to flag missing inputs.

Parentheses for clarity

Use parentheses to group conditions clearly, especially when combining multiple logical operators (AND, OR, NOT).

Examples:

  • Unclear: {{size}} > 100 AND {{location}} == "US" OR {{revenue}} > 1M could qualify the wrong leads.
  • Clear: (size > 100 AND location == "US") OR revenue > 1M ensures correct grouping.

Use cases: Lead qualification, CRM updates, or email campaigns where errors could disqualify valid leads or waste resources.

Example conditional statements within Clay

Example #1: Basic email validation

Validate email formats to flag personal email addresses.

Formula

IF (person.email contains @gmail.com OR @yahoo.com)return "Invalid email format"

ELSEreturn "Valid email format"

Test cases

Example #2: Message snippets based on company size

Serve different message snippets based on the company’s size.

Formula

IF (company.size > 500)

return enterprise_message_snippet

ELSE IF (company.size > 50)

return midmarket_message_snippet

ELSE

return small_message_snippet

Test cases

  • Input: company.size = 750Result: enterprise_message_snippet
  • Input: company.size = 100Result: midmarket_message_snippet
  • Input: company.size = 25Result: small_message_snippet
  • Input: company.size = 0Result: small_message_snippetNote: Since this input doesn't satisfy any of the conditions, the final else statement is returned, but we should add some input validation here.

Example #3: Regional discounts based on geography

Apply different discount rates based on the region.

Formula

IF (region == "US")

return "10% Discount"

ELSE IF (region == "EMEA")

return "15% Discount"

ELSE

return "No Discount Available”

Test cases

  • Input: region = "US"Result: 10% Discount
  • Input: region = "EMEA"Result: 15% Discount
  • Input: region = "APAC"Result: No Discount Available

Explore other docs

Gen AI

Guide: Using Clay plugin

Go-to-market plays you can run from a coding agent with the Clay plugin — source your market, score it for fit, and prioritize who gets worked first.

View article
Gen AI

Audiences for agents and the CLI

Read, segment, and manage your workspace's people, companies, and deals from the Clay CLI — and from the Clay agents that run it for you.

View article
Getting started

Clay MCP for Reps vs. Agent Plugin

Choose between MCP for Reps and the Clay Agent Plugin based on who will be using it and how much your ops team needs to approve in advance.

View article
Enrich

Enrichment in Workflows

Enrich an Audiences segment through a guided workflow that opens with its trigger and write-back step already configured.

View article
Export

Getting started with Sequencer

Sequencer runs cold email campaigns at scale from your Audiences data, handling sending infrastructure, copy, and deliverability in one place.

View article
Export

Connect your own email accounts

Connect email accounts you already own — Google Workspace, Microsoft 365, or any mailbox that supports SMTP — and use them as sending accounts for your campaigns.

View article
Export

Email warmup

What email warmup does, how it differs on purchased and self-connected accounts, and why you'll see unfamiliar emails while it runs.

View article

Other popular resources

Experts

Find a Clay Expert

Explore our network of Clay experts and agencies.

View experts
Community

Join our slack community

Find help in our slack community, and support channels.

Go to slack
Cohorts

Join a cohort, learn Clay fast!

The faster way to master Clay. Sign in if you're enrolled in a cohort (current or past) or apply!

Learn more about cohorts
Talents

Hire GTME Talent

Find and connect with GTM talent who've demonstrated expertise in building advanced workflows

Explore GTME talents