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:Custom Selection Placement
Use{{=SELECTION=}} to control where the selected text appears:
Prompt:
Context Keywords (Enhanced Actions)
Default Context Behavior
When Enhanced Actions (RAG) finds relevant context, it’s automatically added after the selection: Selected text:Custom Context Placement
Use{{=CONTEXT=}} to position context anywhere in your prompt:
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:Template Keyword Reference
Fromsrc/defaultSettings.ts:64-67:
Real-World Examples
Example 1: Context-Aware Q&A
Example 2: Code Review with Project Context
Example 3: Research Assistant
Example 4: Meeting Notes Enhancer
Example 5: Writing Style Matcher
Common Patterns
Pattern 1: Sandwich Structure
Pattern 2: Instruction-First Structure
Pattern 3: Labeled Sections
Pattern 4: Conditional Everything
Important Caveats
Default Appending Behavior
If you don’t use template keywords, both selection and context are automatically appended: Prompt: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
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
Related Resources
Creating Custom Actions
Build custom actions with these templates
AI Providers Setup
Configure embedding providers for context