Skip to main content

Overview

Prompt templating allows you to create dynamic prompts using special keywords that are replaced with actual content at runtime. This enables powerful workflows where selected text and vault context can be intelligently positioned in your prompts.

Template Keywords

Local GPT supports four template keywords:
{{=SELECTION=}}
keyword
Replaced with the text you have selected in the editor.
{{=CONTEXT=}}
keyword
Replaced with relevant context retrieved from your vault (Enhanced Actions/RAG).
{{=CONTEXT_START=}}
keyword
Marks the beginning of a conditional context block.
{{=CONTEXT_END=}}
keyword
Marks the end of a conditional context block.

Selection Keyword

Default Behavior

By default, selected text is automatically added to the end of your prompt: Prompt:
You are an assistant helping a user write more content in a document based on a prompt.
Selected text:
Some example text.
Final prompt sent to AI:
You are an assistant helping a user write more content in a document based on a prompt.

Some example text.

Custom Selection Placement

Use {{=SELECTION=}} to control where the selected text appears: Prompt:
{{=SELECTION=}}

You are an assistant helping a user write more content in a document based on a prompt.
Selected text:
Some example text.
Final prompt sent to AI:
Some example text.

You are an assistant helping a user write more content in a document based on a prompt.
This is useful when you want the AI to process the selected text before reading instructions, or when you want to embed selections within a structured template.

Context Keywords (Enhanced Actions)

Default Context Behavior

When Enhanced Actions (RAG) finds relevant context, it’s automatically added after the selection: Selected text:
Selected text with [[Some meaningful document]].
Retrieved context:
Some example context about the selected text from some meaningful document.
Final prompt:
Selected text with [[Some meaningful document]].

Context:
Some example context about the selected text from some meaningful document.

Custom Context Placement

Use {{=CONTEXT=}} to position context anywhere in your prompt: Prompt:
# Relevant context
{{=CONTEXT=}}

# Selected text
{{=SELECTION=}}
Final prompt:
# Relevant context
Some example context about the selected text from some meaningful document.

# Selected text
Selected text with [[Some meaningful document]].
The {{=CONTEXT=}} keyword is replaced with a multiline string containing all relevant context chunks retrieved from your vault.

Conditional Context Blocks

Often you want to include context only when it’s available. Use {{=CONTEXT_START=}} and {{=CONTEXT_END=}} to create conditional blocks: Prompt:
# Task
{{=SELECTION=}}
{{=CONTEXT_START=}}

# Context
{{=CONTEXT=}}
{{=CONTEXT_END=}}

# Instructions
Do something with the selected text.

When Context is Available

Final prompt:
# Task
Selected text with [[Some meaningful document]].

# Context
Some example context about the selected text from some meaningful document.

# Instructions
Do something with the selected text.

When Context is NOT Available

Final prompt:
# Task
Selected text with [[Some meaningful document]].

# Instructions
Do something with the selected text.
The entire block between {{=CONTEXT_START=}} and {{=CONTEXT_END=}} is removed when no context is available. This includes any text, headers, or formatting within the block.

Template Keyword Reference

From src/defaultSettings.ts:64-67:
export const SELECTION_KEYWORD = "{{=SELECTION=}}";
export const CONTEXT_KEYWORD = "{{=CONTEXT=}}";
export const CONTEXT_CONDITION_START = "{{=CONTEXT_START=}}";
export const CONTEXT_CONDITION_END = "{{=CONTEXT_END=}}";

Real-World Examples

Example 1: Context-Aware Q&A

Prompt: |
  # Question
  {{=SELECTION=}}
  
  {{=CONTEXT_START=}}
  # Relevant Information from Vault
  {{=CONTEXT=}}
  {{=CONTEXT_END=}}
  
  # Instructions
  Answer the question thoroughly. Use information from the context when relevant, but don't be limited by it. If the context doesn't address the question, provide a general answer based on your knowledge.
Use case: Ask questions about topics in your vault, and the AI will use your notes as reference material.

Example 2: Code Review with Project Context

Prompt: |
  # Code to Review
  {{=SELECTION=}}
  
  {{=CONTEXT_START=}}
  # Related Code and Documentation
  {{=CONTEXT=}}
  {{=CONTEXT_END=}}
  
  # Instructions
  Review this code for:
  - Potential bugs
  - Performance issues
  - Best practice violations
  - Security concerns
  
  Consider the related code and documentation when available.
Use case: Get AI code reviews that understand your project’s patterns and conventions.

Example 3: Research Assistant

Prompt: |
  {{=CONTEXT_START=}}
  # Research Notes and Sources
  {{=CONTEXT=}}
  
  {{=CONTEXT_END=}}
  # Research Question
  {{=SELECTION=}}
  
  # Instructions
  Based on the research notes provided, generate a comprehensive answer to the question. Include:
  - Direct answers from the sources
  - Synthesis of multiple sources
  - Identification of gaps or conflicts in the research
Use case: Synthesize information from multiple research notes when answering questions.

Example 4: Meeting Notes Enhancer

