---
schema_version: "1"
id: 5220144feeabb5b4ad1f5120fb09c0fac1892ce97cad3c4d76dfce9c84c8dbaa
title: Organize Complex 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_organize_complex_prompts.md
canonical_url: https://help.salesforce.com/s/articleView?id=ai.prompt_builder_organize_complex_prompts.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: b1d10b514e0fbc963a953242268d088d5b51b7a433861f25467a2c911fcfac3d
description: Structure prompts with multiple data sources and merge fields for clarity and consistency. Well-organized prompts reduce errors, speed up troubleshooting, and produce more reliable AI output.
products:
  - Agentforce
  - Cross Cloud
release: "264"
---
# Organize Complex Prompt Templates

Structure prompts with multiple data sources and merge fields for clarity and consistency. Well-organized prompts reduce errors, speed up troubleshooting, and produce more reliable AI output.

### 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>

## The Challenge of Complex Prompts

Simple prompts with one or two merge fields are straightforward. But production prompts often need much more data, and without proper organization they become hard to read, maintain, and troubleshoot. Common problems include:

- Merge fields blending into sentences, making updates error-prone
- No clear boundary between instructions and data
- Difficulty identifying which merge field is which
- Hard to troubleshoot when something goes wrong

## Use Triple Quotes to Separate Data from Instructions

Triple quotes (`"""`) create a visual container that clearly separates variable data from your instructions. This is the most important technique for organizing complex prompts. Everything between the triple quotes is treated as data or context, distinct from your instructions.

**Without triple quotes**

```
You are a customer service representative. Write a follow-up email to {!Contact.FirstName} {!Contact.LastName} at {!Account.Name} about their case {!Case.Subject} which was created on {!Case.CreatedDate} and is currently {!Case.Status} with priority {!Case.Priority}. Their account details show they're on the {!Account.Support_Tier__c} support tier. Make sure to reference the resolution notes: {!Case.Resolution__c}. Be professional and empathetic. Keep it under 200 words.
```

**With triple quotes**

```
You are a customer service representative.

Task: Write a follow-up email about the customer's support case

"""
Contact Information:
Name: {!Contact.FirstName} {!Contact.LastName}
Account: {!Account.Name}
Support Tier: {!Account.Support_Tier__c}

Case Details:
Subject: {!Case.Subject}
Created: {!Case.CreatedDate}
Status: {!Case.Status}
Priority: {!Case.Priority}
Resolution: {!Case.Resolution__c}
"""

Instructions:
- Greet the customer by first name
- Reference the case subject
- Confirm the case status and resolution
- Thank them for their patience
- Provide next steps if any

Tone: Professional and empathetic
Length: Under 200 words
```

Using triple quotes makes it easy to add, remove, or modify fields, and keeps instructions completely separate from data.

## Organize Data Within Triple Quotes

Inside the triple-quote block, organize merge fields logically using these techniques.

**Group by object**

```
"""
Account Information:
{!Account.Name}
{!Account.Industry}
{!Account.Annual_Revenue__c}

Contact Information:
{!Contact.FirstName}
{!Contact.LastName}
{!Contact.Email}

Case Information:
{!Case.Subject}
{!Case.Status}
{!Case.Priority}
"""
```

**Use labels**

Give each field a human-readable label. Labels help the AI model understand what each piece of data represents, especially when field names are cryptic.

```
"""
Customer: {!Contact.FirstName} {!Contact.LastName}
Company: {!Account.Name}
Issue: {!Case.Subject}
Opened: {!Case.CreatedDate}
Priority: {!Case.Priority}
Status: {!Case.Status}
"""
```

## Follow the Reference-Once Principle

As a general rule, include each piece of data exactly once in your prompt template. Repeating the same merge field multiple times can lead to inconsistent results and makes prompts harder to maintain. Place all merge fields in a single data section, then reference them conceptually in your instructions without repeating the merge field syntax.

## Use Multiple Triple-Quote Sections

For very complex prompts, use multiple triple-quote sections to separate different types of data. For example, use one block for variable data and a second block for a static example that guides tone and structure.

```
"""
Prospect Information:
Name: {!Lead.FirstName} {!Lead.LastName}
Company: {!Lead.Company}
Industry: {!Lead.Industry}
"""

Instructions:
- Personalize based on their industry
- Reference a common pain point
- End with a soft call to action

"""
Example tone and structure:
Hi [Name],

I noticed [Company] is in [Industry]. Many [Industry] leaders we work with struggle with [Pain Point].

Would you be open to a quick 15-minute call?
"""
```

## Handle Empty or Missing Fields

When working with many merge fields, some might be empty for certain records. Use fallback instructions to tell the AI how to handle missing values gracefully.

```
Instructions:
- Greet contact by name
- Reference account name
- If Support Tier is populated, mention their tier level
- If Annual Revenue is populated, acknowledge their business size
- If fields are empty, skip mentioning them (don't say "no tier" or "unknown revenue")
```

## Structure Very Long Prompts

When prompts grow beyond one screen, use clear section headers to make them scannable and easy to maintain.

```
========================================
ROLE
========================================
[Role definition]

========================================
DATA
========================================
"""
[All merge fields organized by object]
"""

========================================
TASK
========================================
[What to produce]

========================================
INSTRUCTIONS
========================================
[Step-by-step instructions]

========================================
FORMAT
========================================
[Response structure requirements]

========================================
CONSTRAINTS
========================================
[Boundaries and limits]
========================================
```

## Common Organization Mistakes

  
| Mistake | Problem | Solution |
| --- | --- | --- |
| Mixing data and instructions | Hard to parse what's data vs. what's instruction | Use triple quotes to separate |
| No labels on merge fields | AI doesn't understand what data means | Add descriptive labels |
| Repeating the same merge field | Inconsistent results | Reference each field once |
| Random field order | Difficult to scan and maintain | Group by object or context |
| No section headers | Can't navigate long prompts | Add clear section breaks |
| Cryptic field names | AI misinterprets data | Use plain-language labels |

## Organization Checklist

Before finalizing a complex prompt template, verify these items.

- All variable data is contained in triple-quote blocks
- Each merge field is referenced only once
- Merge fields have clear, human-readable labels
- Fields are grouped logically (by object or by context)
- Section headers separate major components
- Instructions are completely separate from data
- Prompt is scannable (find any field in under 10 seconds)
- Empty and missing field handling is addressed