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

Available in: Lightning Experience
Available in: Enterprise, Performance, and Unlimited Editions with the Einstein for Platform, or Einstein or Agentforce for Sales or Service add-on, or Agentforce Foundations

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.

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.