> ## Documentation Index
> Fetch the complete documentation index at: https://docs.voucherify.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Create validation rules

> A step-by-step guide to building validation rules that limit redemptions, control loyalty earning, or trigger distributions

Validation rules define the conditions customers must meet to redeem incentives, earn loyalty points, or trigger distributions in Voucherify. All validation logic is configured in the **validation rule builder**.

<Note>
  <Badge color="blue">Validation rules – description</Badge>

  Read the [Validation rules](/optimize/validation-rules-reference) article to learn how each rule works.
</Note>

## Access the validation rule builder

You can open the validation rule builder from:

* **Campaign builder**: Create a validation rule while configuring a campaign. A validation rule is then automatically assigned to the campaign.
* **Campaign details**: Open an existing campaign and go to the **Rules** tab. Enable edit mode to create a validation rule or edit an existing one.
* **Validation rules** in the **Campaign hub**: Create reusable rules for future use across campaigns.

## Build a validation rule

Follow these steps to create or edit a validation rule.

The builder looks slightly different when it's opened in different places.

<Steps>
  <Step title="Name the rule">
    **Name** your validation rule.

    If left unchanged, Voucherify uses the default name.

    <Note>
      <Badge color="blue">Builder in Validation rules</Badge>

      When creating a validation rule in **Validation rules** section of the dashboard, you can also select **Context**.

      Use **Context** to prepare a rule for validating a specific resource. **Context** determines which rule types are available and it's recommended for advanced use cases.
    </Note>
  </Step>

  <Step title="Add rules">
    **Add rules** to choose conditions from available categories:

    * **Audience**: Customer segments, loyalty tiers, or customer metadata.
    * **Products**: Specific products, SKUs, collections, or prices of items.
    * **Prices & quantities**: Order value, item quantity, or price thresholds.
    * **Budget constraints**: Campaign spend restrictions, like total order or discount values, number of redemptions per period or customer.
    * **Redemptions**: Limits for redeeming users and API keys.
    * **Metadata**: Limits related to custom attributes covering customer, order, redemption, or custom event metadata.

    Some rules also have subrules that can set additional conditions.

    **Edit rule** by clicking the three-dot menu.

    <Note>
      <Badge color="blue">Context-dependent rules</Badge>

      Depending on the **Context** defined in the **Name the rule** step or the dashboard context (campaign builder, earning rule, distribution, and so on), the number and types of rules will vary.
    </Note>
  </Step>

  <Step title="Define operators and conditions">
    For each rule, select operators such as **is**, **is more than**, **after**, and so on.

    <Tip>
      You can add multiple conditions within a single rule to refine the logic.

      For example, you can create a rule where the order initial amount is more than \$100 and less than \$150.
    </Tip>
  </Step>

  <Step title="Configure junctions and brackets">
    Combine rules using logical connectors:

    * **AND**: All rules must be met.
    * **OR**: At least one rule must be met.

    Click the junction to change it.

    Use **brackets** to group conditions into complex logic. You can nest rules by dragging them into bracket groups.
  </Step>

  <Step title="Set error messages">
    **Add error message** to define a custom message returned in the API response when a specific rule is not met.

    You can also **Add fallback error message** to the whole validation rule when an error is not specified for a particular rule.

    <Info>
      If no validation rule error message and no fallback message are defined, the API response will not include the `error` object for validation rule violations in some cases.
    </Info>
  </Step>

  <Step title="Save">
    **Save** your validation rule.

    <Info>
      <Badge color="gray">Builder differences</Badge>

      If you configure validation rules through the **Validation rules** section in the dashboard, you will have a **Summary** step where you can **Save** the validation rule.
    </Info>
  </Step>
</Steps>

The rule is assigned to the campaign once the campaign builder is saved or added to the validation rule list.

## Using existing validation rules

In the campaign manager and campaign details, you can:

* Create a new validation rule
* Select an existing validation rule
* Clone and edit an existing rule
* Remove an assigned validation rule

Changes made to assigned rules are applied immediately.

## Validation rules with bundles and product discounts

For **bundle** campaigns and **product discount** campaigns, Voucherify automatically creates a validation rule that includes the configuration of the bundle and discounted products.

<Warning>
  This auto-generated validation rule cannot be removed from the campaign in the campaign manager or campaign details. You can, however, edit the rule to add or remove conditions.
</Warning>

## Related features

Validation rules connect to other Voucherify features. Use the resources below to prepare data and apply rules effectively.

<AccordionGroup>
  <Accordion title="Customer segments">
    [Customer segments](/prepare/customer-segments) group customers based on shared attributes or behavior. Use segments in **Audience** rules to target specific customer groups.

    Segments update dynamically, so a rule that targets a segment always checks the current membership.
  </Accordion>

  <Accordion title="Product collections">
    [Product collections](/prepare/product-collections) group products based on attributes or filters. Use collections in **Products** rules to define required or excluded cart items.

    Dynamic collections update automatically when products match the defined filters.
  </Accordion>

  <Accordion title="Metadata schemas">
    [Metadata](/prepare/metadata) lets you store custom attributes on customers, orders, products, and redemptions. Use metadata in validation rules to create conditions based on any custom data.

    Define metadata schemas in **Project Settings** to ensure consistent data types across rules.
  </Accordion>

  <Accordion title="Custom events">
    [Custom events](/prepare/custom-events) track customer actions sent via API. Use custom event metadata in validation rules for distributions or earning rules.

    For example, trigger a distribution only when a custom event includes specific metadata.
  </Accordion>

  <Accordion title="Campaigns and earning rules">
    Validation rules control eligibility for:

    * [Discount coupons](/build/create-discount-coupons) and [promotions](/build/create-discount-promotions)
    * [Loyalty earning rules](/build/earning-rules)
    * [Referral campaigns](/build/create-referral-campaign)

    Each campaign type supports different rule categories based on its context.
  </Accordion>

  <Accordion title="Developer setup: Validation Rules API">
    Developers can manage validation rules using the [Validation Rules API](/api-reference/validation-rules/validation-rule-object).

    The API supports creating rules, assigning them to campaigns, and listing all assignments.

    <Tip>
      Because validation rules often include complicated logic and many rules, it's recommended to create validation rules through the dashboard to avoid any misconfiguration.
    </Tip>
  </Accordion>
</AccordionGroup>