Prompt: |
  # Meeting Notes
  {{=SELECTION=}}
  
  {{=CONTEXT_START=}}
  # Previous Meeting Context
  {{=CONTEXT=}}
  {{=CONTEXT_END=}}
  
  # Task
  Analyze these meeting notes and generate:
  
  1. **Summary**: Key discussion points
  2. **Decisions**: What was decided
  3. **Action Items**: Who needs to do what
  4. **Follow-ups**: Questions or items for next meeting
  
  {{=CONTEXT_START=}}
  If previous meeting context is available, note any progress or changes since the last meeting.
  {{=CONTEXT_END=}}
Use case: Turn messy meeting notes into structured summaries with historical context.

Example 5: Writing Style Matcher

Prompt: |
  {{=CONTEXT_START=}}
  # Writing Samples for Style Reference
  {{=CONTEXT=}}
  
  {{=CONTEXT_END=}}
  # Content to Rewrite
  {{=SELECTION=}}
  
  # Instructions
  Rewrite the content to match the style of the writing samples provided{{=CONTEXT_START=}} above{{=CONTEXT_END=}}. Focus on:
  - Tone and voice
  - Sentence structure
  - Vocabulary level
  - Formatting conventions
Use case: Rewrite content to match your established writing style based on examples in your vault.

Common Patterns

Pattern 1: Sandwich Structure

{{=CONTEXT=}}
{{=SELECTION=}}
Instructions here
Context first, then selection, then instructions. Good for when context provides background for understanding the selection.

Pattern 2: Instruction-First Structure

Instructions here
{{=SELECTION=}}
{{=CONTEXT=}}
Instructions first, then content. Good for complex tasks where the AI needs to understand the goal before seeing the content.

Pattern 3: Labeled Sections

# Input
{{=SELECTION=}}

# Reference
{{=CONTEXT=}}

# Task
Instructions here
Clear labels for each section. Good for complex prompts with multiple inputs.

Pattern 4: Conditional Everything

{{=CONTEXT_START=}}
# Context
{{=CONTEXT=}}

{{=CONTEXT_END=}}
# Main Content
{{=SELECTION=}}
Makes context completely optional. Good for actions that work with or without Enhanced Actions enabled.

Important Caveats

Default Appending Behavior

If you don’t use template keywords, both selection and context are automatically appended: Prompt:
# Task
Some task.

# Instructions
Do something with the selected text.
What you might expect:
# Task
Some task.

# Instructions
Do something with the selected text.
What actually happens:
# Task
Some task.

# Instructions
Do something with the selected text.

Selected text with [[Some meaningful document]].

Context:
Some example context about the selected text from some meaningful document.
Always use {{=SELECTION=}} if you want to control where the selection appears. Otherwise it will be appended at the end.

Nested Conditionals Not Supported

You cannot nest conditional blocks:
// ❌ This will NOT work
{{=CONTEXT_START=}}
  {{=CONTEXT_START=}}
    Nested content
  {{=CONTEXT_END=}}
{{=CONTEXT_END=}}

Empty Context Behavior

When using {{=CONTEXT=}} without conditional blocks, you’ll get an empty line if no context is available:
// Without conditionals:
# Context
{{=CONTEXT=}}  // This will be an empty line if no context

// With conditionals:
{{=CONTEXT_START=}}
# Context
{{=CONTEXT=}}  // Entire block removed if no context
{{=CONTEXT_END=}}

Best Practices

Always Use Conditionals for Context

{{=CONTEXT_START=}}
# Relevant Context
{{=CONTEXT=}}
{{=CONTEXT_END=}}
The first approach gracefully handles missing context. The second leaves an empty section.

Be Explicit with Selection

If you care about where the selection appears, always use {{=SELECTION=}}:
# Instructions
Summarize the following:

{{=SELECTION=}}

Structure Complex Prompts

Use headers to organize complex prompts:
# Context Information
{{=CONTEXT_START=}}
{{=CONTEXT=}}
{{=CONTEXT_END=}}

# Your Content
{{=SELECTION=}}

# Task Requirements
1. First requirement
2. Second requirement
3. Third requirement

# Output Format
Provide your response as:
- Bullet points
- With clear headers
- In markdown format

Test Your Templates

Test your prompt templates with:
  • ✅ Selection only (no context)
  • ✅ Selection + context
  • ✅ Different context amounts
  • ✅ Empty selection (if applicable)

Troubleshooting

Keywords Not Being Replaced

  • Check spelling and case sensitivity
  • Ensure you’re using the exact keyword format: {{=KEYWORD=}}
  • Verify there are no extra spaces inside the brackets

Context Always Empty

  • Ensure Embedding Provider is configured in settings
  • Check that Enhanced Actions is enabled for the action
  • Verify your vault has relevant linked documents
  • See AI Providers Setup for embedding configuration

Unexpected Formatting

  • Remember that conditional blocks remove ALL content between markers
  • Check for default appending when keywords are missing
  • Verify blank lines and spacing around keywords

Creating Custom Actions

Build custom actions with these templates

AI Providers Setup

Configure embedding providers for context

Build docs developers (and LLMs) love