Chapter 9: Refining Rules
The Problem
Your first segment worked, but real targeting is rarely that simple. You need: "High-value customers who purchased electronics OR home goods, but exclude anyone who returned an item in the last 60 days, and also exclude people already in the VIP program."
Multiple conditions. OR logic. Exclusions. Segment references. This chapter shows you how.
The Key Idea
Core concept
Complex segments combine simple rules with AND/OR logic and include/exclude references to other segments.
AI handles the syntax. You describe the logic in plain English, then verify the YAML captures your intent.
AND vs. OR Logic
By default, conditions combine with AND using type: And:
rule:
type: And
conditions:
- type: Value
attribute: lifetime_value
operator:
type: Greater
value: 1000
- type: Value
attribute: country
operator:
type: Equal
value: "USA"This means: lifetime_value > 1000 AND country = USA.
For OR logic, use type: Or:
> "Target customers from USA OR Canada"rule:
type: Or
conditions:
- type: Value
attribute: country
operator:
type: Equal
value: "USA"
- type: Value
attribute: country
operator:
type: Equal
value: "Canada"Complex Combinations
Real targeting often mixes AND and OR. Nest rule groups to combine them:
> "High-value customers from USA or Canada who purchased electronics or home goods"rule:
type: And
conditions:
- type: Value
attribute: lifetime_value
operator:
type: Greater
value: 1000
- type: Or
conditions:
- type: Value
attribute: country
operator:
type: Equal
value: "USA"
- type: Value
attribute: country
operator:
type: Equal
value: "Canada"
- type: Or
conditions:
- type: Value
attribute: last_purchase_category
operator:
type: Equal
value: "Electronics"
- type: Value
attribute: last_purchase_category
operator:
type: Equal
value: "Home & Garden"Reading this: LTV > 1000 AND (USA OR Canada) AND (Electronics OR Home & Garden).
Using the In Operator
For multiple values in the same field, In is cleaner than multiple ORs:
> "Target customers in USA, Canada, or UK"rule:
type: Value
attribute: country
operator:
type: In
value: ["USA", "Canada", "UK"]This is equivalent to: country = USA OR country = Canada OR country = UK.
Excluding Audiences
To exclude customers, use type: exclude with a segment reference:
> "Exclude customers in the Returns segment"rule:
type: And
conditions:
- type: Value
attribute: lifetime_value
operator:
type: Greater
value: 1000
- type: exclude
segment: recent-returnersThe type: exclude removes anyone in the referenced segment from your audience.
Referencing Other Segments
Instead of duplicating rules, reference existing segments:
> "Target high-value customers but exclude the VIP segment"rule:
type: And
conditions:
- type: Value
attribute: lifetime_value
operator:
type: Greater
value: 1000
- type: exclude
segment: vip-customersThis includes customers matching your rules, minus anyone already in "vip-customers."
You can also include other segments:
rule:
type: And
conditions:
- type: include
segment: engaged-email-subscribers
- type: Value
attribute: lifetime_value
operator:
type: Greater
value: 500This targets people in "engaged-email-subscribers" AND with LTV > 500.
Available Operators
Ask AI what operators work for different field types:
Comparison (numbers, dates):
Equal,NotEqualGreater,GreaterEqualLess,LessEqualBetween
Lists:
In,NotIn
Strings:
Contain,StartWith,EndWithRegexp(pattern matching)
Time/Behaviors:
TimeWithinPast,TimeWithinNextTimeToday,TimeThis,TimeNextTimeRange,TimeInBetweenNext
Null checks:
IsNull(field has no value)
Mental Model: Venn Diagrams
Think of each rule as a circle of customers:
Your segment is the intersection of the circles you want, minus the circles you exclude.
Building Complex Segments Step by Step
For complicated logic, build incrementally:
> "Start with high-value customers"Review the audience size.
> "Add: must have purchased in last 90 days"Review again.
> "Add: exclude the Churned segment"Final review.
This iterative approach helps you understand how each rule affects the audience.
Verifying Complex Logic
After AI generates the YAML, verify by asking:
> "Explain this segment's targeting logic in plain English"AI reads the YAML and explains:
This segment includes customers where:
1. Lifetime value is greater than $1000
2. AND country is either USA or Canada
3. AND they have NOT made a return in the last 60 days
4. AND they are NOT in the VIP Customers segment
Estimated audience: 2,847 customersIf the explanation doesn't match your intent, refine the rules.
Pitfalls
"The OR logic isn't working as expected."
Check the nesting. OR groups need to be explicitly defined:
> "Show me the rule structure as a logic tree""The exclusion excluded too many people."
Exclusions might be broader than intended. Preview the segment:
> "How many customers are being excluded by the return rule?""I referenced a segment that doesn't exist."
Validation catches this:
✗ Segment 'VIP Customers' not found
Available segments: VIP Members, VIP Program, ...What You've Learned
- Conditions combine with
type: Andortype: Or - Nest
And/Orgroups for complex logic Inoperator handles multiple values cleanlytype: excluderemoves segment memberstype: includeadds segment members- Build complex logic incrementally
- Verify by asking AI to explain the rules
Next Step
You can target precisely. Chapter 10 shows you how to send these audiences to marketing channels—Salesforce, Google Ads, email platforms, and more.
You've mastered targeting logic. Next, you'll connect it to the outside world.