---
schema_version: "1"
id: 0d70e6173782b20c6a6809074ee47493c13df31b5236af1d681807662408131d
title: Use Conditional Logic in Prompt Templates
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/ai/264-0-0/prompt_builder_use_conditional_logic.md
canonical_url: https://help.salesforce.com/s/articleView?id=ai.prompt_builder_use_conditional_logic.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 6b68baf924629d2692fc7785b7b800c51b331d04b651573eabdcb255a0d476ac
description: Create dynamic, context-aware prompt templates using conditional logic in the Block Editor. Add if, else if, and else statements to tailor AI responses based on input variables and grounded data.
products:
  - Agentforce
  - Cross Cloud
release: "264"
---
# Use Conditional Logic in Prompt Templates

Create dynamic, context-aware prompt templates using conditional logic in the Block Editor. Add `if`, `else if`, and `else` statements to tailor AI responses based on input variables and grounded data.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Enterprise</strong>, <strong>Performance</strong>, and <strong>Unlimited</strong> Editions with the Einstein for Platform, or Einstein or Agentforce for Sales or Service add-on, or Agentforce Foundations</td></tr></tbody></table>

With conditional logic, your prompt templates adapt based on context. Instead of creating multiple similar templates for different scenarios, build a single template that adjusts its behavior based on conditions you define.

Review what conditional blocks do.

- Adjust tone and messaging. Tailor communication style based on customer tier, case priority, or relationship status.
- Include or exclude text. Show detailed technical information only when relevant, or customize sections based on data values.
- Personalize responses. Customize AI responses based on product type, service level, or user preferences.
- Handle multiple scenarios. Address different business cases within a single template.

## Understand How Conditional Logic Works

Conditional blocks evaluate expressions using merge fields from your grounded data sources. When a condition is true, the corresponding text is included in the prompt sent to the AI model.

The Block Editor uses conditional expressions. Review these supported operators.

- Comparison: `==` (equals), `!=` (not equals), `>` (greater than), `<` (less than), `>=` (greater than or equal), `<=` (less than or equal)
- Logical: `and`, `or`, `not`
- Membership: `in` (check if value exists in a list)

Place conditional blocks inside other conditional blocks to create more complex logic. For example, first check if a case priority is High, and then within that condition, check if the customer tier is Premium to determine the appropriate response strategy.

Conditional blocks evaluate a single related record. They don’t iterate over a collection, such as multiple files related to a case. For details, see [Prompt Builder Limitations](https://help.salesforce.com/s/articleView?id=ai.prompt_builder_limitations.htm&release=264.0.0&type=5 "Learn about the functional limitations of prompt templates that affect certain behaviors and outcomes.").

Review these example use cases.

- Customer Service: "If case priority is High, use urgent tone and escalate to the senior support team."
- Sales: "If opportunity value > $100,000, include executive summary and ROI calculator."
- Marketing: "If the customer tier is Premium, mention exclusive benefits and dedicated support."
- Nested Example: "If case priority is High and customer tier is Premium, assign to a dedicated account team; otherwise if case priority is High, assign to standard escalation team."

For copy-paste examples, see [Conditional Logic Example Templates](https://help.salesforce.com/s/articleView?id=ai.prompt_builder_conditional_logic_example_templates.htm&release=264.0.0&type=5 "Copy these example conditional blocks into a prompt template that uses the Block Editor.").

#### See Also

- [Add Conditional Logic to a Prompt Template](https://help.salesforce.com/s/articleView?id=ai.prompt_builder_add_conditional_logic.htm&release=264.0.0&type=5 "Use conditional blocks to create dynamic prompt templates that adapt based on your grounded data.")
- [Understand the Block Editor](https://help.salesforce.com/s/articleView?id=ai.prompt_builder_understand_block_editor.htm&release=264.0.0&type=5 "The Block Editor is a visual, block-based canvas for building prompt templates. Add resources, format instructions, apply conditional logic, and rearrange text without writing HTML.")
- [Conditional Logic Example Templates](https://help.salesforce.com/s/articleView?id=ai.prompt_builder_conditional_logic_example_templates.htm&release=264.0.0&type=5 "Copy these example conditional blocks into a prompt template that uses the Block Editor.")