FROM, WHERE, EXISTS, and aggregate functions such as COUNT, SUM, MIN, and MAX.
Instead of writing raw JSON, you use expressions to evaluate line items, quote properties, and related CRM data. Each rule expression describes a violation condition, which is a rule that evaluates to true when the condition is met. You can define logic such as product requirements, incompatibilities, pricing thresholds, and validation rules. For example, you can require certain products to be sold together, prevent incompatible products from being added to the same quote, or enforce quantity limits.
Prerequisites
Before using the DSL, it’s recommended that you:- Have familiarity working with CRM objects and their properties (e.g., line items, quotes, deals).
- Understand logical operators such as
AND,OR, andNOT. - Know the property names available in your CRM, which you can find either in the account’s property settings or via the properties API.
- Property references must follow strict syntax and validation rules.
- Some calculations (e.g., arithmetic inside aggregate functions) are not supported.
- Invalid property names or syntax will return parser errors.
Best practices
- Use square brackets for all property references to distinguish them from other value types (e.g.,
[quantity]is a property while"quantity"is a string literal). - Use explicit scope prefixes (e.g.,
line_item.,quote.) when referencing properties outside aWHEREclause. - Add parentheses to clarify evaluation order in complex expressions.
- Validate property names against your CRM before writing rules to ensure the properties exist.
- Test rules with sample data to verify that rules work as expected, and use a sandbox environment when possible.
Syntax overview
The DSL supports the following syntax:- Boolean logic:
AND,OR,NOT - Quantifiers:
EXISTS,ALL_MATCH,NONE_MATCH - Comparisons:
=,!=,>,<,>=,<=,CONTAINS,STARTS_WITH - Group expressions:
SOLD_TOGETHER,INCOMPATIBLE,ALL_SAME - Aggregates:
COUNT,SUM,MIN,MAX - Property references: bracket notation (e.g.,
[property_name]) - Arithmetic operations:
+,-,*,/
Property references
The DSL validates all property references against CRM data. All property references must be wrapped in square brackets.- Outside a
WHEREclause, useobject.propertydot notation to scope the property to a specific object. For example,[quote.hs_quote_amount]describes the quote propertyhs_quote_amount. - Inside a
WHEREclause, properties inherit their scope from the clause object. For example, the clauseFROM line_items WHERE [hs_product_id] = ...references the line item propertyhs_product_id.
WHERE clause. For example, the following rule is invalid because product. is a different object scope than line_items:
[quote.my_custom_property]). Custom property names must:
- Start with a letter.
- Contain only letters, numbers, or underscores.
- Include a valid object scope.
The rule editor renders human-readable labels for recognized properties and objects rather than their internal names. For example, ![Rule editor showing [Product] label instead of [hs_product_id] internal property name](https://developers.hubspot.com/hubfs/Knowledge_Base_2023-24-25/KB-quotes/quote-rule-editor-syntax-rendered-labels.png)
[hs_product_id] displays as Product and line_item displays as Line item. If the value doesn’t match a recognized property or object, the editor renders the raw syntax instead.![Rule editor showing [Product] label instead of [hs_product_id] internal property name](https://developers.hubspot.com/hubfs/Knowledge_Base_2023-24-25/KB-quotes/quote-rule-editor-syntax-rendered-labels.png)
Line item properties
Standard line item property references include:| Property | Description |
|---|---|
hs_product_id | Product identifier |
name | Product name |
quantity | Item quantity |
hs_sku | Stock keeping unit |
description | Product description |
hs_discount_percentage | Discount percentage |
price | List price before discounts |
amount | Total after discounts |
To check the net unit price after discounts, use
[amount] / [quantity] rather than [price]. For example, to enforce that a product must sell at $300, use [amount] / [quantity] != 300, not [price] != 300.Quote properties
Standard quote property references include:| Property | Description |
|---|---|
quote.hs_title | Quote title |
quote.hs_status | Quote status |
quote.hs_expiration_date | Expiration date |
quote.hs_currency | Currency code |
quote.hs_language | Language code |
Basic expressions
Existence checks
Use quantifiers to check whether line items matching a condition exist.Comparisons
Use comparison operators to evaluate property values. When referencing line item properties outside aWHERE clause, use an explicit scope prefix.
Group expressions
Group expressions simplify common multi-product validation patterns.SOLD_TOGETHER
Requires all products in a group to be present if any one of them is present. This expression is shorthand for the more verbose(EXISTS ... OR EXISTS ...) AND NOT (EXISTS ... AND EXISTS ...) pattern.
- Pass: none or all products are present.
- Violation: only some products are present.
INCOMPATIBLE
Ensures that only one product from a group is present. This expression is shorthand for the more verboseEXISTS ... OR EXISTS ... pattern.
- Pass: zero or one product present.
- Violation: multiple products present.
ALL_SAME
Ensures all line items share the same value for a given property. An optionalWHERE clause filters items before checking uniformity.
- Pass: all values match, or no items exist.
- Violation: multiple different values detected.
Compound expressions
Boolean operators
UseAND, OR, and NOT to combine multiple conditions.
Nested logic
Use parentheses to group conditions and clarify evaluation order in complex expressions.Aggregate expressions
COUNT
Count the number of line items, optionally filtered by a condition.SUM
Sum a numeric property across line items, optionally filtered by a condition.MIN and MAX
Check the minimum or maximum value of a property across line items.Arithmetic
Use arithmetic operators to perform calculations across aggregate expressions.Arithmetic inside aggregate functions (e.g.,
SUM([quantity] * [price])) is not supported. Use separate aggregates and compare them instead.Common examples
Required products
The following rule validates that an Enterprise tier product cannot be added to a quote without also including a support plan.Incompatible products
The following rule validates that legacy and modern platform products cannot coexist on the same quote.Bundle validation
The following rule validates that if any item from a bundle is added, all items in the bundle must be included.Quantity limits
The following rule enforces a maximum of five Enterprise licenses per quote.Approval thresholds
The following rules check for conditions that would require manual approval: discounts over 20% and quotes with a total amount over $100,000.Error handling
The parser returns descriptive error messages that indicate the position of the issue and suggest corrections. For example:- Missing brackets around property references.
- Using an invalid or misspelled property name.
- Referencing a line item property without an explicit scope outside a
WHEREclause. - Using unsupported arithmetic inside aggregate functions.