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:
keyword
Replaced with the text you have selected in the editor.
keyword
Replaced with relevant context retrieved from your vault (Enhanced Actions/RAG).
keyword
Marks the beginning of a conditional context block.
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:
Selected text:
Final prompt sent to AI:

Custom Selection Placement

Use {{=SELECTION=}} to control where the selected text appears: Prompt:
Selected text:
Final prompt sent to AI:
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:
Retrieved context:
Final prompt:

Custom Context Placement

Use {{=CONTEXT=}} to position context anywhere in your prompt: Prompt:
Final prompt:
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:

When Context is Available

Final prompt:

When Context is NOT Available

Final prompt:
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:

Real-World Examples

Example 1: Context-Aware Q&A

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

Use case: Get AI code reviews that understand your project’s patterns and conventions.

Example 3: Research Assistant

Use case: Synthesize information from multiple research notes when answering questions.

Example 4: Meeting Notes Enhancer

Use case: Turn messy meeting notes into structured summaries with historical context.

Example 5: Writing Style Matcher

Use case: Rewrite content to match your established writing style based on examples in your vault.

Common Patterns

Pattern 1: Sandwich Structure

Context first, then selection, then instructions. Good for when context provides background for understanding the selection.

Pattern 2: Instruction-First Structure

Instructions first, then content. Good for complex tasks where the AI needs to understand the goal before seeing the content.

Pattern 3: Labeled Sections

Clear labels for each section. Good for complex prompts with multiple inputs.

Pattern 4: Conditional Everything

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:
What you might expect:
What actually happens:
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:

Empty Context Behavior

When using {{=CONTEXT=}} without conditional blocks, you’ll get an empty line if no context is available:

Best Practices

Always Use Conditionals for Context

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=}}:

Structure Complex Prompts

Use headers to organize complex prompts:

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