---
schema_version: "1"
id: 62737857a80da3648ffefca48ef01a3902ad999ed5c9bcec85abfc066778d384
title: Add Conditional Logic to a Prompt Template
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/ai/264-0-0/prompt_builder_add_conditional_logic.md
canonical_url: https://help.salesforce.com/s/articleView?id=ai.prompt_builder_add_conditional_logic.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: fa727b907671963c420373795b7ee251d63155ede4847d4234db294fb44cf7b0
description: Use conditional blocks to create dynamic prompt templates that adapt based on your grounded data.
products:
  - Agentforce
  - Cross Cloud
release: "264"
---
# Add Conditional Logic to a Prompt Template

Use conditional blocks to create dynamic prompt templates that adapt based on your 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>

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d38203e69">User Permissions Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d38203e69 ">To create and manage prompt templates in Prompt Builder:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d38203e69 ">
              <p>Prompt Template Manager permission set</p>
              <ul>
                <li>Manage Prompt Templates</li>

                <li>Execute Prompt Templates</li>

              </ul>
              <p>OR</p>
              <p style="margin-bottom:0;">Customize Application permission set</p>
            </td>

          </tr>
        </tbody>
      </table>

Identify the merge fields you want to use in your conditions. These fields come from your grounded data sources, such as objects, flows, or custom resources.

Add a Conditional Block

1. From Prompt Builder, open or create a prompt template.
2. Position your cursor where you want to add conditional logic.
3. Type / to open the slash-command menu.
4. Select **Conditional Block** or **If Statement**.
5. In the condition field, enter your expression using merge fields and operators. For example, {!Case.Priority} == "High".
6. Add text for the `if` branch. This text appears when the condition is true.
7. Optionally, click **Add Else If** to add conditions for other scenarios.
8. Optionally, click **Add Else** to add text when no conditions are true.
9. Test your conditional logic with **Preview** and sample data.
10. Click **Save**.

Review tips for writing conditions.

- Use the @ symbol to insert merge fields from your grounded data.
- Wrap text values in quotes. For example, {!Account.Type} == "Enterprise".
- Combine multiple conditions. For example, {!Case.Priority} == "High" and {!Case.Age} > 7.
- Use parentheses for complex logic. For example, ({!Amount} > 100000) or ({!Stage} == "Closed Won").
- Test with various data scenarios to make sure that your conditions work as expected.

Review common conditional patterns.

- Check if a field has a value: If a contact has an email, display it.
- Compare numbers: Identify high-value opportunities.
- Check multiple conditions: Prioritize cases based on status and priority.

#### See Also

- [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.")
- [Preview a Resolved Prompt](https://help.salesforce.com/s/articleView?id=ai.prompt_builder_preview_resolved_prompt.htm&release=264.0.0&type=5 "In the Resolved Prompt section of your workspace, you can review a prompt that’s grounded with real Salesforce record data.")
- [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.")